jQuery.preloadImages = function()
{	for (var i = 0; i < arguments.length; i++)
	{	jQuery("<img>").attr("src", arguments[i]);	}
};

$(document).ready(function() {
	
	var toRollOver = null; // needed for timeout script later
	
	// preload main navigation images
	$.preloadImages(
		"images/homeHover/home1.jpg",
		"images/homeHover/home8.jpg",
		"images/homeHover/home3.jpg",
		"images/homeHover/home4.jpg",
		"images/homeHover/home5.jpg"
	);
	
	// Main image fade on nav rollover
	function swapImage(obj) {
		$('#homeContainer img.imgOld').remove();
		$('#homeContainer img').attr('class', 'imgOld');
		var getClass = obj.attr('class').replace(" current", "");
		$('#homeContainer').queue(function () {
			$(this).append('<img src="images/homeHover/' + getClass + '.jpg" width="635" height="434" class="imgNew" />').dequeue();
			$('img.imgNew').fadeIn(200).dequeue();
		});
	}
	
	// clear timeout and swap new iamge
	$('#mainNav a img').mouseover(function () { $.clear(toRollOut); swapImage($(this)); });
	// waits to execute the function fox x amount of milliseconds
	$('#mainNav a img').mouseout(function () {
		toRollOut = $.timeout(function() {
			swapImage($('img.home1'));
		}, 500);
	});

});


