// JavaScript Document

this.menuTimer = null;
this.withinMenu = null;

function findPos(obj) {
	var l = t = 0;
	if (obj.offsetParent) {
		do {
			l += obj.offsetLeft;
			t += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	var posObj = {x:l, y:t};
	return posObj;
}

function showSubmenu (obj, level, name) {
	if (obj.parentNode.parentNode.parentNode.parentNode.getAttribute("id") != null) {
		var submenuName = obj.parentNode.parentNode.parentNode.parentNode.getAttribute("id").split("$")[0];
	}
	menuItemEnter(obj, level);
	var posObj = findPos(obj);
	var l = posObj.x;
	var paddingX = 0;
	if (level != 0) {
		var tdArr = document.getElementsByTagName("td");
		for (var i = 0; i < tdArr.length; i ++) {
			if (tdArr[i].parentNode.parentNode.parentNode.parentNode.getAttribute("id") != null){
				if (tdArr[i].parentNode.parentNode.parentNode.parentNode.getAttribute("id").split("$")[0] == submenuName && tdArr[i].className == "submenuitem") {
					paddingX = Math.max(paddingX, tdArr[i].childNodes[1].offsetLeft);
				}
			}
		}
		l += paddingX + 10;
	}
	var arr = document.getElementsByTagName("div");
	for (var i = 0; i < arr.length; i++) {
		if (arr[i].getAttribute("id") != null){
			if (arr[i].getAttribute("id").split("$")[0] == name) {
				var menuObj = arr[i];
			}
		}
	}
	menuObj.style.left = l + "px";
	if (menuObj.getAttribute("id").split("$")[1] == 1) {
		menuObj.style.top = "30px";
	}
	else {
		menuObj.style.top = posObj.y + "px";
	}
	menuObj.style.display = "block";
}

function menuItemEnter (obj, level) {
	clearTimeout(menuTimer);
	clearMenusAboveLevel(level);
	if (level > 0) {
		obj.style.backgroundColor="#FFFFFF";
	}
}

function menuItemExit (obj) {
	menuTimer = setTimeout(clearAllMenus, 1000);
	obj.style.backgroundColor="#F5F5F5";
}

function menuItemNavigate (theURL) {
	document.src = theURL;
}

function clearMenusAboveLevel(level) {
	var arr = document.getElementsByTagName ("div")
		for (var i  = 0; i < arr.length; i++) {
			if (arr[i].className == "submenu" && arr[i].getAttribute("id").split("$")[1] > level) {
				arr[i].style.display = "none";
			}
		}
}

function clearAllMenus () {
	var arr = document.getElementsByTagName ("div")
		for (var i  = 0; i < arr.length; i++) {
			if (arr[i].className == "submenu") {
				arr[i].style.display = "none";
			}
		}
}