

(function ($) {
	/*
		* SLIDER 
		*  SLIDER
		*	SLIDER
		*	 SLIDER
		*	  SLIDER
		*	   SLIDER
		*/
		jQuery.fn.slider = function(){
			var positions = [20, 155, 296, 435, 543, 653, 750]

			this.each(function(){

				thumb = $(this).find('.slider-thumb');

				ul = $(this).find('.slider-links');

				//thumb.disableSelection().draggable({
				thumb.draggable({
					'containment':'parent',
					'axis':'x',
					stop: function(e, ui){
						var currentClosestIndex;
						var tmpValue = 10000;
						var pi = positions.length;

						var lp = ui.position.left

						for(i = 0; i<pi; i++){
							var tmp = Math.abs(positions[i]*1 - lp);
							if(tmp < tmpValue){
								tmpValue = tmp;

								currentClosestIndex = i;
							}
						}
						//hash change
						location.hash = $('ul.slider-links li').eq(currentClosestIndex).find('a').attr('href')

						$(thumb).trigger('moveto', positions[currentClosestIndex])
					}
				}).bind('moveto', function(e, x_position, time, ease){
					$(this).animate({
						'left':x_position
					}, time || 400, ease || "easeOutQuad");
				}).bind('external_moveto', function(e, index){
					//triggered by anchor tags being clicked
					$('.slider-thumb').trigger('moveto', positions[index])
				}).bind('drag', function(e, ui){
					//$('h1.sliderResult').text( "Dragged " + Math.round( (ui.position.left / ($('.slider').width()-$(thumb).width()))*100 ).toString()+"%" );
				}).bind('mouseover', function(e){
					$(this).find('div.slider-thumb-hover').stop(true,true).fadeIn();
				}).bind('mouseout', function(e){
					$(this).find('div.slider-thumb-hover').stop(true,true).fadeOut();
				});
				//initial slide to hint its draggable
				if(!location.hash){
					setTimeout(function(){ thumb.trigger('moveto', 20) }, 600);
				}

			})
		}
		
		
		//news ticker
		$('ul#ticker01').newsticker();
		
		$('#slider').nivoSlider({
			'effect':'sliceDown',
			'slices':15,
			'pauseTime':5000,
			'captionOpacity':.8,
			'directionNavHide':false,
			'prevText':'',
			'nextText': '',
			'controlNav':false
		});
		
		//menu page
		
		$('div.drinks-section ul').masonry({
			itemSelector:'li'
		});
				
		
		
		//highlight menu items
		$('div.food-menu-item').each(function(){
			var section = this;
			$(this).find('.field-name-field-menu-highlighted').each(function(){
				if($(this).text() == 'true'){
					$(section).find('.node-title').addClass('highlighted');
				}
			})
		})
		
		
		$('.slider').slider();
		
		//only show todays special on homepage
		var days= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
		var today = new Date();
		var thisDay = days[today.getDay()];
		$('div.Specials content').masonry({
			itemSelector:'div.views-row',
			columnWidth:230
		})
		$('div.Specials td').each(function(i){
			if($(this).find('h2').text() == thisDay){
				$(this).find('h2').addClass('highlighted');
			}
		})
		
		$('.views-row', 'div.region-homepage').each(function(i){
			if( $(this).find('h4').text() != thisDay){
				$(this).css('display', 'none');
			} else {
				$(this).find('h4').addClass('highlighted')
				$(this).append('<a href="'+Drupal.settings.basePath+'specials" style="position:absolute;left:30px;bottom:0;font-style:italic;font-size:.9em;">View all specials &raquo;</a>')
				$(this).find('.field-name-field-special-day').css({
					'display':'none'
				})
			}
		});
		$('div.region-homepage').find('h4').css({
			display:'none'
		})
		$('div.region-homepage').find('h2.block-title').addClass('highlighted')
		

		//hash change events in menu
		$(window).hashchange(function(e){
			if(location.hash == "" && $('.Menu').size() > 0){
				location.hash = "#!appetizers"
			}
			$('div.food-menu-item').removeClass('active-food-item').removeClass('inactive-food-item');
			if(location.hash){
				var hash = location.hash.substring(2);
			
				
				$('div.region-content h2.block-title').each(function(i){
					currentSection = $(this).parent();
					if($(this).text().replace(' & ', '_').toLowerCase() == hash) {
						currentSection.find('div.food-menu-item').addClass('active-food-item');
						$(currentSection).masonry({
							itemSelector:'.food-menu-item'
						})
						$(currentSection).show().masonry()
						$('.slider-thumb').trigger('external_moveto', i)
					} else {
						$(currentSection).hide();
						currentSection.find('div.food-menu-item').addClass('inactive-food-item');
					}
				});
				var activeItems = $('div.active-food-item');
			}
			
		}).hashchange();

}(jQuery));





