// A list of the images to be rotated through
var imgArray = [
"/homeImages/Zhabei.jpg", //2
"/homeImages/8by8Exterior.jpg", //3
"/homeImages/PeterLoughheedExterior.jpg", //4
"/homeImages/PeterLoughheedWindows.jpg", //4b
"/homeImages/PeterLoughheedRoom.jpg", //4c
"/homeImages/SAITparkadeExterior.jpg",//5
"/homeImages/SAITparkadeInterior.jpg", //5b
"/homeImages/Bantrel.jpg", //6
"/homeImages/sunshineExterior.jpg", //7
"/homeImages/sunshineInterior.jpg", //7b
"/homeImages/EastVillage.jpg" //1
];


var txtArray = [
"Zhabei Magnolia Stadium | Shanghai, China",
"8th & 8th University of Calgary Downtown Campus | Calgary, Alberta",
"Peter Lougheed Centre | Calgary, Alberta | MTA in collaboration w/HOK",
"Peter Lougheed Centre | Calgary, Alberta | MTA in collaboration w/HOK",
"Peter Lougheed Centre | Calgary, Alberta | MTA in collaboration w/HOK",
"SAIT Parkade | Calgary, Alberta | MTA in collaboration w/Bing Thom Architects", 
"SAIT Parkade | Calgary, Alberta | MTA in collaboration w/Bing Thom Architects",
"Bantrel Place | Calgary, Alberta | MTA in collaboration w/&Co Architects", 
"Sunshine Ski Resort | Banff, Alberta", 
"Sunshine Ski Resort | Banff, Alberta",
"East Village Pebble | Calgary, Alberta | MTA in collaboration w/Broadway Malyan"
];


// Pre load images that will be used for the homepage hero

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

// Swap the image with the next image in the imgArray
function swapHero( el, imgArray, i ) {
	// Fade out the hero
	el.fadeOut("slow", function() {
		
		// Swap in the new image
		$(this).attr('src', imgArray[i]); 
		document.getElementById("text-swap").innerHTML = txtArray[i];
		// Fade in the hero
		$(this).fadeIn("slow", function() {
			
			// Start from the beginning from the image array
			i = ( i == imgArray.length - 1 ) ? 0 : i + 1;
			
			// Recursive call
			setTimeout( "swapHero( $('#hero-swap'), imgArray, " + i + " )", 3000 );
			
		});
	});
}

$(document).ready( function() {

		preloadImages( imgArray );
		setTimeout( "swapHero( $('#hero-swap'), imgArray, 0 )", 3000 );
		
});

