var siteImages = new Array(
	"http://" + location.hostname + "/_images/layout/background/background.jpg",
	"http://" + location.hostname + "/_images/layout/logo.jpg",
	"http://" + location.hostname + "/_images/layout/content_header.jpg",
	"http://" + location.hostname + "/_images/layout/nav/aboutus_on.jpg",
	"http://" + location.hostname + "/_images/layout/nav/aboutus_off.jpg",
	"http://" + location.hostname + "/_images/layout/nav/profiles_on.jpg",
	"http://" + location.hostname + "/_images/layout/nav/profiles_off.jpg",
	"http://" + location.hostname + "/_images/layout/nav/achievements_on.jpg",
	"http://" + location.hostname + "/_images/layout/nav/achievements_off.jpg",
	"http://" + location.hostname + "/_images/layout/nav/brands_on.jpg",
	"http://" + location.hostname + "/_images/layout/nav/brands_off.jpg",
	"http://" + location.hostname + "/_images/layout/nav/events_on.jpg",
	"http://" + location.hostname + "/_images/layout/nav/events_off.jpg",
	"http://" + location.hostname + "/_images/layout/nav/gallery_on.jpg",
	"http://" + location.hostname + "/_images/layout/nav/gallery_off.jpg",
	"http://" + location.hostname + "/_images/layout/nav/contact_on.jpg",
	"http://" + location.hostname + "/_images/layout/nav/contact_off.jpg",
	"http://" + location.hostname + "/_images/content/aboutus/aboutus_main_image.jpg",
	/*"http://" + location.hostname + "/_images/content/profiles/thumbs/profiles_brian_small_1.jpg",
	"http://" + location.hostname + "/_images/content/profiles/thumbs/profiles_thom_small_4.jpg",
	"http://" + location.hostname + "/_images/content/profiles/thumbs/profiles_margaret_small_2.jpg",
	"http://" + location.hostname + "/_images/content/profiles/thumbs/profiles_cassie_small_6.jpg",
	"http://" + location.hostname + "/_images/content/profiles/thumbs/profiles_sue_small_3.jpg",
	"http://" + location.hostname + "/_images/content/profiles/thumbs/profiles_nick_small_5.jpg",
	"http://" + location.hostname + "/_images/content/profiles/norms/profiles_thom_large_4.jpg",
	"http://" + location.hostname + "/_images/content/profiles/norms/profiles_margaret_large_2.jpg",
	"http://" + location.hostname + "/_images/content/profiles/norms/profiles_cassie_large_6.jpg",
	"http://" + location.hostname + "/_images/content/profiles/norms/profiles_brian_large_1.jpg",
	"http://" + location.hostname + "/_images/content/profiles/norms/profiles_sue_large_3.jpg",
	"http://" + location.hostname + "/_images/content/profiles/norms/profiles_nick_large_5.jpg",*/
	"http://" + location.hostname + "/_images/content/achievements/ach_separator.jpg");

var imgLen = siteImages.length;
//loaded:			is an array to tell a function if the particular image has already been loaded, so it 
//						can skip loading it again.
//preImages:	this is the array that the actually loaded image will live in. this is an array of 
//						images.
//currCount:	just a counter.
var loaded = new Array();
var preImages = new Array(); 
var currCount = 0;

function loadImages() {
	//we're going to loop through the siteImages (image locations) and create a matching Image in the 
	//preImages array
	var cunt = 0;
	for (var i = 0; i < imgLen; i++) {
		//creating the Image object
		preImages[i] = new Image();
		//setting it's src to where you've said the image exists
		preImages[i].src = siteImages[i];
		//initializing the loaded array to 0 for the matching Image object
		loaded[i] = 0;
	}
	//once we're done looping, call the checkload function
	checkLoad();
}

function checkLoad() {
	//this check sees if all the loading is done, if it is, calls a final function and returns to break out
	//of the function
	if (currCount == imgLen) { drawCurtain(); return; }
	//alert(currCount + ' | ' + imgLen);
	//looping through the images you want to preload, again.
	for (var i = 0; i < imgLen; i++) {
		//if the current image is NOT loaded and preImages[i].complete (meaning the Image object is done creating
		//itself), then we want to do stuff.
		if (!loaded[i] && preImages[i].complete) {
			//set the loaded element to true so it doesn't try to reload the same image. also increase the count by 
			//one, as we just loaded an image.
			loaded[i] = 1; 
			currCount++;
			//this is a prototype (javascript library) thing to change a progress indicator. this is esthetic and not
			//important to the actual preloading.
			var l = i + 1;
		  var perc = l / imgLen * 100;
			$('preloader_container').innerHTML =  '<center><span style="font-family:arial;font-size:11px;font-weight:bold;">' + Math.round(perc) + '% Loaded.</span></center>';
			//$('curtain').innerHTML += preImages[i].src + '<br>';
			//now we're going to call the function again, recursive. images might not be created and loaded yet, so we
			//want to keep going through until all the images are preloaded. that's why there's the laoded array to
			//make sure we don't end up in an infinite loop. 
			checkLoad();
			return;
		}
	}
	//this timeout is here in case the last itteration doesn't go into the !loaded[i] && preImages[i].complete block,
	//we need the function to call itself.
	setTimeout("checkLoad()",10);
}

function drawCurtain() {
	curtainFadeOut('curtain');
	$('preloader_container').innerHTML = '';
	$('logo_animation').innerHTML = '';
	$('au_on').fireEvent('mouseleave');
	$('pr_on').fireEvent('mouseleave');
	$('ac_on').fireEvent('mouseleave');
	$('br_on').fireEvent('mouseleave');
	$('ev_on').fireEvent('mouseleave');
	$('ga_on').fireEvent('mouseleave');
	$('co_on').fireEvent('mouseleave');
}
