// custom objects, etc. to make menus on the fly
var menuLevel = 0;

function MenuItem(name, url, isMainMenuItem, classNameCss, hasSubmenu, submenuId, submenuLevel) {
	
	this.name = name
	this.url = url
	this.mainMenuItem = isMainMenuItem
	this.className = classNameCss
	this.hasSub = hasSubmenu
	if (hasSubmenu) {
		this.submenuId = submenuId
		this.submenuLevel = submenuLevel
	}
	else
	
		if(!hasSubmenu && isMainMenuItem)
		{
			this.submenuLevel = 0

		}
		
		
}

function AddMenuItem(item) {
	this.items[this.items.length] = item
}
function AddMenu(menu) {
	this.menus[this.menus.length] = menu
}

function MainMenu(x, y, width, type, fgColor, bgColorHi, fgColorHi, borderSize,
				  borderColor, cellpadding, cellAlign, font, fontSize, fontStyle, fontWeight,
				  arrowUrl) {
	this.left = x
	this.top = y
	this.width = width
	this.type = type						// down or out
	//this.bgColor = bgColor
	this.fgColor = fgColor
	this.bgColorHi = bgColorHi
	this.fgColorHi = fgColorHi
	this.border = borderSize
	this.borderColor = borderColor
	this.padding = cellpadding
	this.align = cellAlign
	this.font = font
	this.fontSize = fontSize
	this.fontStyle = fontStyle				// plain, italics
	this.fontWeight = fontWeight			// normal, bold
	this.arrow = arrowUrl
	this.items = new Array()
	this.menus = new Array()
	
	this.addItem = AddMenuItem
	this.addMenu = AddMenu
	this.create = CreateMainMenu
	this.createSS = CreateStylesheet
	this.createSubmenus = CreateSubmenus
}

function Menu(id, menuClass,subMenuLevel, x, y) {
	this.id = id
	this.className = menuClass
	this.left = x
	this.top = y
	this.menuLevel = parseInt(subMenuLevel) + 1
	this.items = new Array()
	
	this.addItem = AddMenuItem
}



function CreateStylesheet() {
	document.writeln("<style type=\"text/css\"><!--")
	
	document.write(".leftNavigation { ",
		       "width: 188px; ",
		       "border: 0px solid; ",
		       "float: left; ",
		       "height: 90%; ",
		       "position: relative; ",
		       "z-index: 3}")
	
	document.write("div.leftNavList, .leftNavList { ",
		       "margin: 0em 0 0.0em 0; ",
		       "list-style-type: none; ",
		       "background-color: none; ", 
		       "border-top: 0.01mm solid #fdfdfd; ",
		       "border-bottom: 0.01mm solid #c1c1c1; ",
		       "width: 182px;}" )

	document.write("div.leftNavList a, .leftNavList td a { ",
		       "text-decoration: none; ",
		       "color: #333; ",
		       "padding: .4em 0 .4em .7em; ",
		       "display: block;}")
	
	document.write("div.leftNavList a:hover, .leftNavList td a:hover { ",
		       "background-color: #c1c1c1;}")

	document.write(".leftNavSectionTitle { ", 
		       "background:url(/images/imgLeftNavTop.gif); ", 
		       "background-repeat: no-repeat; ",
		       "color: #fff; ",
		       "font-size: 95%; ",
		       "font-weight: bold; ",
		       "height: 21px; ",
		       "border: 0px solid #000; ",
		       "padding: 0px 0px 0px 10px; ",
		       "margin-left:0px; ",
		       "width: 188px;} ")

	document.write(".leftNavSectionTitle a:active, .leftNavSectionTitle a:link, .leftNavSectionTitle a:visited { ",
		       "color:#FFFFFF; ",
		       "text-decoration:none; ",
			   "font-size: 11px; ",
			   "} ")
	
	document.write("div td{ ",
		       "font-family: Arial, Helvetica, sans-serif; ", 
		       "font-size: 12px; ",
		       "color: #000000;}")
	
	/*--SubMenus for left navigation --*/
	document.write("div.subLeftNavList, .subLeftNavList {",
		       "font-family:Arial, Helvetica, sans-serif; ",
		       "font-size:11px; ",
		       "color:#000000; ",
		       "margin: 0em 0 0.5em 0; ",
		       "padding: 0 6px 0 0; ",
		       "list-style-type: none; ",
		       "background-color: #cccccc; ",
		       "border-top: 1px solid #c1c1c1; ",
		       "border-bottom: 1px solid #c1c1c1; ",
		       "border-right: 1px solid #c1c1c1; ",
		       "width: 275px;}")

	document.write("div.subMenuItem  a, .subMenuItem a { ",
		       "text-decoration: none; ",
		       "color: #333; ",
		       "display: block; ",
		       "height: 100%; ",
		       "font-size: 11px; }")

	document.write("div.subMenuItem { ",
		       "color: #333; ",
		       "padding: .4em 0 .4em .7em; ",
		       "font-size: 11px; ",
		       "font-weight: bold; ", 
		       "border-bottom: 1px solid #fdfdfd; ",
		       "background-color: #ccc; ", 
		       "width: 275px; ",
		       "height:23px;}")

	document.write("div.subMenuItem a:hover, .subMenuItem a:hover { ",
		       "background-color: #c1c1c1; ",
		       "display: block;}")
		
	document.writeln("-->")
	document.writeln("</style>")
}

function CreateMainMenu(type) {
	
	
	document.write("<table width= \"", this.width, "\" ",
		"border=\"", this.border, "\" ",
		"cellpadding= \"", this.padding, "\" ",
		"bordercolor= \"", this.borderColor, "\" ",
		"style= \"position: absolute; left: ", this.left, "px; top: ", this.top, "px;\">")
	
	//alert("<table width= " + this.width +  "\" border= " + this.border + " cellpadding= " + this.padding + " bordercolor= \"" + this.borderColor + " \" style=\"position: absolute; left: " + this.left + "px; top: " + this.top + "px;\">")
	
	switch (this.type) {
	case "down":
		document.write("<tr align=", this.align, "\"", ">")
		for(i=0; i<this.items.length; i++) {
			document.write("<td class=\"", this.items[i].className, "\"", "width=", 
			Math.round(this.width/this.items.length),
			"><a href=\"", this.items[i].url, "\"")
			if(this.items[i].hasSub) {
				document.write(" onMouseOver=\"pullDown(\'", 
					this.items[i].submenuId, "\', ", 
					this.items[i].submenuLevel, ")\"")
			}//End of if statement
			if (this.items[i].hasSub)
			{
				document.write(" onMouseOut=\"startTimer(", this.items[i].hasSub,", ", this.items[i].mainMenuItem, 
							", ", this.items[i].submenuLevel, ")\">", this.items[i].name, "</a></td>")
			}
			else
			{
				document.write(" onMouseOver =\"startTimer(", this.items[i].hasSub, ", ", this.items[i].mainMenuItem,
							", ", this.items[i].submenuLevel, ")\">", this.items[i].name, "</a></td>")
			}//End of if statement
		}//End of for loop
		document.write("</tr>")
		break
	case "out":
		
		for(i=0; i<this.items.length; i++) {
			//alert(this.items[i].className + " " +this.items[i].hasSub )
			document.write("<tr align=\"", this.align, "\"", "valign= top", ">")
			document.write("<td><div class=\"", this.items[i].className, "\"", ">",
						   "<table width='100%' cellspacing=0 cellpadding=0>",
						   "<tr><td width='90%'><a href=\"", this.items[i].url, "\"")
			//alert(this.items[i].className + " " +this.items[i].hasSub )
			
			if(this.items[i].hasSub) {
				document.write(" onMouseover=\"pullDown(\'", 
					this.items[i].submenuId, "\', ", 
					this.items[i].submenuLevel, ")\"")
				
			}
			
			if (this.items[i].hasSub)
			{
				//alert("What is CSS class:" + this.items[i].className + " " + "hasSubMenu is true: " + this.items[i].hasSub )
				document.write(" onMouseOut=\"startTimer(", this.items[i].hasSub, ", ", this.items[i].mainMenuItem,
							", ", this.items[i].submenuLevel, ")\">", this.items[i].name, "</a>")
			}
			else
			{
				//alert("What is CSS class:" + this.items[i].className + " " + "hasSubMenu is false: " + this.items[i].hasSub )
				document.write(" onMouseOver =\"startTimer(", this.items[i].hasSub, ", ", this.items[i].mainMenuItem,
							", ", this.items[i].submenuLevel, ")\">", this.items[i].name, "</a>")
			}//End of if statement
			
			if(this.items[i].hasSub) {
				document.write("<td align='right'><img src=\"", this.arrow, "\" ",
				"alt=\"&gt;\" align=\"bottom\" border=\"0\">&nbsp;&nbsp;")
			}//End of if Statement
			document.write("</a></table></div></td></tr>")
		}//End of of outer for loop
		break
	}//End of outer for loop	
	document.write("</table>")
}//End of switch statement



function CreateSubmenus() {

	
	for(i=0; i<this.menus.length; i++) {
		document.write("<div id=\"", this.menus[i].id, "\"",
			"class=\"", this.menus[i].className, "\"",
			"\" style=\"position: absolute; left: ",
			this.menus[i].left, "px; top: ", this.menus[i].top,
			"px; visibility: hidden;\">")
		//alert(this.menus[i].className)
		for(j=0; j<this.menus[i].items.length; j++) {
			document.write("<div id=\"subMenuItem\"", 
			"class=\"", this.menus[i].items[j].className, "\"", ">")
			document.write("<table width='100%' cellspacing=0 cellpadding=0><tr><td width='90%'><a href=\"", this.menus[i].items[j].url,
				"\"")
			if(this.menus[i].items[j].hasSub) {
				document.write(" onMouseover=\"pullDown(\'", 
					this.menus[i].items[j].submenuId, "\', ", 
					this.menus[i].items[j].submenuLevel, ")\"")
			}//End of if statement	
			
			if (this.menus[i].items[j].hasSub)
			{
				document.write(" onMouseOut=\"startTimer(", this.menus[i].items[j].hasSub, ", ", 
							this.menus[i].items[j].mainMenuItem, ", ", this.menus[i].items[j].submenuLevel, 
							")\">", this.menus[i].items[j].name, "</a>")
			}
			else if (!this.menus[i].items[j].hasSub && !this.menus[i].items[j].mainMenuItem)
			{
				
				//alert( "hasSub is false and mainMenu is false" + this.menus[i].items[j].name + " " + previousElement )
				/*alert(" onMouseOver=\"hide(\'" + previousElement + "\')\">" +
								this.menus[i].items[j].name + "</a>")*/
				document.write(" onMouseOver=\"hideSub(\'", this.menus[i].menuLevel, "\')\">",
								this.menus[i].items[j].name, "</a>")
			}
			else
			{
				document.write(" onMouseOver=\"startTimer(", this.menus[i].items[j].hasSub, ", ", 
							this.menus[i].items[j].mainMenuItem, ", ", this.menus[i].items[j].submenuLevel, 
							")\">", this.menus[i].items[j].name, "</a>")	
				
			}//End of if statement
			 cssClassItem = this.menus[i].items[j].cssMainItem
			
			if(this.menus[i].items[j].hasSub) {
				document.write("<td align='right'><img src=\"", this.arrow, "\" ",
				"alt=\"&gt;\" align=\"bottom\" border=\"0\">&nbsp;&nbsp;")
			}//End of if statement
			document.write("</table><br /></div>")
		}//End of for loop
		document.write("</div>")
	}//End of outer for loop
}//End of CreateSubmenus function
