pageLoaded = 0;				// Prevent access to layers until they're loaded
DEBUG_ON = false;

delayedPreloadImages = new Array();
onloadFunctions = new Array();

// Set the pageLoaded variable to denote that the layers are ready to be used 
function doLoadProc() {
	if (DEBUG_ON) {
		dbg = document.createElement("textarea");
		dbg.id = "debugBox";
		dbg.value = "";
		dbg.cols = 110;
		dbg.rows = 20;
		document.body.appendChild(dbg);
	}

	pageLoaded = 1;
	
	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;
}

eWepCustomWindowObj = null;
function eWEPCustomWindow(url, width, height) {
	eWepCustomWindowObj = window.open(url, "eWEPCustomWin", "width=" + width + ",height=" + height + ",scrollbars=1,resizable=1");
	return false;
}

swapStyle = function(id, c) {
	tmp = document.getElementById(id);
	if (tmp) {
		tmp.className = c;
	}
}

currentTab = "features";
showTab = function(tabId) {
	if (tabId != currentTab && !noTabs) {
		hideLayer(currentTab);
		swapImg("tabImg", eval(tabId + "Tab"));
		showLayer(tabId);
		currentTab = tabId;
	}
}

showLineTab = function(tabId) {
	if (tabId != currentTab) {
		hideLayer(currentTab);
		swapImg(currentTab + "Tab", eval(currentTab + "Off"));
		swapImg(tabId + "Tab", eval(tabId + "On"));
		showLayer(tabId);
		currentTab = tabId;
	}
}

noTabs = false;
showBubble = function() {
	if (document.getElementById("bubble")) {
		showLayer("bubble");
		showLayer("hideBubble");
		setTimeout(function() { showNutrient("starting"); }, 0);
	}
}

hideBubble = function() {
	if (document.getElementById("bubble")) {
		hideLayer("bubble");
		hideLayer("hideBubble");
		showTab("nutritional");
	}
}

showformBubble = function() {
	if (document.getElementById("formBubble")) {
		showLayer("formBubble");
		showLayer("hideBubble");
	}
}

hideformBubble = function() {
	if (document.getElementById("formBubble")) {
		hideLayer("formBubble");
		hideLayer("hideBubble");
	}
}

showInternational = function() {
	if (document.getElementById("internationalMenu")) {
		showLayer("internationalMenu");
		showLayer("hideDhtmlInt");
	}
}

hideInternational = function() {
	if (document.getElementById("internationalMenu")) {
		hideLayer("internationalMenu");
		hideLayer("hideDhtmlInt");
	}
}

currentNutrient = "";
showNutrient = function(nutrientId) {
	hideLayer(currentNutrient);
	showLayer(nutrientId);
	currentNutrient = nutrientId;
}


debug = function(dbgText) {
	if (DEBUG_ON) {
		document.getElementById("debugBox").value += dbgText;
		document.getElementById("debugBox").value += "\n";
		document.getElementById("debugBox").scrollTop = document.getElementById("debugBox").scrollHeight;
	}
}
