
loader = (isFrames) ? parent : window;
loader.onload = startIt;
origWidth = loader.innerWidth;
origHeight = loader.innerHeight;
loader.onresize = reDo;

isLoaded = false;
NSresized = false;

if (!window.menuVersion) {
	clickKill = showVisited = NSfontOver = keepHilite = clickStart = false;
}

isWin = (navigator.appVersion.indexOf("Win") != -1)
if (!isWin && !isMac) NSfontOver = showVisited = false;

mSecsVis = secondsVisible*1000;
isRight = (window.navFrLoc && navFrLoc == "right");

imgSuf = (isRight) ? ">"  : "ALIGN=RIGHT>";


//if(sudDir== "1") {imgSrc = "../" + imgSrc;}


imgStr = "<IMG SRC='" + imgSrc + "' WIDTH=" + imgWd + " HEIGHT=" + imgHt +" BORDER=0 VSPACE=2 " + imgSuf;
spStr = (isRight && NS4) ? "<SPACER TYPE=HORIZONTAL SIZE="+imgSiz+">" : "";

areCreated = false;
menuLoc = null;

initVars();

/**
  * resets menu variables
  */
function initVars() {
	if(areCreated) {
		for(i=1; i<topCount; i++) {
			cur = eval("menuElement"+i);
			clearTimeout(cur.hideTimer);
			cur.hideTimer=null;
	}
		clearTimeout(allTimer);
	}
	
	topCount = 1;
	areCreated = false;
	beingCreated = false;
	isOverMenu = false;
	currentMenu = null;
	allTimer = null;
}




/*
 * function called when window loaded
 */
function startIt() {
	isLoaded = true;
	if (isFrames) {
		menuLoc = eval("parent.frames." + mainFrName);
		loader.captureEvents(Event.LOAD);
		loader.onload = NSloaded;
		menuLoc.onunload = NSunloaded;
	}
	else {
		menuLoc = window;
	}
	menuLoc = window;
	menuLoc.nav = nav = window;
	if (clickKill) {
		menuLoc.document.captureEvents(Event.MOUSEDOWN);
		menuLoc.document.onmousedown = clicked;
	}
	makeTop();	
}

function makeTop(){
	beingCreated = true;

	while(eval("window.Menu" + topCount)) {
		makeMenuNS(false,topCount);
		topCount++;
	}

	status = "e-Business... it's about transactions";
	areCreated = true;
	beingCreated = false;
}




function NSunloaded(){
	isLoaded = false;
}

function NSloaded(e){
	if (e.target.name == mainFrName) {
		initVars();
		startIt();
	}
}


function keepTrack() {
	if (menuLoc.document.readyState == "complete") {
		initVars();
		startIt();
	}
	else {
		setTimeout("keepTrack()",50);
	}
}


function makeMenuNS(isChild,menuCount,menuParent,parItem) {
    
	tempArray = eval("Menu" + menuCount);
	
	if (!isChild) { //if parent menu, check against a set menu width
		tempWidth = tempArray[0] ? tempArray[0] : menuWidth;
		menu = makeElement("menuElement" + menuCount,tempWidth,null,null);
	}
	else {//else, it's a submenu, don't set width, do that in make element function
		menu = makeElement("menuElement" + menuCount,null,menuParent,null);
	}
	menu.array = tempArray;
	menu.setMenuTree = setMenuTree;
	menu.setMenuTree(isChild,menuParent);

	while (menu.itemCount < menu.maxItems) {
		menu.itemCount++;
		prevItem = (menu.itemCount > 1) ? menu.item : null;
		itemName = "item" + menuCount + "_" + menu.itemCount;

		menu.item = makeElement(itemName,null,null,menu);

		menu.item.prevItem = prevItem;
		menu.item.setup = itemSetup;
		menu.item.setup(menu.itemCount,menu.array);
		if (menu.item.hasMore) {
			makeMenuNS(true,menuCount + "_" + menu.itemCount,menu,menu.item);
			menu = menu.parentMenu;
		}
	}

	menu.lastItem = menu.item;
	menu.setup(isChild,menuParent,parItem);
}

function setMenuTree(isChild,menuParent) {
	if (!isChild) {
		this.menuWidth = this.array[0] ? this.array[0] : menuWidth;
		if (isCentered) {
		  this.menuLeft = calcOffset((this.array[1] + netscapeOffset), templateWidth);
		} else {
		  this.menuLeft = (this.array[1] + netscapeOffset);
		}
		this.menuTop = this.array[2];
		this.menuFontColor = this.array[3] ? this.array[3] : fntCol;
		this.menuFontOver = this.array[4] ? this.array[4] : overFnt;
		this.menuBGColor = this.array[5] ? this.array[5] : backCol;
		this.menuBGOver = this.array[6] ? this.array[6] : overCol;
		this.menuBorCol = this.array[7] ? this.array[7] : borCol;
		this.menuSeparatorCol = this.array[8] ? this.array[8] : separatorCol;
		this.treeParent = this;
		this.startChild = this;
	}
	else {
		this.menuWidth = menuParent.menuWidth;
		this.menuLeft = menuParent.menuLeft;
		this.menuTop = menuParent.menuTop;
		this.menuFontColor = menuParent.menuFontColor;
		this.menuFontOver = menuParent.menuFontOver;
		this.menuBGColor = menuParent.menuBGColor;
		this.menuBGOver = menuParent.menuBGOver;
		this.menuBorCol = menuParent.menuBorCol;
		this.menuSeparatorCol = menuParent.menuSeparatorCol;
		this.treeParent = menuParent.treeParent;
	}

	this.maxItems = (isChild) ? this.array.length/3 : (this.array.length-9)/3;
	this.hasParent = isChild;
    this.setup = menuSetup;
	this.itemCount = 0;
}



function makeElement(whichEl,whichWidth,whichParent,whichContainer) {

		if (whichWidth) {
			elWidth = whichWidth;
		}
		else {
			elWidth = (whichContainer) ? whichContainer.menuWidth : whichParent.menuWidth;
			if (whichContainer) elWidth = elWidth-(borWid*2)-(itemPad*2);
		}
		if (!whichContainer) whichContainer = menuLoc;
		eval(whichEl + "= new Layer(elWidth,whichContainer)");

	return eval(whichEl);
}

function itemSetup(whichItem,whichArray) {
	this.onmouseover = itemOver;
	this.onmouseout = itemOut;
	this.container = this.parentLayer ;

	arrayPointer = (this.container.hasParent) ? (whichItem-1)*3 : ((whichItem-1)*3)+9;

	this.dispText = whichArray[arrayPointer];	
	this.linkText = whichArray[arrayPointer + 1];
	
//	if((sudDir== "1") && (this.linkText != "")) {this.linkText = "../" + this.linkText;}
	
	this.hasMore = whichArray[arrayPointer + 2];


	if (this.linkText) {
	  this.captureEvents(Event.MOUSEUP)
	  this.onmouseup = linkIt;
	}

		htmStr = this.dispText;
		if (fntBold) htmStr = htmStr.bold();
		if (fntItal) htmStr = htmStr.italics();

		htmStr = "<FONT FACE='" + fntFam + "' POINT-SIZE=" + fntSiz + ">" + htmStr+ "</FONT>";
		htmStrOver = htmStr.fontcolor(this.container.menuFontOver);
		htmStr = htmStr.fontcolor(this.container.menuFontColor);
		this.htmStr = (this.hasMore) ? imgStr + htmStr : spStr + htmStr;
		this.htmStrOver = (this.hasMore) ? imgStr + htmStrOver : spStr + htmStrOver;		

		this.visibility = "inherit";
		this.bgColor = this.container.menuBGColor;

		if (whichItem == 1) {
			this.top = borWid + itemPad;
		}
		else {
			this.top = this.prevItem.top + this.prevItem.clip.height + separator;
		}
		this.left = borWid + itemPad;
		this.clip.top = this.clip.left = -itemPad;
		this.clip.right = this.container.menuWidth-(borWid*2)-itemPad;

		this.txtLyr = new Layer(this.container.menuWidth-(borWid*2)-itemPad,this);
		this.txtLyr.document.write(this.htmStr);
		this.txtLyr.document.close();
		this.txtLyr.visibility = "inherit";

		this.clip.bottom += this.txtLyr.document.height+itemPad;

		this.dummyLyr = new Layer(100,this);
		this.dummyLyr.left = this.dummyLyr.top = -itemPad;
		this.dummyLyr.clip.width = this.clip.width;
		this.dummyLyr.clip.height = this.clip.height;
		this.dummyLyr.visibility = "inherit";
	
	
}	

function menuSetup(hasParent,openCont,openItem) {
	this.onmouseover = menuOver;
	this.onmouseout = menuOut;
	
	this.showIt = showIt;
	this.keepInWindow = keepInWindow;
	this.hideTree = hideTree
	this.hideParents = hideParents;
	this.hideChildren = hideChildren;
	this.hideTop = hideTop;
	this.hasChildVisible = false;
	this.isOn = false;
	this.hideTimer = null;

	this.childOverlap = (perCentOver != null) ? ((perCentOver/100) * this.menuWidth) : childOverlap;
	this.currentItem = null;
	this.hideSelf = hideSelf;
		
	if (hasParent) {
		this.hasParent = true;
		this.parentMenu = openCont;
		
			this.parentItem = openItem;
			this.parentItem.child = this;
		
	}
	else {
		this.hasParent = false;
	}

	
		this.bgColor = this.menuBorCol;
		this.fullHeight = this.lastItem.top + this.lastItem.clip.bottom + borWid;
		this.clip.right = this.menuWidth;
		this.clip.bottom = this.fullHeight;
	
	
}

function popUp(menuName,e){
	if (NSresized) startIt();
	if (!isLoaded) return;
	linkEl = e.target;
	if (clickStart) linkEl.onclick = popMenu;
	if (!beingCreated && !areCreated) startIt();
	linkEl.menuName = menuName;	
	if (!clickStart) popMenu(e);
}

function popMenu(e){
	if (!isLoaded || !areCreated) return true;

	eType = e.type ;
	if (clickStart && eType != "click") return true;
	hideAll();

	linkEl = e.target;
	
	currentMenu = eval(linkEl.menuName);
	currentMenu.hasParent = false;
	currentMenu.treeParent.startChild = currentMenu;
	
	if (!isFrames) {
		xPos = (currentMenu.menuLeft) ? currentMenu.menuLeft : e.pageX ;
		yPos = (currentMenu.menuTop) ? currentMenu.menuTop : e.pageY ;
	}
	else {
		switch (navFrLoc) {
			case "left":
				xPos = (currentMenu.menuLeft) ? currentMenu.menuLeft : menuLoc.pageXOffset;
				yPos = (currentMenu.menuTop) ? currentMenu.menuTop : (e.pageY-pageYOffset)+menuLoc.pageYOffset;
				break;
			case "top":
				xPos = (currentMenu.menuLeft) ? currentMenu.menuLeft : (e.pageX-pageXOffset)+menuLoc.pageXOffset;
				yPos = (currentMenu.menuTop) ? currentMenu.menuTop : menuLoc.pageYOffset;
				break;
			case "bottom":
				xPos = (currentMenu.menuLeft) ? currentMenu.menuLeft : (e.pageX-pageXOffset)+menuLoc.pageXOffset;
				yPos = (currentMenu.menuTop) ? currentMenu.menuTop : menuLoc.pageYOffset+menuLoc.innerHeight;
				break;
			case "right":
				xPos = (currentMenu.menuLeft) ? currentMenu.menuLeft : menuLoc.pageXOffset+menuLoc.innerWidth;
				yPos = (currentMenu.menuTop) ? currentMenu.menuTop : (e.pageY-pageYOffset)+menuLoc.pageYOffset;
				break;
		}
	}

	currentMenu.moveTo(xPos,yPos);
	currentMenu.keepInWindow()
	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() {
	this.isOn = false;
	isOverMenu = false;
	menuLoc.status = "";
	if (!clickKill) allTimer = setTimeout("currentMenu.hideTree()",10);  
}

function itemOver(){
	if (keepHilite) {
		if (this.container.currentItem && this.container.currentItem != this) {
				this.container.currentItem.bgColor = this.container.menuBGColor;
				if (NSfontOver) {
					with (this.container.currentItem.txtLyr.document) {
						write(this.container.currentItem.htmStr)
						close();
					}
				}			
		}
	}

		this.bgColor = this.container.menuBGOver;
		if (NSfontOver) {
			this.txtLyr.document.write(this.htmStrOver);
			this.txtLyr.document.close();
		}
	

	menuLoc.status = this.linkText;

	this.container.currentItem = this;

	if (this.container.hasChildVisible) {
		this.container.hideChildren(this);
	}

	if (this.hasMore) {
		horOffset = (isRight) ? (this.container.childOverlap - this.container.menuWidth) : (this.container.menuWidth - this.container.childOverlap);
		
		this.childX = this.container.left + horOffset;
		this.childY = this.pageY + childOffset;

		this.child.moveTo(this.childX,this.childY);
		this.child.keepInWindow();
		this.container.hasChildVisible = true;
		this.container.visibleChild = this.child;
		this.child.showIt(true);
	}
}

function itemOut() {
	
		if (!keepHilite) {
			this.bgColor = this.container.menuBGColor;
			if (NSfontOver) {
				with (this.txtLyr.document) {
					write(this.htmStr);
					close();
				}
			}
	
		}
		if (!isOverMenu && !clickKill) {
			allTimer = setTimeout("currentMenu.hideTree()",10); 
		}
	
}

function moveTo(xPos,yPos) {
	this.style.pixelLeft = xPos;
	this.style.pixelTop = yPos;
}

function showIt(on) {
	
		this.visibility = (on) ? "show" : "hide";
		if (keepHilite && this.currentItem) {
			this.currentItem.bgColor = this.menuBGColor;
			if (NSfontOver) {
				with (this.currentItem.txtLyr.document) {
					write(this.currentItem.htmStr);
					close();
				}
			}
		}
	
	
	this.currentItem = null;
}

function keepInWindow() {
	scrBars = 20;
	botScrBar = (isFrames && navFrLoc=="bottom") ? (borWid*2) : scrBars;
	rtScrBar = (isFrames && navFrLoc=="right") ? (borWid*2) : scrBars;
		winRight = (menuLoc.pageXOffset + menuLoc.innerWidth) - rtScrBar;
		rightPos = this.left + this.menuWidth;
   
		if (rightPos > winRight) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.left;
				newLeft = ((parentLeft-this.menuWidth) + this.childOverlap);
				this.left = newLeft;
			}
			else {
				dif = rightPos - winRight;
				this.left -= dif;
			}
		}

		winBot = (menuLoc.pageYOffset + menuLoc.innerHeight) - botScrBar ;
		botPos = this.top + this.fullHeight;

		if (botPos > winBot) {
			dif = botPos - winBot;
			this.top -= dif;
		}
		
		winLeft = menuLoc.pageXOffset;
		leftPos = this.left;

		if (leftPos < winLeft) {
			if (this.hasParent) {
				parentLeft = this.parentMenu.left;
				newLeft = ((parentLeft+this.menuWidth) - this.childOverlap);
				this.left = newLeft;
			}
			else {
				this.left = 5;
			}
		}

	
}

function linkIt() {
//3.07 added colon (:)
	if (this.linkText.indexOf("javascript:")!=-1) eval(this.linkText)
	else menuLoc.location.href = this.linkText;
}

function popDown(menuName){
	if (!isLoaded || !areCreated) return;
	whichEl = eval(menuName);
	whichEl.isOn = false;
	if (!clickKill) whichEl.hideTop();
}

function hideAll() {
	for(i=1; i<topCount; i++) {
		temp = eval("menuElement" + 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;
	(clickKill) ? whichTop.hideSelf() : (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}

function reDo(){
	if (loader.innerWidth==origWidth && loader.innerHeight==origHeight) return;
	initVars();
	NSresized=true;
	//menuLoc.location.reload();
    document.location.reload();
	status="resized!";
}

function clicked() {
	if (!isOverMenu && currentMenu!=null && !currentMenu.isOn) {
		whichEl = currentMenu;
		whichEl.hideTree();
	}
}

window.onerror = handleErr;

function handleErr(){
	arAccessErrors = ["permission","access"];
	mess = arguments[0].toLowerCase();
	found = false;
	for (i=0;i<arAccessErrors.length;i++) {
		errStr = arAccessErrors[i];
		if (mess.indexOf(errStr)!=-1) found = true;
	}
	return found;
}

function calcOffset(x, width) {
	var newx;
	if(window.innerWidth) {
		newx = ((window.innerWidth - width) / 2) + x;
	}
	else {
		if (document.body.clientWidth) {
		newx = ((document.body.clientWidth - width) / 2) + x;
		}
	}
	return newx;
}
//end
