$(document).ready(function(){
	setupCalendar();
	setupHistory();
	setupPackages();
	setupSubmitButton();
	
	$("#form-signup").validate();
});

function setupSubmitButton()
{
	$('.button-submit').hover(function() {
		$(this).css('background-position','0 -40px');
	},
	function() {
		$(this).css('background-position','0 0');
	});
}

function setupCalendar()
{
	//$("#calendar table tr td[background] a.image").css("opacity", "0");
	
	$("#calendar table tr td[background] a.image").hover( function (){
		$(this).stop().animate({opacity: 0}, 500);
	}, 
	function (){
		$(this).stop().animate({opacity: 1}, 500);
	});
	
	$("#calendar .copy").hide();
	var replaceText = $(".sidebar-description .replace-text");
	var originalCopy = replaceText.html();
		
	$("#calendar a:not(.arrow, .button)").click( function (){
		var updatedCopy = $(this).next('.copy').html();
		replaceText.html(updatedCopy);
		
		$("a.return").click( function (){
			replaceText.html(originalCopy);
		});
	});
}

function setupHistory()
{
	$("#history-visuals").scrollable({size: 1, loop:true});
}

function setupPackages()
{        
	var currentPrimary = 0;
	var totalPrimary = $("#slideshow-nav .top-level").size();
	
	var secondary = $("#slideshow-nav li .sub-nav").tabs(".sub-nav li .pane", {
		tabs: 'a:not(.link)',
		effect:'fade',
		initialIndex: -1,
		api:true
	});
	
	var primary = $("#slideshow-nav").tabs("#slideshow-nav li .sub-nav", {
		tabs: 'li a.top-level',
		effect:'fade',
		initialIndex: 0,
		onClick: function(event, tabIndex) { 
			//$(".sub-nav li .pane").hide();
			currentPrimary = this.getIndex();
		},
		api:true
	});
	
	$("#slide-prev").click(function (){
		if(currentPrimary - 1 == -1){
			currentPrimary = totalPrimary - 1;
		} else {
			currentPrimary -= 1;
		}
		$(".top-level:eq(" + currentPrimary + ")").click();
	});
	
	$("#slide-next").click(function (){
		if(currentPrimary + 1 == totalPrimary){
			currentPrimary = 0;
		} else {
			currentPrimary += 1;
		}
		$(".top-level:eq(" + currentPrimary + ")").click();
	});
	
	var slideshow = $("#slideshow-visuals").scrollable({
			size: 1,
			loop:true,
			globalNav:true,
			clickable:false
		}).circular().navigator({ 
			navi: "#slideshow-nav",
			naviItem: 'a:not(.link)', 
			activeClass: 'current',
			api:true
	});
}