// firstRun - is this the first time the script has been run
var firstRun = true;
var mouseOverMenu = false;

function checkMousePosition(menuObj) {
	thisObj = menuObj;
	if (mouseOverMenu == false) {
		hideObject(thisObj);
	}
}
function hideMenu(menuObj) {
	thisObj = menuObj;
	mouseOverMenu = false;
	menuTimeout = setTimeout("checkMousePosition(thisObj)", 1000);
}
function showMenu(menuObj) {
	if (is.ie) {
		thisObj = menuObj;
		mouseOverMenu = true;
		if (firstRun == false) {
			hideObject(lastMenu);
		} else {
			firstRun = false;
		}
		showObject(thisObj);
		lastMenu = thisObj;
	}
}
function menuItem(name, colour, vis, x, y, width, align) {
	if (is.ie) { winWidth = document.body.offsetWidth-20; winHeight = document.body.offsetHeight; }
	if (is.ns) { winWidth = window.innerWidth-16; winHeight = window.innerHeight; }
	if (winWidth < 780) { winWidth = 760+25; }
	// declare the properties of the menuItem object
	this.name = name;
	this.width = width;
	this.addItem = addItem;
	this.startItems = startItems;
	this.endItems = endItems;
	// write the styles for the menuItem
	writeCSSHeader();
	if (is.ie) {
		if (align == "center") {
			writeCSS(name,'absolute',(winWidth/2)+x,y,width,colour,vis);
		} else if (align == "left") {
			writeCSS(name,'absolute',x,y,width,colour,vis);
		}
	}
	if (is.ns) {
		if (align == "center") {
			writeCSS(name,'absolute',((winWidth/2)+x)-(x/13),y,width,colour,vis);
		} else if (align == "left") {
			writeCSS(name,'absolute',x-(x/13),y,width,colour,vis);
		}
	}
	writeCSSFooter();
}
function addItem(itemText, linkText) {
	// add a new item
	tempText = linkText;
	document.write("<tr>\n");
    document.write("<td onMouseOver='showMenu("+this.name+");changeStyle(this, true)' onMouseOut='hideMenu("+this.name+");changeStyle(this, false)' onClick=\"goToPage('"+linkText+"')\" class='mouse_out'>\n"); // onClick='goToPage("+linkText+")'
	document.write("<ilayer><layer width='100%' onMouseOver='showMenu("+this.name+");changeStyle(this, true)' onMouseOut='hideMenu("+this.name+");changeStyle(this, false)'>");
	if (is.ie) { document.write(itemText); }
	if (is.ns) { document.write("<a href='"+linkText+"' class='l_sub_menu'>"+itemText+"</a>"); }
	document.write("</ilayer></layer></td>\n");
	document.write("</tr>\n");
}
function startItems() {
	// start the items list
	document.write("<div id='"+this.name+"' class='menu_item' onMouseOver='showMenu("+this.name+");' onMouseOut='hideMenu("+this.name+");'>\n");
	document.write("<table width='100%' cellspacing='1' cellpadding='2' border='0'>\n");
}
function endItems() {
	// end the items list
	document.write("</table>\n");
	document.write("</div>\n");
}
function changeStyle(theCell, isMouseOver) {
	// change the style of the td on mouseOver
	if (isMouseOver) {
		theCell.className = "mouse_over";
	} else {
		theCell.className = "mouse_out";
	}
}
function goToPage(thePage) {
	// the url of the page to go to
	location.href = thePage;
}