var isNS4 = (document.layers ? true : false);

function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}
function getSty(id) {
	return (isNS4 ? getRef(id) : getRef(id).style);
} 
var popTimer = 0;
var popMenu = null;
var highlightNow = new Array();
function popOn(menu, menuNum, itemNum) {
	clearTimeout(popTimer);
	if(menu != popMenu && popMenu != null) {
		hideAllBut(popMenu, 0);
	} else {
		hideAllBut(menu, menuNum);
	}
	highlightNow = getTree(menu, menuNum, itemNum);
	changeColor(menu, highlightNow, true);
	targetNum = menu[menuNum][itemNum].target;
	if (targetNum > 0) {
		thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
		thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
		with (menu[targetNum][0].ref) {
			left = parseInt(thisX + menu[targetNum][0].x);
			top = parseInt(thisY + menu[targetNum][0].y);
			visibility = 'visible';
		}
	}
}
function popOut(menu, menuNum, itemNum) {
	popMenu = menu;
	if ((menuNum == 0) && !menu[menuNum][itemNum].target){
		hideAllBut(popMenu, 0)
	} else {
		popTimer = setTimeout('hideAllBut(popMenu, 0)', 500);
	}
}
function hideAllBut(menu, menuNum) {
	var keepMenus = getTree(menu, menuNum, 1);
	for (count = 0; count < menu.length; count++) {
		if (!keepMenus[count]) {
			menu[count][0].ref.visibility = 'hidden';
		}
	changeColor(menu, highlightNow, false);
	}
}
function getTree(menu, menuNum, itemNum) {
	itemArray = new Array(menu.length);

	while(1) {
		itemArray[menuNum] = itemNum;
		if (menuNum == 0) 
			return itemArray;
		itemNum = menu[menuNum][0].parentItem;
		menuNum = menu[menuNum][0].parentMenu;
	}
}
function changeColor(menu, changeArray, isOver) {
	for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
		if (changeArray[menuCount]) {
			newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
			with (menu[menuCount][changeArray[menuCount]].ref) {
				if (isNS4) 
					bgColor = newCol;
				else 
					backgroundColor = newCol;
					fgColor = "#FFFFFF";
			}
		}
	}
}
function Menu(isVert, popInd, x, y, width, overCol, backCol, textClass) {
	this.isVert = isVert;
	this.popInd = popInd;
	this.x = x;
	this.y = y;
	this.width = width;
	this.overCol = overCol;
	this.backCol = backCol;
	this.textClass = textClass;
	this.parentMenu = null;
	this.parentItem = null;
	this.ref = null;
}

function Item(text, href, frame, length, target) {
	this.text = text;
	this.href = href;
	this.frame = frame;
	this.length = length;
	this.target = target;
	this.ref = null;
}
var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');

function moveRoot(){
	with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
}
if (isNS4){ 
	document.captureEvents(Event.CLICK);
}

document.onclick = clickHandle;
function clickHandle(evt){
	if (isNS4) document.routeEvent(evt);
	//hideAllBut(popMenu, 0);
}
