/*
	Summary
	+--------------------------------------+
	Project:		Fusion
	Date Created:	29 June 2010
	Author:			KG
	+--------------------------------------+
*/

// Execute jQuery when the DOM is ready
$(document).ready(function(){	
						   
	var bronzemanStart = new Date("August 4, 2012 12:00:00");
	//austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
	//austDay.setFullYear();
	if($("#countdownClock").length > 0){
	$("#countdownClock").countdown({
								   until: bronzemanStart,
								   format: 'DHMS'
								   });
	}
	/*
		A random image for the homepage
	
	if($("#mainImage").length){
		$("#mainImage").addClass(selectRandomHomepageImage());	
	}*/
	/*
		The font on the parent list item link is 0px so
		it cannot be clicked on. The following code
		takes the href attribute from the link and wraps
		it around the parent li keeping the page
		valid. Nice.
	*/
	$("#topNav ul li").click(function(){
		window.location = $("a", this).attr("href");						  
	});
	
	/*	Make the large buttons a link keeping the page
		valid.
	
	if($("#mainButtons div").length){
		$("#mainButtons div").click(function(){
			window.location = $("a", this).attr("href");
		});
	}*/
	/* 
		target="_blank" is invalid XHTML, use JS to make any
		links with rel="blank" pop in a new window.
	
	$("a").each(function(){
		if($(this).attr('rel') == 'blank')
			$(this).attr('target', '_blank');
	});*/
	/*
		On the Inner Pages we want the first paragraph to be different
	
	if($("#page p").length){
		$("#page p:first").addClass("first");
	}*/
}); // End document.ready()

// Execute jQuery when the final image has loaded
$(window).load(
    function() {
		/*
			Fade in the text over the main image
			AFTER the images have loaded.
		*/
        if($('#mainImageText').length){
			$('#mainImageText').fadeTo(1000, 0.8);
		}
    }
); // End window.load()

// Select a random image for the homepage
function selectRandomHomepageImage(){
	// Define these classes in include/fusion.css, or else...
	var mainImageClasses=["homepageImage1", "homepageImage2", "homepageImage3", "homepageImage4"];
	var randomNumber = Math.floor(Math.random() * mainImageClasses.length)
	return mainImageClasses[randomNumber];
}
