var LastShownSubMenu = null;

function GetObjectRef(ObjId){
	if (document.getElementById) {
		return document.getElementById (ObjId);
	}
	else if (document.all) {
		return document.all[ObjId];
	}
	else {
		return null;
	}
}
function ShowSubMenu(oTop, sObjId, e){
	var oSubMenu = GetObjectRef(sObjId)
	if (oSubMenu == null){
		alert("Not found: '" + sObjId + "'")
		return true
	}
	if (LastShownSubMenu != null && LastShownSubMenu != oSubMenu) {
		LastShownSubMenu.style.display = "none"
		LastShownSubMenu = null
	}
	LastShownSubMenu = oSubMenu
	
	if (false){
		var sLastSubTopMenu = "SubTopMenu" + iNumCats
		if (oSubMenu.id == sLastSubTopMenu){
			//alert("SubTopMenuX width is " + oSubMenu.style.width + ", oTop width is " + oTop.style.width)
			if (oSubMenu.style.width == "") { // || oSubMenu.style.width< oTop.style.width){
				oSubMenu.style.width = (oTop.offsetWidth <= 150 ? 150 : oTop.offsetWidth) // oTop.style.width
				alert("SubTopMenuX width is now " + oSubMenu.style.width)
			}
		}
	}
	oSubMenu.style.display = "block"
	e.cancelBubble = true
}
function ShowMenu(oSubMenu, e){
	//alert("ShowMenu of " + oSubMenu.id)
	if (LastShownSubMenu != null && LastShownSubMenu != oSubMenu) {
		LastShownSubMenu.style.display = "none"
		LastShownSubMenu = null
		alert("Last shown is different")
	}
	LastShownSubMenu = oSubMenu
	oSubMenu.style.display = "block"
	e.cancelBubble = true
}

function KillSubMenu(){
	if (LastShownSubMenu != null) {
		LastShownSubMenu.style.display = "none";
		LastShownSubMenu = null;
	}
}
function TopMenuScriptInit(){
	if (document.getElementById || document.all) {
		if (document.captureEvents) {
			document.captureEvents(Event.MOUSEOVER); 
		}
		document.onmouseover = KillSubMenu;
	}

	BuildPositions()
}
//var iNumCats = 0 DECLARED EXTERNALLY
function BuildPositions(){
	var oMenuTable = GetObjectRef("MenuTable")
	
	if (oMenuTable == null)
		return false
		
	for (var i=0; i<iNumCats; i++){
		var sName = "TopMenu" + (i+1)
		var oTop = GetObjectRef(sName)
		var oSubTop = GetObjectRef("Sub" + sName)
		if (oTop != null && oSubTop != null){
			oSubTop.style.left = oMenuTable.offsetLeft + oTop.offsetLeft
			oSubTop.style.top = oMenuTable.offsetTop + oTop.offsetTop + oTop.offsetHeight
			oSubTop.style.zIndex = 300
		}
	}
	return true
}
