$(document).ready(function() {			
	// the array to hold the pages to pull using ajax
	var hp_pages = new Array();
	hp_pages[0] = "/includes/hp-announcements.inc.php";
	hp_pages[1] = "/includes/hp-specials.inc.php";
	hp_pages[2] = "/includes/hp-bands.inc.php";
	
	$(function() {
		var current_index = -1;
		var content_open = false;
		
		// hide content by default
		$("#hp-tabs-content").hide();
		
		$("#hp-tabs > a").click(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").load(hp_pages[index], function () {
					$("#hp-tabs-content").fadeIn("fast");
				});
				
				// 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;
			}
				
			return false;
		});
		
		$("a.close").live("click", function () {
			$("#hp-tabs-content").hide();
			
			// remove class
			$("#hp-tabs > a").eq(current_index).removeClass("active");
			
			// reset index
			current_index = -1;
			
			return false;
		});
		
		// calendar tooltip stuff
		$("#calendar a").tooltip({tip: '#tooltip', position: ['center', 'left'], offset: [0, 0], onBeforeShow: showTip, onHide: hideTip});
		
		$("#calendar a").click(function () {
			return false;
		});
		
		function showTip() {
			var tip = $(this.getTip());
			var target = $(this.getTrigger());
			var url = $(target).attr("href");
			$(tip).load(url);
		}
		
		function hideTip(){
			var tip = $(this.getTip());
			$(tip).html("");
		}
		
		
		// links
		$("#links").tabs("#links div.linksNav", {tabs: 'h4', effect: 'slide', initialIndex: 0});
	});
	
	// horizontal scrollables. each one is circular and has its own navigator instance
	if ($(".item").size() > 1) {
		var horizontal = $(".scrollable").scrollable({size: 1}).circular().navigator(".navi").autoscroll({ 
			steps: 1, 
			interval: 6000         
		});
		
		// when page loads setup keyboard focus on the first horzontal scrollable
		horizontal.eq(0).scrollable().focus();
	}
});