

function Menu(sName,sWidths)
	{
	this.name = sName;
	this.width = 0
	this.height = 27
	this.menucount = 0
	this.offsets = sWidths.split(",")
	this.mainindexes = new Array()
	this.data = new Array();
	this.parents = ":";
	this.subsec = "";
	}

Menu.prototype = {
	
	// ============== Add Menu Item
	
	add : function (id, cap, sAction, sOptions, sParent, alt)
		{
		var iTemp
		if (arguments.length < 3) sAction = ""
		if (arguments.length < 4) sOptions = ""
		if (arguments.length < 5) sParent = ""
		if (arguments.length < 6) alt = ""
		if (sParent != "") 
			{
			this.parents += sParent + ":"
			}
		else
			{
			this.menucount++;
			this.mainindexes[this.data.length] = this.menucount;
			iTemp = this.offsets[this.mainindexes[this.data.length]]
			if (!isNaN(iTemp)) 
				{
				iTemp = parseInt(iTemp)
				this.width += iTemp;
				}
			}
		
		this.data[this.data.length] = new Array(id, cap, sAction, sOptions, sParent, alt)
		},
	
	// ============== Generate Menu HTML
	
	draw : function (main)
		{
		var sBuffer = "<table cellspacing='0' cellpadding='0' border='0' height='" + this.height + "px'><tr>"
		
		for (var a=0;a<this.data.length;a++)
			{
			if (this.data[a][4] == "") sBuffer += this.drawRow(a)
			}
		
		sBuffer += "</tr><td colspan='100'><img src='images/spacer.gif' height='0' width='" + this.width + "px'></td></tr>"
		sBuffer += "</table>"
		
		return sBuffer;
		},
	
	// ============== Generate Menu Row HTML
	
	drawRow : function (a)
		{
		var sBuffer = "<td id='m-" + a + "' class='menuitem' width='" + this.offsets[this.mainindexes[a]] + "'"
			if (this.data[a][2] != "") sBuffer += " onmouseup=\"menu_exec(" + a + ", '" + this.name + "')\""
			sBuffer += " onmouseover=\"hilite_menu(" + a + ",'" + this.data[a][0] + "')\""
			sBuffer += " onmouseout='norm_menu(" + a + ")'>"
			sBuffer += this.data[a][1]
			sBuffer += "</td>"
			
		return sBuffer;
		},

	// ============== Generate SubMenu HTML
	
	drawsub : function (parent)
		{
		var iCount = 0;

		var sBuffer = "<table cellspacing='0' cellpadding='0' border='0'>"
		
		for (var a=0;a<this.data.length;a++)
			{
			if (this.data[a][4] == parent)
				{
				sBuffer += this.drawSubRow(a)
				iCount++;
				}
			}
		
		// sBuffer += "<tr><td class='submenucap'>&nbsp;</td><tr>"
		sBuffer += "</table>"
		if (iCount == 0) return "";
		return sBuffer;
		},

	
	// ============== Generate Submenu Row HTML
	
	drawSubRow : function (a)
		{
		var sBuffer = "<tr>"
			sBuffer += "<td class='submenutext' id='sm_" + a + "'"
			if (this.data[a][2] != "") sBuffer += " onmouseup=\"menu_exec(" + a + ", '" + this.name + "')\""
			sBuffer += " onmouseover='hilite_submenu(" + a + ")'"
			sBuffer += " onmouseout='norm_submenu(" + a + ")'"
			if (this.data[a][5] != "") sBuffer += " alt='" + a + "'"
			sBuffer += ">"
			sBuffer += this.data[a][1]
			sBuffer += "</td>"
			sBuffer += "<tr>"
			
		return sBuffer;
		},
	
	// ============== Calculate the menu offset
	
	getoffset : function (iIndex)
		{
		iIndex = this.mainindexes[iIndex]
		var iTotal = 0;
		for (var a=0;a<iIndex;a++)
			{
			iTotal += parseInt(this.offsets[a])
			}
		return iTotal;
		},
		
	getleftedge : function ()
		{
		var iLeft = (document.body.clientWidth - this.width) / 2
		if (iLeft < 0) iLeft = 0;
		return iLeft
		}
		
	}

// ============= E X T E R N A L   F U N C T I O N S

function hilite_menu(id,sParent)
	{
	var sBuffer = oMenu.drawsub(sParent)
	var obj = document.getElementById("m-" + id);
	obj.style.backgroundColor = "#A6BF7D"
	
	if (sBuffer == "")
		{
		clearMenu()
		}
	else
		{
		var obj = document.getElementById("submenusec");
		obj.style.left = (oMenu.getleftedge() + oMenu.getoffset(id)) + "px"
		obj.innerHTML = sBuffer;
		obj.style.display = ""
		}
	}

function norm_menu(id)
	{
	var obj = document.getElementById("m-" + id);
	obj.style.backgroundColor = ""
	}

function hilite_submenu(id,sParent)
	{
	var obj = document.getElementById("sm_" + id)
	obj.style.backgroundColor = "#A6BF7D"
	var data = oMenu.data[id];
	window.status = data[5]
	}

function norm_submenu(id)
	{
	var obj = document.getElementById("sm_" + id)
	obj.style.backgroundColor = "";
	}

function menu_exec(id, sName)
	{
	var obj = self[sName];
	var data = obj.data[id];
	var opt = data[3].toUpperCase()
	opt = opt.split(",")
	
	switch (opt[0])
		{
		case "":
			if (data[2] != "") self.location = data[2];
			break;
		case "NEW":
			window.open(data[2],"_new")
		}
	
	}

function clearMenu()
	{
	var obj = document.getElementById("submenusec");
	obj.style.display = "none"
	}
	