

// Generate all navigation menu objects
for (var i = 0; i < nav_menuNames.length; i++) {
	var menuName = nav_menuNames[i];
	nav_menuObjs[menuName] = new Menu(menuName,nav_menuText[menuName],nav_menuURLs[menuName], nav_menuWidth, nav_menuRowHeight, nav_menuTextInset, nav_menuTextClass);
}

// Constructor for menu objects
function Menu(name,menuText,menuURLs, menuWidth, menuRowHeight, menuTextInset, MenuTextClass) {
	this.name = name;
	this.containerDivRef = this.name + 'Menu';
	this.containerDivName = this.containerDivRef + 'Div';
	this.menuText = menuText;
	this.menuURLs = menuURLs;
	this.obj = this.name + 'Obj';
	this.openMenu = MenuOpen;
	this.closeMenu = MenuClose;
	this.build = MenuBuild;
	this.highlightElm = HighlightElm;
	this.revertElm = RevertElm;
	
	// Various style attributes for menu elements
	this.menuWidth = nav_menuWidth;
	//this.rowHeight = menuRowHeight;
	this.menuRowHeight = nav_menuRowHeight;
	this.menuTextInset = nav_menuTextInset;
	//this.padHeight = menuPadHeight;
	//this.padWidth = menuPadWidth;
	this.menuClass = MenuTextClass;
	this.menuEdgeColor = nav_menuEdgeColor;
	this.menuOutlineColor = nav_menuOutlineColor;
	this.highlightColor = nav_menuHighlightColor;
	eval(this.obj+"=this");
	// Build the menu items
	this.build();	
}

function MenuOpen() {
	eval(this.containerDivRef + ".show()");
}

function MenuClose() {
	eval(this.containerDivRef + ".hide()");
}

function HighlightElm(name) {
	obj=getDomObjRef(name);

	if (is.ie4) {
		obj.background = nav_ie4HighlightImage;
	} else {
		obj.bgColor = this.highlightColor;
	}
}

function RevertElm(name) {
	obj=getDomObjRef(name);
		
	if (is.ie4) {
		obj.background = '';
	} else {
		obj.bgColor = '';
	}
}
	

// Function to dynamically build the DIVs used to house the content menu
function MenuBuild() {
	var cellWidth = this.menuWidth - 8;
	var dataWidth = cellWidth - 4
	var tableWidth = this.menuWidth;

	this.div = '<div id="' + this.containerDivName + '" width="' + tableWidth + '">\n';
	this.div += '   <table width="' + tableWidth + '" summary="Menu for ' + this.name + '" border="0" cellpadding="0" cellspacing="0">\n<tr>\n';
	this.div += '    <td bgcolor="' + this.menuEdgeColor + '"><img src="/images/interface/pixelWedge.gif" alt="" width="4" height="1" border="0"></td>\n';
	this.div += '    <td bgcolor="' + this.menuEdgeColor + '" ><img src="/images/interface/pixelWedge.gif" alt="" width="2" height="1" border="0"></td>\n';
	this.div += '    <td bgcolor="' + this.menuEdgeColor + '"><img src="/images/interface/pixelWedge.gif" alt="" width="4" height="1" border="0"></td>\n</tr>\n';

	// Generate code for all URLs
	var j = 0;
	var elmName;
	for (var i = 0; i < this.menuText.length; i++) {
		thisImg = nav_menuArrow[menuName][i];
		thisImgNormal = "/images/interface/pixelWedge.gif";
		thisImgActive = "/images/nav/global/menuArrow.gif";
		arrowSwapInit(thisImg,thisImgActive,thisImgNormal);
		elmName = this.name + 'Elm' + i;
		this.div += '<tr><td bgcolor="' + this.menuEdgeColor + '"><img src="/images/interface/pixelWedge.gif" alt="" width="4" height="2" border="0"></td>\n';
		if (this.menuText[i] != '') {
			this.div += '<td width="' + cellWidth + '" id="' + elmName + '" width="' + cellWidth + '">\n';
			this.div += '<table width="' + cellWidth+ '" cellpadding="0" cellspacing="0" border="0">\n';
			this.div += '<tr><td background="/images/nav/global/menuDots.gif"><img src="/images/interface/pixelWedge.gif" name="'+ thisImg +'" alt="" width="16" height="23" border="0"></td>\n';
			this.div += '<td width="' + dataWidth +'"><div class="menuMargin"><a href="/'+ this.name +'/' + this.menuURLs[i] + '" class="'+ this.menuClass + '" onmouseout="arrowOff(\''+ thisImg +'\');" onmouseover="arrowOn(\''+ thisImg +'\');">' + this.menuText[i] + '</a></div></td>\n';
			this.div += '<tr><td colspan="3" bgcolor="' + this.menuEdgeColor + '"><img src="/images/interface/pixelWedge.gif" alt="" width="4" height="1" border="0"></td></tr>\n';
			this.div += '</table></td>\n';
		} else {
			// Empty cell within menu
			this.div += '       <td width="' + cellWidth + '">&nbsp;</td>\n';
		}
			this.div += '    <td bgcolor="' +this.menuEdgeColor + '"><img src="/images/interface/pixelWedge.gif" alt="" width="4" height="2" border="0"></td></tr>\n';
	}
	this.div += '<tr>\n<td bgcolor="#ffffff" colspan="3"><img src="/images/interface/pixelWedge.gif" alt="" width="4" height="2" border="0"></td>\n</tr>\n</table>\n</div>\n';
}
