


var countDowner=0;	// time before a fade-out can happen
// var countDowner2=0;


preloadImages();
countdown();

$(function() {
	

	

	$('.nav').click(function() {
		countDowner=0;
		showMenu();
	});

	$('.nav').hover(function() {
		countDowner=0;
		showMenu();
	});


	$('#watch').click(function() {
		$('#filmContent').html($('#filmContent').html());	// reload the film
	});
	

	/*
	|----------------------------------------------------------------------------------------------------------------------------------
	| centerBoxes
	|----------------------------------------------------------------------------------------------------------------------------------
	| 
	*/
	centerBoxes();

	$(window).resize(function() {
		centerBoxes();
	});

	$(window).trigger('resize');

})




/*
|----------------------------------------------------------------------------------------------------------------------------------
| showMenu
|----------------------------------------------------------------------------------------------------------------------------------
| 
*/
function showMenu(){
	
	if (countDowner<=0)	{
		
		if (!$('.nav a').is(":visible")){

			$('.nav a').fadeIn('slow');
			$('.social_nav').fadeIn('slow');
		}
	}

	countDowner=5;				// time in seconds before fadeout
}


/*
|----------------------------------------------------------------------------------------------------------------------------------
| centerBoxes
|----------------------------------------------------------------------------------------------------------------------------------
| 
*/
function centerBoxes(){
	
	$('.content').each(function(){
	
		var left=(document.body.clientWidth-$(this).width())/2;
		var top=(document.body.clientHeight-$(this).height())/2;

		$(this).css('left',left+'px');
		$(this).css('top',top+'px');

	});

}


/*
|----------------------------------------------------------------------------------------------------------------------------------
| fadeIn Counter 1
|----------------------------------------------------------------------------------------------------------------------------------
| 
*/
function countdown(){ 

	countDowner--;
	if (countDowner<0) {
		countDowner=0;

		if ($('.nav a').is(":visible")){

			$('.nav a').fadeOut('slow');
			$('.social_nav').fadeOut('slow');	
		}
	}

	setTimeout("countdown()",1000);
}


/*
|----------------------------------------------------------------------------------------------------------------------------------
| preloadImages
|----------------------------------------------------------------------------------------------------------------------------------
| 
*/
function preloadImages(){ 

	$("img").each(function(){
	  (new Image()).src = $(this).attr('src');   
	});


	$("a").each(function(){

		if ($(this).css('background-image').substring(0,4)=='url('){

			var bits=$(this).css('background-image').split('"');		// the CSS needs to us " to surround the image URL
			(new Image()).src=bits[1];   
		
		
			// there's also a hover version... which is always the main version with a 2 appended.

			var hover=bits[1].replace('.gif','2.gif');	 // assume gifs rather than pngs
			(new Image()).src=hover;
		}
	});

}







