// Generate all navigation menu objects
for (var i = 0; i < glnav_menuNames.length; i++) {
	//debugln(' ' + glnav_menuNames[i]);
	var menuName = glnav_menuNames[i];
	glnav_menuObjs[menuName] = new Menu(menuName,glnav_menuText[menuName],glnav_menuURLs[menuName]);
}

// Constructor for menu objects
// Last modified: 06.05.01 
// Original author: rPm | Race
function Menu(name,menuText,menuURLs) {
    //debugln('Menu Constructor: Name:' + name);
	this.name = name;
	this.containerDivRef = this.name + 'Container';
	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 = glnav_menuWidth;
	this.rowHeight = glnav_menuRowHeight;
	this.menuElmHeight = glnav_menuElmHeight;
	this.pad = glnav_menuPad;
	this.menuClass = glnav_menuTextClass;
	this.menuEdgeColor = glnav_menuEdgeColor;
	this.highlightColor = glnav_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 = glnav_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() {
   //debugln('in MenuBuild');
   var cellWidth = this.menuWidth - 2;
   var dataWidth = cellWidth - 2*this.pad;
   this.div = '<div id="' + this.containerDivName + '" width="' + this.menuWidth + '">\n';
   this.div += '   <table width="' + this.menuWidth + '" summary="Menu for ' + this.name + '" border="0" cellpadding="0" cellspacing="0">\n';
   this.div += '    <tr><td colspan="3" height="1" bgcolor="' + this.menuEdgeColor + '"><spacer type="block" height="1" width="1"></td>\n';
   
   // Generate code for all URLs
   var elmName;
   for (var i = 0; i < this.menuText.length; i++) {
   		elmName = this.name + 'Elm' + i;
   		this.div += '    <tr height="' + this.rowHeight + '"><td width="1" bgcolor="' +this.menuEdgeColor + '"><spacer type="block" height="1" width="1"></td>\n';
		if (this.menuText[i] != '') {
			this.div += '       <td width="' + cellWidth + '" id="' + elmName + '" width="' + cellWidth + '" onmouseover="' + this.obj + '.highlightElm(\'' + elmName + '\');" onmouseout="' + this.obj + '.revertElm(\'' + elmName + '\');">\n';
			this.div += '	<table height="' + this.rowHeight + '" width="' + cellWidth + '" cellpadding="0" cellspacing="0" border="0">\n';
			this.div += '	  <tr height="' + this.pad + '"><td colspan="3"><spacer type="block" height="1" width="1"></td></tr>\n';
			this.div += '	  <tr height="' + this.menuElmHeight + '"><td width="' + this.pad + '"><spacer type="block" height="1" width="1"></td>\n';
			this.div += '	    <td width="' + dataWidth + '" valign="middle">&nbsp;<a class="' + this.menuClass + '" href="' + this.menuURLs[i] + '">' + this.menuText[i] + '</a></td>\n';
			this.div += '	    <td width="' + this.pad + '"><spacer type="block" height="1" width="1"></td></tr>\n';
			this.div += '	  <tr height="' + this.pad + '"><td colspan="3"><spacer type="block" height="1" width="1"></td></tr>\n';
			this.div += '	</table></td>\n';
		} else {
			// Empty cell within menu
			this.div += '       <td width="' + cellWidth + '">&nbsp;</td>\n';
		}
		this.div += '       <td width="1" bgcolor="' + this.menuEdgeColor + '"><spacer type="block" height="1" width="1"></td></tr>\n';
        this.div += '    <tr><td colspan="3" height="1" bgcolor="' + this.menuEdgeColor + '"><spacer type="block" height="1" width="1"></td>\n';
   }
   this.div += '   </table>\n</div>\n';
   
   //debugln(this.div);
}