$(document).ready(function() {
	// the array to hold the pages to pull using ajax
	var hp_pages = new Array();
	hp_pages[0] = "includes/hp-specials.inc.php?day=0";
	hp_pages[1] = "includes/hp-specials.inc.php?day=1";
	hp_pages[2] = "includes/hp-specials.inc.php?day=2";
	hp_pages[3] = "includes/hp-specials.inc.php?day=3";
	hp_pages[4] = "includes/hp-specials.inc.php?day=4";
	hp_pages[5] = "includes/hp-specials.inc.php?day=5";
	hp_pages[6] = "includes/hp-specials.inc.php?day=6";
	
	$(function() {
		var current_index = -1;
		var content_open = false;
		
		// hide content by default
		$("#hp-tabs-content").hide();
		
		$("#hp-tabs a").hover(function () {
			var index = $("#hp-tabs a").index(this);
			
			if (index != current_index) {
				// remove active pane
				if (current_index >= 0) {
					// remove active class from tab
					$("#hp-tabs a").eq(current_index).removeClass("active");
					
					// hide content window
					$("#hp-tabs-content").hide();
				}
				// set style of active button
				$("#hp-tabs a").eq(index).addClass("active");
				
				// load new content into content window
				$("#hp-tabs-content").show();
				$("#hp-tabs-content").load(hp_pages[index]);
				
				// set current index
				current_index = index;
			} else if (index == current_index) {
				$("#hp-tabs a").eq(current_index).removeClass("active");
				
				// hide content window
				$("#hp-tabs-content").hide();
				
				// reset current index
				current_index = -1;
			}
		},
		function () {
			var index = $("#hp-tabs a").index(this);
			
			// remove active style
			$("#hp-tabs a").eq(index).removeClass("active");
			
			// hide content window
			$("#hp-tabs-content").hide();
			
			// reset current index
			current_index = -1;
		});
	});
	
	
	// Photo Gallery Functions
	$(function() {
		$("#photo_nav a").tooltip({tip: '#tooltip', position: ['top', 'center'], offset: [-10, 0], onBeforeShow:showThumbnail, onHide:removeThumbnail}); 
		$("#photo_nav a").click(function () {
			var caption = $(this).data("title");
			var hrefer = $(this).attr("href");
			
			$("#photolg").attr("src", hrefer);
			if (caption == "") caption = "&nbsp;";
			$("#photocaption").html(caption);
			
			return false;
		});
		
		$("#photo_contain").photoScroll({nextBtn:"#next",prevBtn:"#prev", displayUp:10, scrollCount: 10});
		
		function showThumbnail() {
			var tip = $(this.getTip());
			var target = $(this.getTrigger());
			var url = $(target).attr("href");
			var thumb = url.substr(0, 19) + "_sm.jpg";
			$(tip).html("<img width=\"125\" src='"+thumb+"' />");
		}
		
		function removeThumbnail(){
			var tip = $(this.getTip());
			$(tip).html("");
		}
	});
});


/*------ PHOTO SCROLL -----*/
// Note: Never have a scrollCount greater than displayUp, not only is it silly because not all items would be shown
// but it would also cause unpredictable behavior.
(function($) {  
	$.fn.photoScroll = function(options) {
		var defaults = {
			scrollCount: 10, // Items to scroll per click, use this number to determine pages
			pxPerItem: 24, // the width of each item -- kev wants to calculate this
			displayUp: 10, // how many to display at a time
			totalOffset: 0, // This number represents any additional td tags that exist in photo scroll, but are not links
			offClass: "fade",
			nextBtn: ".forward",
			prevBtn: ".backward"
		}
		var options = $.extend(defaults, options);
		var obj;
		var scrollDiv;
		var index = 0;
		var total;
		var pages;
		var page;
		var pageIndex = 1;
		return this.each(function() {
			obj = $(this);
			scrollDiv = obj.find(".photo-scroll div");
			// total number of items
			total = obj.find(".photo-scroll td").size()-options.totalOffset;
			// get total number of pages
			pages = Math.max(1, Math.ceil((total - (options.displayUp - options.scrollCount)) / options.scrollCount));
			// Make sure page number is within valid range.
			pageIndex = Math.max(1, pageIndex);
			pageIndex = Math.min(pages, pageIndex);
			
			scrollDiv.scrollLeft(0);
			scrollDiv.css("overflow","hidden");
			
			// disable prev and next nav items by default
			obj.find(options.prevBtn).addClass(options.offClass);
			obj.find(options.nextBtn).addClass(options.offClass);
			
			// check if prev and next nav items might be necessary
			if (pages > 1) {
				obj.find(options.nextBtn).removeClass(options.offClass);
				obj.find(options.prevBtn).click(
					function(){
						moveScroll("previous");
						$(this).blur();
						return false;
					}
				);
				obj.find(options.nextBtn).click(
					function(){
						moveScroll("next");
						$(this).blur();
						return false;
					}
				)
			}
		});
		function moveScroll(direction) {
			switch (direction) {
				case "previous":
					obj.find(options.nextBtn).removeClass(options.offClass);
					(pageIndex > 1) ? (pageIndex--) : (pageIndex = 1);
					if (pageIndex == 1) {
						obj.find(options.prevBtn).addClass(options.offClass);	
					}
					break;
				case "next":
					obj.find(options.prevBtn).removeClass(options.offClass);
					(pageIndex < pages) ? (pageIndex++) : (pageIndex = pages);
					if(pageIndex == pages){
						obj.find(options.nextBtn).addClass(options.offClass);	
					}
					break;
			}
			scrollAmount = (options.scrollCount * options.pxPerItem) * (pageIndex - 1);
			scrollDiv.animate({scrollLeft: scrollAmount},"fast");
		}
	}
})(jQuery);  
/*------ END PHOTO SCROLL -----*/
