function menuSystem(numOfMenus, name, mainLeft, mainTop, hideTimer)
{
	this.numOfMenus = numOfMenus;
	this.name = name;
	this.mainLeft = mainLeft;
	this.mainTop = mainTop;
	this.hideTimer = hideTimer;
	this.code = '';
	this.menus = new Array();
	this.activeItems = new Array();
	this.menuCounter = 0;
	this.write = write;
}

function activeItem(name, parentName, functions)
{
	this.name = name;
	this.parentName = parentName;
	this.functions = functions;
	this.isActive = false;
}

function menu(parentMenuID, menuID, orientation, isMainMenu, numOfItems, size, bgColorNorm, bgColorOver, 
	textColorNorm, textColorOver, fontName, fontSize, fontStyle, borderedItems, borderSize, borderStyle, 
	borderColor, padding, markerWidth, markerType, markerImages, markerSymbol, showOption,	xOffset, 
	yOffset, showMarkers, hasRolloverTransitions, transitionNumber, cursor, menuTrans, transNum, 
	menuSystem)
{
	this.parentMenuID = parentMenuID;
	this.menuID = menuID;
	this.orientation = orientation;
	this.isMainMenu = isMainMenu;
	this.numOfItems = numOfItems;
	this.size = size;
	this.bgColorNorm = bgColorNorm;
	this.bgColorOver = bgColorOver;
	this.textColorNorm = textColorNorm;
	this.textColorOver = textColorOver;
	this.fontName = fontName;
	this.fontSize = fontSize;
	this.fontStyle = fontStyle;
	this.borderedItems = borderedItems;
	this.borderSize = borderSize;
	this.borderStyle = borderStyle;
	this.borderColor = borderColor;
	this.padding = padding;
	this.markerWidth = markerWidth;
	this.markerType = markerType;
	this.markerImages = markerImages;
	this.markerSymbol = markerSymbol;
	this.showOption = showOption;
	this.xOffset = xOffset;
	this.yOffset = yOffset;
	this.showMarkers = showMarkers;
	this.hasRolloverTransitions = hasRolloverTransitions;
	this.transitionNumber = transitionNumber;
	this.cursor = cursor;
	this.menuTrans = menuTrans;
	this.transNum = transNum;
	this.menuSystem = menuSystem;
	this.targets = new Array();
	this.links = new Array();
	this.code = '';
	this.script = '';
	this.itemCounter = 0;
	this.left = borderSize;
	this.top = borderSize;
	this.addItem = item;
	this.compile = compile;

	if (isNS4)
	{
		if (orientation == "horizontal")
			this.xOffset -= borderSize;
		else
			this.yOffset -= borderSize;
	}
}

function item(height, width, target, link, alignment, content, menuToShow, showDir)
{
	var parentMenuID = this.parentMenuID;
	var menuID = this.menuID;
	var orientation = this.orientation;
	var numOfItems = this.numOfItems;
	var size = this.size;
	var bgColorNorm = this.bgColorNorm;
	var bgColorOver = this.bgColorOver;
	var textColorNorm = this.textColorNorm;
	var textColorOver = this.textColorOver;
	var fontName = this.fontName;
	var fontSize = this.fontSize;
	var fontStyle = this.fontStyle;
	var borderedItems = this.borderedItems;
	var borderSize = this.borderSize;
	var borderStyle = this.borderStyle;
	var borderColor = this.borderColor;
	var padding = this.padding;
	var markerWidth = this.markerWidth;
	var markerType = this.markerType;
	var markerImages = this.markerImages;
	var markerSymbol = this.markerSymbol;
	var showOption = this.showOption;
	var xOffset = this.xOffset;
	var yOffset = this.yOffset;
	var showMarkers = this.showMarkers;
	var hasRolloverTransitions = this.hasRolloverTransitions;
	var transitionNumber = this.transitionNumber;
	var cursor = this.cursor;
	var menuTrans = this.menuTrans;
	var transNum = this.transNum;
	var menuSystem = this.menuSystem;
	
	this.targets[this.itemCounter] = target;
	this.links[this.itemCounter] = link;

	var btag;
	if (isIE || isNS5)
	{
		if (orientation == "horizontal")
			btag = "span";
		else
			btag = "div";
	}

	var	sizeString = 'height="' + height + '" width="' + width + '"';

	var bStyleTag = "", eStyleTag = "";
	var nfontStyle = fontStyle;
	fontStyle = "";

	if (nfontStyle.indexOf("bold") != -1)
	{
		fontStyle += "font-weight:bold;";
		bStyleTag += "<b>";
		eStyleTag += "</b>";
	}
	
	if (nfontStyle.indexOf("italic") != -1)
	{
		fontStyle += "font-style:italic;";
		bStyleTag += "<i>";
		eStyleTag += "</i>";
	}

	if (nfontStyle.indexOf("underline") != -1)
	{
		fontStyle += "text-decoration:underline;";
		bStyleTag += "<u>";
		eStyleTag += "</u>";
	}

	var border;
	if (isIE || isNS5)
	{
		if (this.orientation == "horizontal" && this.itemCounter != numOfItems - 1 && borderedItems)
			border = "border-right:" + borderSize + "px " + borderStyle + " " + borderColor + ";";
		else if (this.orientation == "vertical" && this.itemCounter != numOfItems - 1 && borderedItems)
			border = "border-bottom:" + borderSize + "px " + borderStyle + " " + borderColor + ";";
		else
			border = "";
	}

	var markerNorm, markerOver;
	var markerFunctionOver, markerFunctionOut;
	if (markerType == "image")
	{
		markerImages = markerImages.split(":");
		var markerImgNorm = markerImages[0];
		var markerImgOver = markerImages[1];

		markerFunctionOver = "rollover(\'" + menuID + "Marker" + this.itemCounter + "\', \'" + 
			markerImgOver + "\', false, 0);";
		markerFunctionOut = "rollover(\'" + menuID + "Marker" + this.itemCounter + "\', \'" + markerImgNorm 
			+ "\', false, 0);";

		markerNorm = '<img id="' + menuID + 'Marker' + this.itemCounter + '" src="' + markerImgNorm + '" ' + 
			'border="0">';
		markerOver = '<img id="' + menuID + 'Marker' + this.itemCounter + '" src="' + markerImgOver + '" ' + 
			'border="0">';
	}
	else if (markerType == "symbol")
	{
		markerFunctionOver = "colorText(\'" + menuID + "Marker" + this.itemCounter + "\', \'" + 
			textColorOver + "\');";
		markerFunctionOut = "colorText(\'" + menuID + "Marker" + this.itemCounter + "\', \'" + 
			textColorNorm + "\');";
		
		if (isIE || isNS5)
			markerNorm = '<font id="' + menuID + 'Marker' + this.itemCounter + '" color="' + textColorNorm + 
				'" face="' + fontName + '" style="font-size:' + fontSize + 'pt; ' + fontStyle + '">' + 
				markerSymbol + '</font>';
		else if (isNS4)
		{
			markerNorm = '<font id="' + menuID + 'Marker' + this.itemCounter + '" color="' + textColorNorm + 
				'" face="' + fontName + '" point-size="' + fontSize + '">' + bStyleTag + markerSymbol + 
				eStyleTag + '</font>';
			markerOver = '<font id="' + menuID + 'Marker' + this.itemCounter + '" color="' + textColorOver + 
				'" face="' + fontName + '" point-size="' + fontSize + '">' + bStyleTag + markerSymbol + 
				eStyleTag + '</font>';
		}
	}
	
	if (!showMarkers || menuToShow == "")
	{
		markerFunctionOver = "";
		markerFunctionOut = "";
		markerNorm = '';
		markerOver = '';
	}

	var showStringClick, showStringOver;
	if (menuToShow != "")
	{
		if (showOption == "click")
		{
			showStringClick = 'show(' + menuSystem.name + ', \'' + menuToShow + '\', \'' + menuID + '\', \'' 
				+ menuID + 'Item' + this.itemCounter + '\', \'' + showDir + '\', ' + xOffset + ', ' + yOffset + 
				', ' + menuTrans + ', ' + transNum + ');';
			showStringOver = '';
		}
		else if (showOption == "over")
		{
			showStringClick = '';
			showStringOver = 'show(' + menuSystem.name + ', \'' + menuToShow + '\', \'' + menuID + '\', \'' 
				+ menuID + 'Item' + this.itemCounter + '\', \'' + showDir + '\', ' + xOffset + ', ' + yOffset 
				+ ', ' + menuTrans + ', ' + transNum + ');';
		}
	}
	else
	{
		showStringClick = '';
		showStringOver = 'hideAfter(' + menuSystem.name + ', \'' + menuID + '\');';
	}

	var itempad;
	if (!padding)
		itempad = "";
	else
		itempad = "&nbsp;";

	var contentNorm, contentOver;
	var rollFunctionOver = "", rollFunctionOut = "";
	if ((isIE || isNS5) && content.indexOf("rollover:") != -1)
	{
		var imageArray = content.split(":");
		var normImage = imageArray[1];
		var overImage = imageArray[2];
		var rollFunctionOver = "rollover(\'" + menuID + "Rollover" + this.itemCounter + "\', \'" + 
			overImage + "\', " + hasRolloverTransitions + ", " + transitionNumber + ");";
		var rollFunctionOut = "rollover(\'" + menuID + "Rollover" + this.itemCounter + "\', \'" + 
			normImage + "\', " + hasRolloverTransitions + ", " + transitionNumber + ");";

		content = '<img name="' + menuID + 'Rollover' + this.itemCounter + '" src="' + normImage + '" ' + 
			'height="' + height + '" width="' + width + '" border="0" onmouseover="' + rollFunctionOver + 
			'" onmouseout="' + ((menuToShow == "") ? rollFunctionOut : "") + '">';
	}
	else if (isNS4 && content.indexOf("rollover:") != -1)
	{
		var imageArray = content.split(":");
		var normImage = imageArray[1];
		var overImage = imageArray[2];

		contentNorm = '<img src="' + normImage + '" height="' + height + '" width="' + width + '" ' + 
			'border="0">';
		contentOver = '<img src="' + overImage + '" height="' + height + '" width="' + width + '" ' + 
			'border="0">';
	}
	else if (isNS4)
	{
		contentNorm = content;
		contentOver = content;
	}

	if (isNS5 && cursor == "hand")
		cursor = "pointer";
	if (link == "" || link == "#")
		cursor = "default";

	var textColorFunctionOver = "", textColorFunctionOut = "";
	if (isIE || isNS5)
	{
		textColorFunctionOver = "colorText(\'" + menuID + "Text" + this.itemCounter + "\', \'" + 
			textColorOver + "\');";
		textColorFunctionOut = "colorText(\'" + menuID + "Text" + this.itemCounter + "\', \'" + 
			textColorNorm + "\');";
	}

	var contentTable = '';
	var contentTableNorm = '', contentTableOver = '';
	if (isIE || isNS5)
	{
		contentTable += '\t<table border="0" cellpadding="0" cellspacing="0" height="' + height + '" ' + 
			'width="' + width + '">\r';
		contentTable += '\t\t<tr>\r';
		contentTable += '\t\t\t<td align="' + alignment + '"><font id="' + 
			menuID + 'Text' + this.itemCounter + '" color="' + textColorNorm + '" face="' + fontName + 
			'" style="font-size:' + fontSize + 'pt; ' + fontStyle + '">' + itempad + content + 
			'</font></td>\r';
		if (showMarkers && menuToShow != "")
			contentTable += '\t\t\t<td align="right" width="' + markerWidth + '">' + markerNorm + 
				itempad + '</td>\r';
		contentTable += '\t\t</tr>\r';
		contentTable += '\t</table>\r';
	}
	else if (isNS4)
	{
		contentTableNorm += '\t<table border="0" cellpadding="0" cellspacing="0" height="' + height + '" ' 
			+	'width="' + width + '">\r';
		contentTableNorm += '\t\t<tr>\r';
		contentTableNorm += '\t\t\t<td align="' + alignment + '"><font color="' 
			+ textColorNorm + '" face="' + fontName + '" point-size="' + fontSize + 'pt">' + bStyleTag + 
			itempad + contentNorm + eStyleTag + '</font></td>\r';
		if (showMarkers && menuToShow != "")
			contentTableNorm += '\t\t\t<td align="right" width="' + markerWidth + '">' + markerNorm + 
				itempad + '</td>\r';
		contentTableNorm += '\t\t</tr>\r';
		contentTableNorm += '\t</table>\r';

		contentTableOver += '\t<table border="0" cellpadding="0" cellspacing="0" height="' + height + '" ' 
			+	'width="' + width + '">\r';
		contentTableOver += '\t\t<tr>\r';
		contentTableOver += '\t\t\t<td align="' + alignment + '"><font color="' 
			+ textColorOver + '" face="' + fontName + '" point-size="' + fontSize + 'pt">' + bStyleTag + 
			itempad + contentOver + eStyleTag + '</font></td>\r';
		if (showMarkers && menuToShow != "")
			contentTableOver += '\t\t\t<td align="right" width="' + markerWidth + '">' + markerOver + 
				itempad + '</td>\r';
		contentTableOver += '\t\t</tr>\r';
		contentTableOver += '\t</table>\r';
	}

	var bgFunctionOver = "", bgFunctionOut = "";
	var layerFunctionOver = "", layerFunctionOut = "";
	if (isIE || isNS5)
	{
		bgFunctionOver = "colorBg(\'" + menuID + "Item" + this.itemCounter + "\', \'" + bgColorOver + "\');";
		bgFunctionOut = "colorBg(\'" + menuID + "Item" + this.itemCounter + "\', \'" + bgColorNorm + "\');";
	}
	else if (isNS4)
	{
		layerFunctionOver = "switchLayer(\'" + menuID + "\', \'" + menuID + "Item" + this.itemCounter + "\');";
		layerFunctionOut = "switchLayerBack(\'" + menuID + "\', \'" + menuID + "Item" + this.itemCounter + 
			"\');";
	}

	if (menuToShow != "")
	{
		var itemFunctions = "";
		if (isIE || isNS5)
		{
			itemFunctions = bgFunctionOut + markerFunctionOut + textColorFunctionOut + rollFunctionOut;
			bgFunctionOut = "";
			markerFunctionOut = "";
			rollFunctionOut = "";
			textColorFunctionOut = "";
		}
		else if (isNS4)
		{
			itemFunctions = layerFunctionOut;
			layerFunctionOut = "";
		}
		menuSystem.activeItems[menuSystem.activeItems.length] = new activeItem(menuID + "Item" + 
			this.itemCounter, menuID, itemFunctions);
	}

	if (isIE || isNS5)
	{
		if (isNS5 && orientation == "horizontal")
			btag = "td";

		if (showOption == "over" || menuToShow == "")
			navFunction = "nav(\'" + link + "\', \'" + target + "\');"
		else
			navFunction = "";

		this.code += '\t<' + btag + ' id="' + menuID + 'Item' + this.itemCounter + '" style="height:' + 
			height + 'px; width:' + width + 'px; ' + border + ' cursor:' + cursor + '; z-index:1001;" ' + 
			'onclick="' + navFunction + ' ' + showStringClick + '" onmouseover="' + showStringOver + ' ' + 
			bgFunctionOver + ' ' + textColorFunctionOver + ' ' +	markerFunctionOver + '" onmouseout="' + 
			bgFunctionOut + ' ' + textColorFunctionOut + ' ' + markerFunctionOut + '">\r';
		this.code += contentTable;
		this.code += '\t</' + btag + '>\r';
	}
	else if (isNS4)
	{
		var checkFunction;
		if (this.isMainMenu)
			checkFunction = "check(" + menuSystem.name + ")";
		else
			checkFunction = "";

		this.code += '\t<layer id="' + menuID + 'Item' + this.itemCounter + 'Norm" ' + sizeString + ' left="' 
			+ this.left + '" top="' + this.top + '" visibility="inherit" bgcolor="' + bgColorNorm + '" ' + 
			'onclick="' + showStringClick + '" onmouseover="' + showStringOver + ' ' + layerFunctionOver + 
			'" z-index="1001">\r';
		this.code += contentTableNorm;
		this.code += '\t</layer>\r';

		this.code += '\t<layer id="' + menuID + 'Item' + this.itemCounter + 'Over" ' + sizeString + ' left="' 
			+ this.left + '" top="' + this.top + '" visibility="hidden" bgcolor="' + bgColorOver + '" ' + 
			'onclick="' + showStringClick + '" onmouseover="' + showStringOver + '" onmouseout="' + 
			layerFunctionOut + ' ' + checkFunction + '" z-index="1001">\r';
		this.code += contentTableOver;
		this.code += '\t</layer>\r';

		this.script += '<script type="text/javascript">\r';
		this.script += 'function upHandler' + this.menuID + 'Item' + this.itemCounter + '(e)\r';
		this.script += '{\r';
		if (showOption == "click" && menuToShow != "")
			this.script += '\t' + showStringClick + '\r';
		else
			this.script += '\tnav(\'' + this.links[this.itemCounter] + '\', \'' + this.targets[this.itemCounter] 
				+ '\');\r';
		this.script += '}\r';
		this.script += 'document.layers.' + this.menuID + '.layers.' + this.menuID + 'Item' + this.itemCounter 
			+ 'Over.captureEvents(Event.MOUSEUP);\r';
		this.script += 'document.layers.' + this.menuID + '.layers.' + this.menuID + 'Item' + this.itemCounter 
			+ 'Over.onmouseup = upHandler' + this.menuID + 'Item' + this.itemCounter + ';\r';
		this.script += '</script>\r';
	}

	if (orientation == "horizontal")
		this.left += width + ((borderedItems) ? borderSize : 0);
	else
		this.top += height + ((borderedItems) ? borderSize : 0);

	if (this.itemCounter != numOfItems - 1)
		this.itemCounter++;
	else
		this.compile();
}

function compile()
{
	var vis = (this.isMainMenu) ? "visible" : "hidden";

	if (!this.borderedItems)
	{
		if (this.orientation == "horizontal")
			this.left += this.borderSize;
		else
			this.top += this.borderSize;
	}

	if (isIE || isNS5)
	{
		var positionString;
		if (this.isMainMenu)
			positionString = "position:absolute; left:" + this.menuSystem.mainLeft + "px; top:" + 
				this.menuSystem.mainTop + "px;";
		else
			positionString = "position:absolute; left:0px; top:0px;";

		var sizeString;
		if (this.orientation == "horizontal")
			sizeString = "height:" + this.size + "px; width:" + this.left + "px;";
		else
			sizeString = "width:" + this.size + "px;";

		this.beg = '<div id="' + this.menuID + '" style="' + sizeString + ' ' + positionString + 
			' visibility:' + vis + '; background-color:' + this.bgColorNorm + '; border:' + this.borderSize + 
			'px ' + this.borderStyle + ' ' + this.borderColor + '; z-index:1000;" onmouseover="keepOpen()" ' + 
			'onmouseout="check(' + this.menuSystem.name + ')">\r';
		if (isNS5 && this.orientation == "horizontal")
		{
			this.beg += '<table cellpadding="0" cellspacing="0" height="' + this.size + '" width="' + 
				this.left + '">\r<tr>\r';
			this.end = '</tr>\r</table>\r</div>';
		}
		else
			this.end = '</div>\r';
	}
	else if (isNS4)
	{
		var positionString;
		if (this.isMainMenu)
			positionString = ' left="' + this.menuSystem.mainLeft + '" top="' + this.menuSystem.mainTop + '"';
		else
			positionString = ' left="0" top="0"';
		
		var sizeString;
		if (this.orientation == "horizontal")
			sizeString = 'height="' + (this.size + this.borderSize*2) + '" width="' + this.left + '"';
		else
			sizeString = 'height="' + this.top + '" width="' + (this.size + this.borderSize*2) + '"';
	
		this.beg = '<layer id="' + this.menuID + '" ' + sizeString + positionString + ' visibility="' 
			+ vis + '" bgcolor="' + this.borderColor + '" onmouseover="keepOpen()" onmouseout="check(' + 
			this.menuSystem.name + ')" z-index="1000">\r';
		this.end = '</layer>\r';
	}

	this.menuSystem.code += this.beg;
	this.menuSystem.code += this.code;
	this.menuSystem.code += this.end;
	this.menuSystem.code += this.script;
	this.menuSystem.menus[this.menuSystem.menuCounter] = this.menuID;
	this.menuSystem.menuCounter++;
	if (this.menuSystem.menuCounter == this.menuSystem.numOfMenus)
		this.menuSystem.write();
}

function write()
{
	if (isIE || isNS4 || isNS5)
		document.write(this.code);
}