// JavaScript Document
jQuery(function( $ ){		
	var urls = [ 'homeMastheadBkgd1', 'homeMastheadBkgd2', 'homeMastheadBkgd3', 'homeMastheadBkgd4', 'homeMastheadBkgd5', 'homeMastheadBkgd6', 
					'homeMastheadBkgd7', 'homeMastheadBkgd8', 'homeMastheadBkgd9' ];
	$.preload( urls, {
		base:'/imgs/slideshow/',
		ext:'.jpg',
		onComplete:function( data ){
			var img = new Image();
			img.src = data.image;
		},
		onFinish:function(){
			rotateImages(9);
		}
	});
});
var mastheadBkgd = new Array();
mastheadBkgd[0] = "/imgs/slideshow/homeMastheadBkgd1.jpg";
mastheadBkgd[1] = "/imgs/slideshow/homeMastheadBkgd2.jpg";
mastheadBkgd[2] = "/imgs/slideshow/homeMastheadBkgd3.jpg";
mastheadBkgd[3] = "/imgs/slideshow/homeMastheadBkgd4.jpg";
mastheadBkgd[4] = "/imgs/slideshow/homeMastheadBkgd5.jpg";
mastheadBkgd[5] = "/imgs/slideshow/homeMastheadBkgd6.jpg";
mastheadBkgd[6] = "/imgs/slideshow/homeMastheadBkgd7.jpg";
mastheadBkgd[7] = "/imgs/slideshow/homeMastheadBkgd8.jpg";
mastheadBkgd[8] = "/imgs/slideshow/homeMastheadBkgd9.jpg";
var loopCounter = 0;
function rotateImages(imagesLength) {
	if(loopCounter == (imagesLength - 1)) { loopCounter = 0; } else { loopCounter++; }
	$("#masthead").fadeTo(2000, 1.0, function() {
		$("#mastheadDouble").css("background", "transparent url("+mastheadBkgd[loopCounter]+") no-repeat 100% 0");
		$("#masthead").fadeTo(4000, 0.0, function() {
			if(loopCounter == (imagesLength - 1)) { loopCounter = 0; } else { loopCounter++; }
			$("#masthead").css("background", "transparent url("+mastheadBkgd[loopCounter]+") no-repeat 100% 0");
			$("#masthead").fadeTo(2000, 0.0, function() {
				$("#masthead").fadeTo(4000, 1.0, function() { rotateImages(imagesLength); });
			});
		});
	});
}
