// Preload
(function($) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
	    }
	};
})(jQuery);
$.preLoadImages("/images/hero-2.jpg", "/images/hero-3.jpg", "/images/hero-4.jpg");

$(function() {
	heroDelay = 7500; // Delay between transitions
	heroTime = 500; // Transition time
	heroCount = 1; // Counter
	heroLimit = 4; // Number of hero images
	
	function heroAnimate()
	{
		// Increment count
		heroCount++;
		if (heroCount>heroLimit)
		heroCount = 1;
		
		$("#hero").delay(heroDelay).animate({"opacity" : "0"}, heroTime, function() {
			$(this).attr("src", "/images/hero-"+heroCount+".jpg");
			$(this).animate({"opacity" : "1"}, heroTime, heroAnimate);
		});
	}
	
	// Kick things off...
	heroAnimate();
});
