ver5 = 0;
if (navigator.userAgent.indexOf("MSIE 5")!=-1) ver5 = 1;

window.onload = startIt;
isLoaded = false;
if (!window.imgHspace) imgHspace=0;
mSecsVis = secondsVisible*1000;
imgStr = "<IMG SRC='" + imgSrc + "' WIDTH=" + imgHSiz + " HEIGHT=" + imgVSiz +" VSPACE=2 HSPACE="+ imgHspace +" BORDER=0 ALIGN=RIGHT>";
fullImgSize = (imgHSiz+(imgHspace*2));
imgStr = "<SPAN STYLE='height:100%;width:"+ fullImgSize +";float:right;overflow:hidden'>"+ imgStr +"</SPAN>";
areCreated = false;
menuLoc = null;

function initVars() {
	topCount = 1;
	areCreated = false;
	beingCreated = false;
	isOverMenu = false;
	currentMenu = null;
	allTimer = null;
}

initVars();

function startIt() {
	isLoaded = true;
	menuLoc = window;
	makeTop();	
}

function makeTop(){
	beingCreated = true;
	while(eval("window.arMenu" + topCount)) {
		makeMenuIE(false,topCount);
		topCount++
	}
	areCreated = true;
	beingCreated = false;
}

function findTree(men){
	foundTree = false;
	for(i = 9; i < men.array.length; i += 4){
		if(men.array[i]) {
			foundTree = true;
			break;
		}
	}
	return foundTree;
}

function setMenuTree(isChild,parMenu) {
        if (!isChild) {
                this.menuHead = this.array[4];
                this.menuHeadCol = this.array[5];
                this.startChild = this;
        }
        this.menuWidth = (isChild) ? parMenu.menuWidth : menuWidth;
        this.menuLeft = (isChild) ? parMenu.menuLeft : this.array[1];
        this.menuTop = (isChild) ? parMenu.menuTop : this.array[2];
        this.menuBGOver = (isChild) ? parMenu.menuBGOver : this.array[3];
        this.treeParent = (isChild) ? parMenu.treeParent : this;
        this.isTree = (isChild) ? parMenu.isTree : findTree(this);
	this.maxItems = (isChild) ? this.array.length/4 : (this.array.length-6)/4;
	this.hasParent = isChild;
	this.setup = menuSetup;
	this.itemCount = 0;
}

function makeMenuIE(isChild,menuCount,parMenu) {
	menu = makeElement("elMenu" + menuCount);
	menu.array = eval("arMenu" + menuCount);
	menu.setMenuTree = setMenuTree;
	menu.setMenuTree(isChild,parMenu);
	menu.itemStr = "";
	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
		itemName = "item" + menuCount + "_" + menu.itemCount;
		arrayPointer = (isChild) ? (menu.itemCount-1)*4 : ((menu.itemCount-1)*4)+6;
		dispText = menu.array[arrayPointer];
		linkState = menu.array[arrayPointer + 2];
		hasMore = menu.array[arrayPointer + 3];
		htmStr = (hasMore) ? imgStr + dispText : dispText;

		menu.itemStr += "<SPAN ID=" + itemName + " STYLE=\"width:" + (menu.menuWidth-(borWid*2)) + "\">" + htmStr + "</SPAN><BR>";
		if (hasMore) {
			makeMenuIE(true,menuCount + "_" + menu.itemCount,menu);
			menu = menu.parentMenu;
		}	
	}
	menu.innerHTML = menu.itemStr;
	itemColl = menu.children.tags("SPAN");
	for (i = 0; i < itemColl.length; i++) {
		it = itemColl(i);
		it.setup = itemSetup;
		it.setup(i + 1, menu.array);
	}
	if (itemColl.length) menu.lastItem = itemColl(itemColl.length - 1);
	menu.setup(isChild,parMenu);
}

function makeElement(whichEl,whichWidth,whichParent,whichContainer) {
	elStr = "<DIV ID=" + whichEl + " STYLE='position:absolute'></DIV>";
	if (ver5) document.write(elStr);
	else menuLoc.document.body.insertAdjacentHTML("BeforeEnd",elStr);

	return eval(whichEl);
}

function itemSetup(whichItem,whichArray) {
	this.onmouseover = itemOver;
	this.onmouseout = itemOut;
	this.container = this.offsetParent;
	arrayPointer = (this.container.hasParent) ? (whichItem-1)*4 : ((whichItem-1)*4)+6;
	this.dispText = whichArray[arrayPointer];
	this.linkText = whichArray[arrayPointer + 1];
	this.linkState = whichArray[arrayPointer + 2];
	this.hasMore = whichArray[arrayPointer + 3];
	if (this.hasMore) {
		this.child = eval("elMenu" + this.id.substr(4));
		this.child.parentMenu = this.container;
		this.child.parentItem = this;
	}
	if (this.linkText) {
		this.onclick = linkIt;
		this.style.cursor = "hand";
	}
	with (this.style) {
		padding = itemPad;
		if (this.container.isTree && !this.hasMore) paddingRight = itemPad+fullImgSize;
		color = (this.linkState == 1) ? fntCol : menuFontGray;
		fontSize = fntSiz + "pt";
		fontFamily = fntFam;
		borderBottomWidth = separator + "px";
		borderBottomColor = separatorCol;
		borderBottomStyle = "solid";
		backgroundColor = backCol;
	}
}	

function menuSetup(hasParent,openCont,openItem) {
	this.onmouseover = menuOver;
	this.onmouseout = menuOut;
	this.showIt = showIt;
	this.hideTree = hideTree
	this.hideParents = hideParents;
	this.hideChildren = hideChildren;
	this.hideTop = hideTop;
	this.hasChildVisible = false;
	this.isOn = false;
	this.hideTimer = null;
	this.currentItem = null;
	this.hideSelf = hideSelf;
		
	if (hasParent) {
		this.hasParent = true;
		this.parentMenu = openCont;
	} else this.hasParent = false;

	with (this.style) {
		width = this.menuWidth;
		borderWidth = borWid;
		borderColor = borCol;
		borderStyle = "solid";
	}
	if (this.lastItem) this.lastItem.style.border="";
	this.fullHeight = this.scrollHeight;
	this.showIt(false);
	this.onselectstart = cancelSelect;
	this.moveTo = moveTo;
	this.moveTo(0,0);
}

function popUp(menuName,e){
	if (!isLoaded) return;
	linkEl = event.srcElement;
//	linkEl.onclick = popMenu;
	if (clickStart) linkEl.onclick = popMenu;
	if (!beingCreated && !areCreated) startIt();
	linkEl.menuName = menuName;	
	if (!clickStart) popMenu(e);
}

function popMenu(e){
	if (!isLoaded || !areCreated) return true;
	if (clickStart && event.type != "click") return true;
	hideAll();
	linkEl = event.srcElement;
	currentMenu = eval(linkEl.menuName);
	currentMenu.hasParent = false;
	currentMenu.treeParent.startChild = currentMenu;
	menuLocBod = menuLoc.document.body;
	xPos = (currentMenu.menuLeft) ? currentMenu.menuLeft : (event.clientX + menuLocBod.scrollLeft);
	yPos = (currentMenu.menuTop) ? currentMenu.menuTop : (event.clientY + menuLocBod.scrollTop);
	xPos = new Number(xPos) + (menuLocBod.clientWidth - 630) / 2;
	currentMenu.moveTo(xPos,yPos);
	currentMenu.isOn = true;
	currentMenu.showIt(true);
	return false;
}

function menuOver(e) {
	this.isOn = true;
	isOverMenu = true;
	currentMenu = this;
	if (this.hideTimer) clearTimeout(this.hideTimer);
}

function menuOut() {
	theEvent = menuLoc.event;
	if (theEvent.srcElement.contains(theEvent.toElement)) return;
	this.isOn = false;
	isOverMenu = false;
	menuLoc.status = "";
	allTimer = setTimeout("currentMenu.hideTree()",10);  
}

function itemOver(){
	theEvent = menuLoc.event;
	if (theEvent.srcElement.tagName == "IMG") return;
	if (this.linkState == 1) {
		this.style.backgroundColor = this.container.menuBGOver;
		this.style.color = overFnt;
	} else {
		this.style.backgroundColor = menuBGOverGray;
		this.style.color = menuFontOverGray;
	}
	this.style.fontWeight = "bold";
	if (!this.container.hasParent)
		eval(this.container.menuHead).style.backgroundColor = this.container.menuHeadCol;

        tmpstr = this.dispText.replace(/&nbsp;/g, " ");
        menuLoc.status = tmpstr;
	this.container.currentItem = this;
	if (this.container.hasChildVisible) this.container.hideChildren(this);

	if (this.hasMore) {
		horOffset = this.container.menuWidth - childOverlap;
		this.childX = this.container.style.pixelLeft + horOffset;
		this.childY = this.offsetTop + this.container.style.pixelTop + childOffset + borWid;
		this.child.moveTo(this.childX,this.childY);
		this.container.hasChildVisible = true;
		this.container.visibleChild = this.child;
		this.child.showIt(true);
	}
}

function itemOut() {
	theEvent = menuLoc.event;
    	if (theEvent.srcElement.contains(theEvent.toElement) || (theEvent.fromElement.tagName=="IMG" && theEvent.toElement.contains(theEvent.fromElement)))
     		return;

	this.style.fontWeight = "normal";
	this.style.backgroundColor = backCol;
	if (this.linkState == 1) this.style.color = fntCol;
	else this.style.color = menuFontGray;
}

function moveTo(xPos,yPos) {
	this.style.pixelLeft = xPos;
	this.style.pixelTop = yPos;
}

function showIt(on) {
	if (on) {
		this.style.visibility = "visible";
		if (!this.hasParent) eval(this.menuHead).style.backgroundColor = this.menuHeadCol;
	} else {
		this.style.visibility = "hidden";
		if (!this.hasParent && this.menuHead.indexOf('menu') >= 0)
			eval(this.menuHead).style.backgroundColor = menuHeadDefCol;
	}
	this.currentItem = null;
}

function linkIt() {
	if (this.linkText.indexOf("javascript:")!=-1) eval(this.linkText)
	else menuLoc.location.href = this.linkText;
}

function hideAll() {
	for(i=1; i<topCount; i++) {
		temp = eval("elMenu" + i + ".startChild");
		temp.isOn = false;
		if (temp.hasChildVisible) temp.hideChildren();
		temp.showIt(false);
	}	
}

function hideTree() { 
	allTimer = null;
	if (isOverMenu) return;
	if (this.hasChildVisible) this.hideChildren();
	this.hideParents();
}

function hideTop() {
	whichTop = this;
	this.hideTimer = setTimeout("if(whichTop.hideSelf)whichTop.hideSelf()",mSecsVis);
}

function hideSelf() {
	this.hideTimer = null;
	if (!this.isOn && !isOverMenu) this.showIt(false);
}

function hideParents() {
	tempMenu = this;
	while (tempMenu.hasParent) {
		tempMenu.showIt(false);
		tempMenu.parentMenu.isOn = false;		
		tempMenu = tempMenu.parentMenu;
	}
	tempMenu.hideTop();
}

function hideChildren(item) {
	tempMenu = this.visibleChild;
	while (tempMenu.hasChildVisible) {
		tempMenu.visibleChild.showIt(false);
		tempMenu.hasChildVisible = false;
		tempMenu = tempMenu.visibleChild;
	}
	if (!this.isOn || !item.hasMore || this.visibleChild != this.child) {
		this.visibleChild.showIt(false);
		this.hasChildVisible = false;
	}
}

function cancelSelect(){return false}

