

$(document).ready(function(){
	
	$("#privacypolicy a[rel]").overlay({
		fixed: false,
		top: '10%',
		left: 'center',		
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find(".contentWrap");
			wrap.load(this.getTrigger().attr("href"));
		}

	});
	
	//Obscure the email address 
	
	var name = "sales";
	var dmname = "zenentertainment.com";
	var subj = "?subject=GiGSE Event Request";
	$('.globaligame').click(function(){
		
		window.location.href = "mailto:"+ name + "@" + dmname+subj;
		return false;
		
	});
	
	/*$("#casino_leadin").overlay({
		load: true,
		top: "10%",
		left: "35%",
		onLoad: function() {
			$(".dimmer").css("height", $(document).height()).css("width", $(document).width()).offset({top:0,left:0});
			$(".dimmer").fadeIn();
			
		},
		
		onClose: function() {
			$(".dimmer").fadeOut();
		}
		
		
	});*/
	

	
	
	$(window).resize(function() {
	  positionglowystuff();
	});
	
	
	//preload the hover states

	var slideshowDiv = ["#brand-", "#sponsor-", "#target-"];

	$(slideshowDiv[0]+"content").show();
	$(slideshowDiv[0]+"tab").animate({
		"backgroundPosition" : "300px"
		}, 500, 'swing');

	
	$(slideshowDiv[1]+"content").hide();
	$(slideshowDiv[2]+"content").hide();

	
	splashnavinteraction(slideshowDiv);


	
	$("#pitches ul.tabs").tabs("> .pane", {
		
		effect: 'default',
		onClick: function(e, tabIndex){
			//Selects the pane
			pane = $('.pane').get(tabIndex);
			
			//Variables
			paneHeight = $(pane).height();
			whoHeight = $("#whoisusingzen").outerHeight();
			
			
			if (paneHeight < 650){
				$(pane).animate({height: '640px'});
			
			} else {
				//$(".pitch-content").animate({height:($(pane).height())+'px'});
			}
			
			
			//Pitches tab is always the same as the panes outerheight, 
			//so I wait until the very end to calculate it. 
			$("#pitches-tab").animate({height:($(pane).outerHeight())+'px'});
			$("#whoisusingzen .content").animate({height:($(pane).outerHeight()-53)+'px'}, positionglowystuff);

						
		}		
		
	});
		

	$("#whoisusingzen ul.tabs").tabs("> .pane"); 
	
	//Positions background glowy stuff
	positionglowystuff();

	$("#whoisusingzen").corner();

});


//Typekit loader for fonts
try{Typekit.load();}catch(e){}


//positions glowy stuff behind #main
//Just another charge on the technical debt card.
function positionglowystuff(){
	leftvar = $("#main").offset().left;
	topvar = $("#main").offset().top;
	mainheight = $("#main").height();

	$("#background-top-glow img").offset({top: topvar-130, left: leftvar-40 });
	$("#background-bottom-glow img").offset({top: topvar+mainheight, left: leftvar-40});
	



}


//hack until I have time to re-write the tab view plugin 
//to not b	e useless
function splashnavinteraction(slideshowDiv){
	
	
	$("#brand-tab").click(function(){
			toggleslides(slideshowDiv, 0);
			clearInterval(slideshow);
	});

	$("#sponsor-tab").click(function(){
			toggleslides(slideshowDiv, 1);
			clearInterval(slideshow);
	});

	$("#target-tab").click(function(){
			toggleslides(slideshowDiv, 2);
			clearInterval(slideshow);
	});


		//use scope to set/cancel setInterval. refactor later
		var slideshow; 
		var counter = 0;
		
		startSlideShow(3500);
		
		function startSlideShow(time){
			
			slideshow = setInterval(function(){
					counter++;
	
					toggleslides(slideshowDiv,(counter%slideshowDiv.length));
					
				
			} ,time);
		}
		
}



function toggleslides(slidearray, activeslide){
	$.each(slidearray, function(i, k){
			if( i == activeslide){

				$(slidearray[i]+"tab").animate({
					"backgroundPosition" : "300px"
					}, 500, 'swing');
				$(slidearray[i]+"content").show(500);

			} else if (i != activeslide){
					$(slidearray[i]+"tab").animate({
						"backgroundPosition" : "0px"}, 500, 'swing');
					$(slidearray[i]+"content").hide(500);


			}	
		
		
		
	});
}


