var browserVersion = navigator.appVersion
var browserName = navigator.appName
var browserPlatform = navigator.platform

var ie = (browserName == "Microsoft Internet Explorer")
var moz = (browserName == "Netscape")
var pc = (browserPlatform.indexOf('Win') >= 0)
var mac = (browserPlatform.indexOf('Mac') >= 0)


var menusOpen = new Array()

var topmenuitem


function menuObj(id) {
	this.layerobj = document.getElementById(id + "menu")
	this.layerobj.name = id + "menu"
	this.layerobj.kidarray = eval(id + "menuarray")
	this.layerobj.css = this.layerobj.style
	this.layerobj.visible = this.layerobj.css.visibility
	this.layerobj.myparent = document.getElementById(id + "link")
	
	if (this.layerobj.myparent != null) {
		navparent = this.layerobj.myparent.parentNode
		firstmenu = (this.layerobj.myparent.myparent.name == 'navlinksmenu') ? true : false
		//this.layerobj.css.top = navparent.offsetTop + ((firstmenu) ? navparent.offsetHeight + ((moz) ? -1 : 39): this.layerobj.myparent.offsetTop)
		//this.layerobj.css.left = navparent.offsetLeft + ((firstmenu) ? document.getElementById("maintable").offsetLeft : navparent.offsetWidth)
		
		this.layerobj.css.top = navparent.parentNode.parentNode.parentNode.parentNode.offsetTop + navparent.offsetHeight + "px"
		this.layerobj.css.left = document.getElementById("maintable").offsetLeft + navparent.parentNode.parentNode.parentNode.parentNode.offsetLeft + navparent.offsetLeft + "px"
	}
	
	this.layerobj.show = showMe
	this.layerobj.hide = hideMe
	this.layerobj.makechildren = makeMenuObjects
	this.layerobj.makechildren()
}


function makeMenuObjects() {
	for (this.i = 0; this.i < this.kidarray.length; this.i++) {
		this.kidarray[this.i] = new menuItemObj(this.kidarray[this.i], this.name)
	}
}


function menuItemObj(id, par) {
	this.layerobj = document.getElementById(id + "link")
	this.layerobj.name = id + "link"
	this.layerobj.myparent = document.getElementById(par)
	if (document.getElementById(id + "menu")) {
		new menuObj(id)
		this.layerobj.kids = document.getElementById(id + "menu")
	}
	this.layerobj.css = this.layerobj.style
	this.layerobj.onmouseover = itemOver
	this.layerobj.onmouseout = itemOut
	this.layerobj.onmousedown = itemDown
	this.layerobj.cleanMenus = cleanUp
}



function itemOver() {
	//this.className='navitemover'
	//this.className = (this.myparent.name == "navlinksmenu") ? 'topnavitemover' : 'navitemover'
	
	if (this.className == 'navitem') this.className = 'navitemover'
	if (this.className == 'navitem2') this.className = 'navitemover2'
	
	//color the top nav item
	if (this.myparent.name == "navlinksmenu") {
		if (topmenuitem) topmenuitem.style.background=''
		topmenuitem = this.parentNode
		//topmenuitem.style.background='#000000'
	}
	
	clearTimeout(theTime)

	if (menusOpen.length > 0) {
		
		/*theres something in the menusopen array so you need to see what it is so you dont double up on menus in the array*/
		
		lastOne = menusOpen[menusOpen.length - 1]
		if (lastOne != this.myparent && lastOne != this.kids) {
			
			/*if the lastone = myparent then you just rolled onto another link in the same menu
			if lastone = kids then you are rolling back onto a link from its submenu
			if neither one are true then add your menu group (myparent), 
			so for example this happens when you roll onto a submenu
			
			but if you are 3 levels deep and you rolloff that entire branch and go back to a 
			completely different part of the main menu, that would be a rollover and its parent or kids 
			wouldnt be the last one in the array so we have this loop here*/
			
			for (p=0; p < menusOpen.length; p++) {
				if (menusOpen[p] == this.myparent) {
					this.cleanMenus()
					break
				}
			}
			
			menusOpen[menusOpen.length] = this.myparent
		}
	}
	else  {
	
		/*theres nothing in the menus open so you stick in your menu*/
		
		menusOpen[menusOpen.length] = this.myparent
	}
	
	/*this cleanMenus is here in case someone rolled off one of is childmenus and it needs to be removed*/

	this.cleanMenus()
	if (this.kids) this.kids.show()
}


function itemOut() {
	//this.className='navitem'
	//this.className = (this.myparent.name == "navlinksmenu") ? 'topnavitem' : 'navitem'
	if (this.className == 'navitemover') this.className = 'navitem'
	if (this.className == 'navitemover2') this.className = 'navitem2'
	
	//uncolor the top nav item
	if (this.myparent.name == "navlinksmenu" && !this.kids) {
		if (topmenuitem) topmenuitem.style.background=''
	}
	
	setTimer()
}


function itemDown() {
	if (this.myparent.name != "navlinksmenu") {
		index = (moz) ? 1 : 0
		window.location = this.childNodes[index].href
	}
}


function cleanUp() {
	for (i = menusOpen.length-1; i >= 0; i--) {
		/*loop through the openmenus array */
		for (j = 0; j < menusOpen[i].kidarray.length; j++) {
			/*for each link item in the menu check to see if that item has a kids menu and if it does then hide that menu */
			if (menusOpen[i].kidarray[j].layerobj.kids) menusOpen[i].kidarray[j].layerobj.kids.hide()
		}
		
		/*menusOpen[i] = your own parent menu then break out of the loop because you dont want to hide yourself 
		or the menus opened above you, although your children and grandchildren should have already been hidden 
		by this point*/
		
		if (menusOpen[i] == this.myparent) break
		
		//uncolor the top nav item
		if (menusOpen[i].myparent && menusOpen[i].myparent.myparent.name == "navlinksmenu") {
			topmenuitem.style.background=''
		}
		else if (menusOpen[i].myparent == null) {
			topmenuitem.style.background=''
		}
		
		/*hide the menus as it goes backward throught the array hidding those menus opened last,
		then set the array value to null and reset the array length */
		
		menusOpen[i].hide()
		menusOpen[i] = null
		menusOpen.length = menusOpen.length - 1
	}
}


function showMe() {
	this.visible = "visible"
	this.css.visibility = this.visible
}


function hideMe() {
	if (this.name != "navlinksmenu") {
		this.visible = "hidden"
		this.css.visibility = this.visible
	}
}


var theTime

function setTimer() {
	theTime = setTimeout("cleanUp()", 1000)
}


function buildMenu() {
	new menuObj("navlinks")
}
