 $(document).ready(function() {
	$("body").addClass("JSEnabled");
	if("#home"){
		enableIntro();	
	}
	toLoad = new String();	 	 	
	$.blockUI.defaults.overlayCSS = {};	 	 	 
	
	$(".navLink").click(function(event){
		$(".navLink").removeClass("current");
		$(this).addClass("current");	 		
						
		targetDiv = $(this).attr('id').replace(/nav/, "");
		toLoad = $(this).attr('href')+" #"+targetDiv;
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);   				
		
		loadContent();


		return false;   
		   
	});			
	
	var hash = window.location.hash.substr(1);
	if(hash.length > 0){
		targetDiv = hash;
		toLoad = hash + ".aspx #"+targetDiv;	
		
		setTimeout(loadContent, 100);
	}


 });
 
function flipFrame(){
	posY = (parseInt($(".active").css("backgroundPosition").split(" ")[1].split("px")[0]));
	if(posY >= -354){
		posY = posY - 118;
	} else {
		posY = 0;
	}
	$(".active").css({"background-position" : "left " + posY + "px"});	
}


function loadContent() { 		    
	$("#header").block({message : null});
	
	outgoing = $('#content div:first');
	outgoing.css({"position" : "absolute", "top" : "0", "height" : "100%"});			    
	$("#content").append('<div> </div>');
	newContent = $('#content div:last');				
				
	$('#load').remove();   
	$('#ajax').append('<span id="load">Loading...</span>');   
	$('#load').fadeIn('normal');
	
	newContent.load(toLoad,'', showNewContent);  
}			


function showNewContent() {   
	$('#content').cycle({fx : 'scrollLeft', autostop : 1, end : completeTransition, delay : -5000, timeout : 2});			    
}


function completeTransition() {
	hideLoader();
	outgoing.remove();
	$('#content div:first').css({"position" : "static"});
	$('#content').css({"overflow-y" : "auto", "width" : "100%", "height" : "100%"});

	$("#header").unblock();				    					        
	if(targetDiv == "work" || targetDiv == "latest"){
		enableFlips();			
	}
	if(targetDiv == "showreel" || targetDiv == "project"){
		enableFlash();			    			
	}		
	if(targetDiv == "home" || targetDiv == "index" ){
		enableIntro();	
	}
}		


function hideLoader() {   
	$('#load').fadeOut('normal');   
}   


function enableFlips(){
	$(".workImage").mouseover(function(){
		$(this).addClass("active");
		$(this).css({"backgroundPosition" : "left -118px"});						
		frameInterval = setInterval("flipFrame()",1000);			
	});


	$(".workImage").mouseout(function(){			
		clearInterval(frameInterval);
		$(this).removeClass("active");
		$(this).css({"backgroundPosition" : "left top"});
	});
	$("#content ul li a").click(function(event){
		$(".navLink").removeClass("current");				
		targetDiv = "project";
		toLoad = $(this).attr('href')+" #"+targetDiv;
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		
		loadContent();
																
		return false
	});
}


function enableFlash(){
	var flvSrc = $("#flvSource").html();
	$("#flashPlaceholder").flash(
		{src: '/media/120738/bolderplayer.swf', 
		width: 544, 
		height: 306, 
		wmode : "transparent",
		allowFullScreen : true,
		version: '8', 
		expressInstall: true,
		flashvars: { flvURL: flvSrc}}
	);	
        $("#alt").hide();
	
}	    	    	


function enableIntro(){
	var flvToLoad = $("#flvSource").html();
	$("#home").flash(
		{src: flvToLoad,
		 width: 1024,
		 height: 655,
		 wmode: 'transparent',
		 version: '8',
		 expressInstall: true} 
	)			
	$("#home img").hide();
}






