pageLoaded = 0;				// Prevent access to layers until they're loaded

delayedPreloadImages = new Array();
onloadFunctions = new Array();

// Set the pageLoaded variable to denote that the layers are ready to be used 
$(function() {
	pageLoaded = 1;
	
	$("a[target=_modal]").ceebox();

	window.onload = function() {
		for (i in delayedPreloadImages) {
			if (typeof delayedPreloadImages[i] != "function") {
				eval(i + " = preload('" + delayedPreloadImages[i] + "')");
			}
		}
		
		for (i in onloadFunctions) {
			if (i != "getIndex") {
				onloadFunctions[i]();
			}
		}
	}
});

// swapImg - swaps an image for another that has already been preloaded.
function swapImg(imgName, preloadedImg) {
	if (document[imgName]) {
		document[imgName].src = preloadedImg.src;
	}
}

function preload(imgSrc) {
	img = new Image();
	img.src = imgSrc;
	return img;
}

function delayedPreload(imgName, imgSrc) {
	if (!pageLoaded) {
		eval(imgName + " = new Image()");
		delayedPreloadImages[imgName] = imgSrc;
	} else {
		eval(imgName + " = preload('" + imgSrc + "')");
	}
}

function addOnLoad(func) {
	onloadFunctions[onloadFunctions.length] = func;
}

selectBoxGo = function(selBox) {
	if (selBox.options[selBox.selectedIndex].value.length) {
		sel = selBox.options[selBox.selectedIndex].value.split(",");
		url = sel[0];
		if (url.indexOf("http") != 0) {
			url = "http://<cfoutput>#http_host#</cfoutput>" + url;
		}
		target = "_top";
		if (sel[1]) {
			target = sel[1];
		}
		
		switch (target) {
			case "_modal":
				$.fn.ceebox.popup("<a href='" + url + "'></a>", {});
				break;
			default:
				window.open(url, target);
				break;
		}
	}
}

