/* Insight Web Design - Copyright 2008

image pre-loader

*/

var firstTime = true;
var autoFade = true;
var imageCounter = 0;

function preLoad()
{
	var i = 0;
	var pic = new Array();
	
	if (section != 'home')
	{
		disableNavigation();
		
		// moved from linkText script to blank out the ALT tag
		window.onLoad = document.images.link_text.setAttribute("alt", "");
	}
	
	// preload standard page image elements
	if (firstTime == true)
	{
		var pic1 = new Image();
		pic1.src = "images/next.gif";
		
		var pic2 = new Image();
		pic2.src = "images/back.gif";
		
		var pic3 = new Image();
		pic3.src = "images/next_hover.gif";
		
		var pic4 = new Image();
		pic4.src = "images/back_hover.gif";
		
		var pic5 = new Image();
		pic5.src = "images/loft_on.gif";
		
		var pic6 = new Image();
		pic6.src = "images/extensions_on.gif";
		
		var pic7 = new Image();
		pic7.src = "images/timberframe_on.gif";
		
		var pic8 = new Image();
		pic8.src = "images/garage_on.gif";
		
		var pic9 = new Image();
		pic9.src = "images/kitchens_on.gif";
		
		var pic10 = new Image();
		pic10.src = "images/plastering_on.gif";
		
		var pic11 = new Image();
		pic11.src = "images/contact_on.gif";

		var pic12 = new Image();
		pic12.src = "images/white_spacer.gif";

		
		firstTime = false;
	}
	
	// preload small gallery photos on specific page
	while (i <= photos.length -1)
	{
		pic[i] = new Image();
		pic[i].src = photos[i];
				
		if (section != 'home')
		{
		pic[i].onLoad = imageLoaded();
		}
		i ++;		
	}
}


// when a photo is pre-loaded the counter increments
// when all the photos have loaded then the gallery begins
function imageLoaded()
{
	imageCounter ++;
	
	if (imageCounter == photos.length)
	{		
		// switches the 'gallery loading picture' for the 'gallery loaded picture'
		window.setTimeout("document.images.photoslider.src='images/gallery_loaded.gif';document.images.bottom_photo.src='images/gallery_loaded.gif';", 1500);
		
		// fades the 'gallery loaded picture'
		window.setTimeout("document.images.photoslider.src=photos[which]; fadeImage();", 1500 + 1000);
		
		// replaces the 'gallery loaded picture' with the 1st photo, then starts auto-fade if the photo is a fading photo
		window.setTimeout("document.images.bottom_photo.src=photos[which]; autoForwards();", 1500 + 1000 + 1000 + timeout);		
	}
}
