
var ie = (document.all) ? true : false
var ns = (document.layers) ? true : false
var ns6 = (document.getElementById && !ie) ? true : false
var theMenuObjectArray = new Array()
var menuOverlap = 0
var defaultOffsetTop = 125
var cutoffRight = 1000
var defaultOffsetLeft = 2
var menuWidth = 100
var childMenuWidth = 70
var childMenuOffsetTop = 3
function Menu () {
	/* menu options */
	this.menuWidth = (arguments[0])?(arguments[0]):menuWidth
	this.optionHeight = 18
	this.borderWidth = 0
	this.borderColor = "#FFFFFF"
	this.fontFamily = "Arial"
	this.fontSize = 11
	this.isBold = false
	this.textIndent = 5
	this.textTop = 3
	this.normalBGColor = "#A32B2A"
	this.normalFGColor = "#FFFFFF"
	this.activeBGColor = "#CCCCCC"
	this.activeFGColor = "#A32B2A"
	this.nonOptionTotal = 0
	this.top = 0
	this.left = 0

	this.activeOption = false
	this.parentMenu = false
	this.timeOutDelay = 1000
	this.items = new Array()
	this.nonItems = new Array()
	this.timerID = false
	this.optionTimerID = false
	/* create the menu layer */
	if (ns) {
		this.MenuContainer = new Layer(this.menuWidth)
	} else if (ie | ns6) {
		this.MenuContainer = document.createElement("DIV")
	}
	this.MenuContainer.boundObject = this
	/* set up the menu layer */
	if (ns) {
		this.MenuContainer.clip.width = this.menuWidth
		this.MenuContainer.clip.height = 0
		this.MenuContainer.left = 0
		this.MenuContainer.top = 0
		if (this.borderWidth > 0) this.MenuContainer.bgColor = this.borderColor
		this.MenuContainer.visibility = "hide"
	} else {
		this.MenuContainer.style.position = "absolute"
		this.MenuContainer.style.width = this.menuWidth - ((ns6) ? this.borderWidth * 2 : 0) + "px"
		this.MenuContainer.style.left = 0
		this.MenuContainer.style.top = 0
		this.MenuContainer.style.borderStyle = "solid"
		this.MenuContainer.style.borderWidth = this.borderWidth + "px"
		this.MenuContainer.style.borderColor = this.borderColor
		this.MenuContainer.style.visibility = "hidden"
		document.body.insertBefore (this.MenuContainer, null)
	}
	this.MenuContainer.onmouseover = function () {
		clearTimeout(this.boundObject.timerID)
	}
	this.MenuContainer.onmouseout = function () {
		this.boundObject.timeOutMenu()
	}
	this.MenuContainer.onselectstart = function () {
		return false
	}
	/* show the menu */
	this.showMenu = function (left, top, isChild) {
		this.top = top
		this.left = left
		clearTimeout(this.timerID)
		/* hide the other menus */
		if (!isChild) {
			for (menuCount = 0; menuCount < theMenuObjectArray.length; menuCount ++) {
				if (theMenuObjectArray[menuCount].MenuContainer != this.MenuContainer) {
					theMenuObjectArray[menuCount].hideMenuTree(true)
					// theMenuObjectArray[menuCount].MenuContainer.zIndex = 1
				} else {
					// theMenuObjectArray[menuCount].MenuContainer.zIndex = 2
				}
			}
		}
		if (this.items.length<1) return false
		if (ns) {
			this.MenuContainer.top = top
			this.MenuContainer.left = left
			this.MenuContainer.visibility = "show"
		} else {
			this.MenuContainer.style.top = top
			this.MenuContainer.style.left = left
			this.MenuContainer.style.visibility = "visible"
		}
	}
	/* time out the menu */
	this.timeOutMenu = function () {
		this.functionString = "theMenuObjectArray[" + this.objectNumber + "].hideMenuTree()"
		this.timerID = setTimeout(this.functionString, this.timeOutDelay)
	}
	/* hide the entire menu tree */
	this.hideMenuTree = function (down) {
		clearTimeout(this.timerID)
		if (this.activeOption) {
			if (this.activeOption.childMenu) clearTimeout(this.activeOption.childMenu.timerID)
			this.doOptionOff()
		}
		if (ns) {
			this.MenuContainer.visibility = "hide"
			this.MenuContainer.top = 0
			this.MenuContainer.left = 0
		} else {
			this.MenuContainer.style.visibility = "hidden"
			this.MenuContainer.style.top = 0
			this.MenuContainer.style.left = 0
		}
		if (this.parentMenu && !down) this.parentMenu.hideMenuTree()
		else if (this.activeOption.childMenu && down) this.activeOption.childMenu.hideMenuTree(true)
	}
	/* create a new menu option */
	this.createMenuOption = function (theText, theURL, childMenu) {
		this.itemNumber = this.items.length
		theText = theText.replace(/[ ]/g, "&nbsp;")
		if (ns) this.items[this.itemNumber] = new Layer((this.menuWidth - (this.borderWidth * 2)), this.MenuContainer)
		else this.items[this.itemNumber] = document.createElement("DIV")
		this.items[this.itemNumber].childMenu = childMenu
		if (childMenu) this.items[this.itemNumber].childMenu.parentMenu = this
		this.items[this.itemNumber].optionNumber = this.items.length
		this.items[this.itemNumber].nonOptionOffset = this.nonOptionTotal
		this.items[this.itemNumber].getMenuObject = function() {
			if (ns) return this.parentLayer.boundObject
			else return this.parentNode.boundObject
		}
		if (ns) {
			this.items[this.itemNumber].clip.width = (this.menuWidth - (this.borderWidth * 2))
			this.items[this.itemNumber].clip.height = this.optionHeight
			this.items[this.itemNumber].top = (this.itemNumber * this.optionHeight) + this.borderWidth + this.nonOptionTotal
			this.items[this.itemNumber].left = this.borderWidth
			this.items[this.itemNumber].bgColor = this.normalBGColor
			this.items[this.itemNumber].displayText = '<ILAYER left="' + this.textIndent + '" top="' + this.textTop + '" width=90>' + ((this.isBold) ? "<B>" : "") + theText + ((this.isBold) ? "</B>" : "") + '</ILAYER>'
			this.items[this.itemNumber].document.write('<FONT face="' + this.fontFamily + '" point-size="' + (this.fontSize - 3) + '" color="' + this.normalFGColor + '">' + this.items[this.itemNumber].displayText + '</FONT>')
			this.items[this.itemNumber].document.close()
			this.items[this.itemNumber].visibility = "inherit"
			this.MenuContainer.clip.height = ((this.itemNumber + 1) * this.optionHeight) + (this.borderWidth * 2) + this.nonOptionTotal
			this.items[this.itemNumber].onmouseover = function () {
				this.parentLayer.boundObject.optionOn(this)
			}
			this.items[this.itemNumber].onmouseout = function () {
				this.parentLayer.boundObject.optionOff(this)
			}
		} else {
			this.items[this.itemNumber].style.position = "absolute"
			this.items[this.itemNumber].style.width = (this.menuWidth - (this.borderWidth * 2)) + "px"
			this.items[this.itemNumber].style.height = this.optionHeight + "px"
			this.items[this.itemNumber].style.top = (this.itemNumber * this.optionHeight) + this.nonOptionTotal + "px"
			this.items[this.itemNumber].style.left = 0
			this.items[this.itemNumber].style.overflow = "hidden"
			this.items[this.itemNumber].style.fontFamily = this.fontFamily
			this.items[this.itemNumber].style.fontWeight = ((this.isBold) ? "bold" : "normal")
			this.items[this.itemNumber].style.fontSize = this.fontSize + "px"
			this.items[this.itemNumber].style.backgroundColor = this.normalBGColor
			this.items[this.itemNumber].style.color = this.normalFGColor
			this.items[this.itemNumber].style.cursor = (ns6)?"pointer":"hand"
			this.items[this.itemNumber].innerHTML = '<SPAN style="position:relative;padding-left:' + this.textIndent + 'px;top:' + this.textTop + 'px;">' + theText + '</SPAN>'
			this.items[this.itemNumber].onmouseover = function () {
				this.parentNode.boundObject.optionOn(this)
			}
			this.items[this.itemNumber].onmouseout = function () {
				this.parentNode.boundObject.optionOff(this)
			}
			this.MenuContainer.style.height = ((this.itemNumber + 1) * this.optionHeight) + (this.borderWidth * 2) - ((ns6) ? this.borderWidth * 2 : 0) + this.nonOptionTotal
			this.MenuContainer.insertBefore(this.items[this.itemNumber], null)
 		}
		this.items[this.itemNumber].action = theURL
	}
	this.optionOn = function (theOption) {
		if (this.parentMenu) {
			clearTimeout(this.parentMenu.optionTimerID)
			clearTimeout(this.parentMenu.timerID)
		}
		if (this.activeOption) {
			clearTimeout(this.optionTimerID)
			this.doOptionOff()
		}
		this.activeOption = theOption
		if (theOption.childMenu) {	
			childLeftPos = this.left + this.menuWidth - menuOverlap
			//alert(childLeftPos + childMenuWidth)
			if ((childLeftPos + childMenuWidth) > cutoffRight) {
				childLeftPos = this.left - childMenuWidth
			}
			theOption.childMenu.showMenu((childLeftPos) - menuOverlap, (this.top + ((theOption.optionNumber - 1) * this.optionHeight)) + theOption.nonOptionOffset, true)
		}
		if (ns) {
			theOption.bgColor = this.activeBGColor
			theOption.document.write('<FONT face="' + this.fontFamily + '" point-size="' + (this.fontSize - 3) + '" color="' + this.activeFGColor + '">' + theOption.displayText + '</FONT>')
			theOption.document.close()
			theOption.captureEvents(Event.MOUSEUP)
			theOption.onmouseup = function () {
				window.location.href = this.action
			}
		} else {
			theOption.style.backgroundColor = this.activeBGColor
			theOption.style.color = this.activeFGColor
			theOption.onclick = function () {
				window.location.href = this.action
			}
		}
	}
	this.optionOff = function (theOption) {
		this.functionString = "theMenuObjectArray[" + this.objectNumber + "].doOptionOff()"
		this.optionTimerID = setTimeout(this.functionString, 100)
	}
	this.doOptionOff = function() {
		if (!this.activeOption) return false
		var theOption = this.activeOption
		if (ns) {
			theOption.bgColor = this.normalBGColor
			theOption.document.write('<FONT face="' + this.fontFamily + '" point-size="' + (this.fontSize - 3) + '" color="' + this.normalFGColor + '">' + theOption.displayText + '</FONT>')
			theOption.document.close()
		} else {
		  theOption.style.backgroundColor = this.normalBGColor
		  theOption.style.color = this.normalFGColor
		}
		if (theOption.childMenu) {
			theOption.childMenu.hideMenuTree(true)
		}
		this.activeOption = false
	}
	/* create a new menu item */
	this.createMenuItem = function (content, useBG) {
		this.nonItemNumber = this.nonItems.length
		if (ns) this.nonItems[this.nonItemNumber] = new Layer((this.menuWidth - (this.borderWidth * 2)), this.MenuContainer)
		else this.nonItems[this.nonItemNumber] = document.createElement("DIV")
		if (ns) {
			this.nonItems[this.nonItemNumber].clip.width = (this.menuWidth - (this.borderWidth * 2))
			this.nonItems[this.nonItemNumber].top = (this.items.length * this.optionHeight) + this.borderWidth + this.nonOptionTotal
			this.nonItems[this.nonItemNumber].left = this.borderWidth
			this.nonItems[this.nonItemNumber].bgColor = this.normalBGColor
			this.nonItems[this.nonItemNumber].document.write(content)
			this.nonItems[this.nonItemNumber].document.close()
			this.nonItems[this.nonItemNumber].visibility = "inherit"
			this.nonOptionTotal += this.nonItems[this.nonItemNumber].clip.height
			this.MenuContainer.clip.height = ((this.items.length) * this.optionHeight) + (this.borderWidth * 2) + this.nonOptionTotal
			this.nonItems[this.nonItemNumber].onmouseover = function () {
				this.parentLayer.boundObject.nonOptionOn(this)
			}
		} else {
			this.nonItems[this.nonItemNumber].style.position = "absolute"
			this.nonItems[this.nonItemNumber].style.width = (this.menuWidth - (this.borderWidth * 2)) + "px"
			this.nonItems[this.nonItemNumber].style.top = (this.items.length * this.optionHeight) + this.nonOptionTotal + "px"
			this.nonItems[this.nonItemNumber].style.left = 0
			this.nonItems[this.nonItemNumber].innerHTML = "<SPAN id='c'>"+content+"</SPAN>"
			this.MenuContainer.insertBefore(this.nonItems[this.nonItemNumber], null)
			this.nonItems[this.nonItemNumber].style.backgroundColor = this.normalBGColor
			this.nonOptionTotal += (this.nonItems[this.nonItemNumber].offsetHeight)
			this.MenuContainer.style.height = ((this.items.length) * this.optionHeight) + (this.borderWidth * 2) - ((ns6) ? this.borderWidth * 2 : 0) + this.nonOptionTotal
			this.nonItems[this.nonItemNumber].onmouseover = function () {
				this.parentNode.boundObject.nonOptionOn(this)
			}
		}
	}
	this.nonOptionOn = function (theOption) {
		if (this.parentMenu) {
			clearTimeout(this.parentMenu.optionTimerID)
			clearTimeout(this.parentMenu.timerID)
		}
		if (this.activeOption) {
			clearTimeout(this.optionTimerID)
			this.doOptionOff()
		}
	}
	this.objectNumber = theMenuObjectArray.length
	theMenuObjectArray[this.objectNumber] = this
}

function hideAllMenus () {
	for (menuCount = 0; menuCount < theMenuObjectArray.length; menuCount ++) {
		theMenuObjectArray[menuCount].hideMenuTree(true)
	}
}

function buildMenus () {
	var menuCount = 1
	
	menuWidth1 = 160
	menuWidth2 = 110
	menuWidth3 = 90
	menuWidth4 = 150
	menuWidth5 = 100
	menuWidth6 = 95
	
	while (eval("window.oMenu"+menuCount)) {
		menuArray = eval("window.oMenu"+menuCount)
		theMenuWidth = eval('menuWidth' + menuCount)
		eval("menu"+menuCount+" = new Menu(theMenuWidth)")
		theMenu = eval("menu"+menuCount)
		for (optionCount = 1; optionCount<menuArray.length; optionCount ++) {
			if (menuArray[optionCount][2]) {
				theMenu.createMenuOption(menuArray[optionCount][0], menuArray[optionCount][1], createSubMenu(""+menuCount, optionCount))
			} else {
				theMenu.createMenuOption(menuArray[optionCount][0], menuArray[optionCount][1], false)
			}
		}
		menuCount ++
	}
}
function createSubMenu(menuName, optionCount) {
	var menuArray = eval("window.oMenu"+menuName+"_"+optionCount)
	var theMenu = eval("menu"+menuName+"_"+optionCount+" = new Menu("+childMenuWidth+")")
	theMenu.optionHeight = 19
	theMenu.normalBGColor = "#A32B2A"
	theMenu.normalFGColor = "#FFFFFF"
	theMenu.activeBGColor = "#CCCCCC"
	theMenu.activeFGColor = "#A32B2A"
	for (var i=1; i<menuArray.length; i++) {
		if (menuArray[i][2]) {
			theMenu.createMenuOption(menuArray[i][0], menuArray[i][1], createSubMenu(""+menuName+"_"+optionCount, i))
		} else {
			theMenu.createMenuOption(menuArray[i][0], menuArray[i][1])
		}
	}
	return theMenu
}

function onMenu(menuNumber, that) {
		
	if (eval("window.menu" + menuNumber)) {
		var menuObject = eval("window.menu" + menuNumber)
		// figure out if the menu will go over the cut off point
		if (ns) {
			var menuXLeftPos = that.x + defaultOffsetLeft + menuWidth
		} else if (ie || ns6) {
			var menuXLeftPos = getAnchorX(that) + defaultOffsetLeft + menuWidth
		}
		
		//alert(menuXLeftPos)
		if (menuXLeftPos < cutoffRight) {
			if (ns) menuObject.showMenu(that.x + defaultOffsetLeft, defaultOffsetTop);
			else if (ie || ns6) menuObject.showMenu(getAnchorX(that) + defaultOffsetLeft, defaultOffsetTop);
		} else {
			//alert('your aving a larf')
			if (ns) menuObject.showMenu(cutoffRight - menuWidth, defaultOffsetTop);
			else if (ie || ns6) menuObject.showMenu(cutoffRight - menuWidth, defaultOffsetTop);
		}
		
		
	}
}

function timeOutMenu(menuNumber) {
	if (eval("window.menu" + menuNumber)) {
		var menuObject = eval("window.menu" + menuNumber)
		menuObject.timeOutMenu()
	}
}

function getAnchorX(theAnchor) {
	var offsetL = theAnchor.offsetLeft;
	while ((theAnchor=theAnchor.offsetParent) != null) { 
		offsetL += theAnchor.offsetLeft; 
	}
	return offsetL;
}
function getAnchorY(theAnchor) {
	var offsetT = theAnchor.offsetTop;
	while((theAnchor = theAnchor.offsetParent) != null) { 
		offsetT += theAnchor.offsetTop; 
	}
	return offsetT;
}
