var currentActiveRef = null;
var submenuvalid = false;
var menutimer = null;
function ShowSubNav(anchor, navigationname) {
	submenuvalid = true;
	if (menutimer != null) {
		window.clearTimeout(menutimer);
	}
	if (currentActiveRef != null) {
		if (currentActiveRef.style) {
			currentActiveRef.style.visibility = 'hidden';
		}
		else {
			currentActiveRef.visibility = 'hidden';
		}
	}
	if (navigationname == "") {
		currentActiveRef = null;
	}
	else {
		var subNavRef = getObjectById(navigationname);
		if (subNavRef != null) {
			//==================================//
			// Calculate x-coord of sub nav
			//==================================//
			var xpos = 0;
			
			if (anchor.offsetLeft != null && anchor.offsetLeft == 0) {
				xpos = offsetX(anchor, 0);
			}
			else {
				xpos = anchor.x;
			}

/*			if (document.all) {
				alert("document.all");
				xpos = offsetX(anchor, 0);
			}
			else if (anchor.offsetLeft) {
				alert("anchor.offsetLeft");
				xpos = anchor.offsetLeft;
			}
			else {
				alert("anchor.x");
				xpos = anchor.x;
			}*/
//			alert("xpos: " + xpos);
			currentActiveRef = subNavRef;
			if (currentActiveRef.style) {
				currentActiveRef.style.left = xpos;
				currentActiveRef.style.visibility = 'visible';
			}
			else {
				currentActiveRef.left = xpos;
				currentActiveRef.visibility = 'visible';
			}
		}
	}
}

function InitiateClose() {
	submenuvalid = false;
	if (currentActiveRef) {
		menutimer = window.setTimeout('CloseSubNav()', 1000);
	}
}

function ClearTimer() {
	submenuvalid = true;
	if (menutimer != null) {
		window.clearTimeout(menutimer);
	}
}

function CloseSubNav() {
	if (!submenuvalid && currentActiveRef != null) {
		if (currentActiveRef.style) {
			currentActiveRef.style.visibility = 'hidden';
		}
		else {
			currentActiveRef.visibility = 'hidden';
		}
		currentActiveRef = null;
	}
}

function getObjectById(subMenuID) {
	if (document.all) {
		if (eval('document.all.' + subMenuID)) {
			return eval('document.all.' + subMenuID);
		}
		else {
			return null;
		}
	}
	else if (document.getElementById) {
		if (document.getElementById(subMenuID) != null) {
			return document.getElementById(subMenuID);
		}
		else {
			return null;
		}
	}
	else if (document.layers) {
		return document.layers[subMenuID];
	}
	return null;
}

function offsetX(obj, value) {
	if (obj.offsetParent) {
		value += obj.offsetLeft;
		return offsetX(obj.offsetParent, value);		
	}
	else {
		return value;
	}
}

