/*	Pull-down Menu Library
	Author: Tina McDuffie
	Copyright 2003 Tina McDuffie.  All rights reserved. 
	
	Description: this library contains the custom objects, 
	etc. to make menus on the fly.
	The functions that provide pull-down menu functionality
	can be found in the pullDownMenuLib.js file.            */

function MenuItem(name, url, hasSubmenu, submenuId, submenuLevel, numNbsps) {
	this.name = name
	this.url = url
	this.hasSub = hasSubmenu
	if (hasSubmenu) {
		this.submenuId = submenuId
		this.submenuLevel = submenuLevel
		this.nbsps = numNbsps 
	}
}

function AddMenuItem(item) {
	this.items[this.items.length] = item
}
function AddMenu(menu) {
	this.menus[this.menus.length] = menu
}

function MainMenu(x, y, width, type, bgColor, 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, x, y) {
	this.id = id
	this.left = x
	this.top = y
	this.items = new Array()
	
	this.addItem = AddMenuItem
}

function CreateStylesheet() {
	document.writeln("<style type=\"text/css\"><!--")
	document.write("div.menu { padding-left: 10px; ",
		"padding-right: 2px; padding-top: 4px; ",
		"padding-bottom: 4px; background-color: ",
		this.bgColor, "; border: ", this.borderColor, ";}")
	document.write(".menu a:link, .menu a:visited, .menu a:active, .menu a:hover { ",
		"text-decoration: none; font-size: ", this.fontSize,
		"; font-style: ", this.fontStyle, "; font-weight: ",
		this.fontWeight, "; font-family: ", this.font, ";}")
	document.write(".menu a:link, .menu a:visited { ", 
		"background-color: ", this.bgColor, 
		"; color: ", this.fgColor, ";}")
	document.write(".menu a:hover, .menu a:active { ", 
		"background-color: ", this.bgColorHi, 
		"; color: ", this.fgColorHi, ";}")
	document.writeln("-->")
	document.writeln("</style>")
}

function CreateMainMenu(type) {
	document.write("<table class=menu width=", this.width, " bgColor=\"",
		this.bgColor, "\" 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 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, ")\"")
			}
			document.write(" onMouseOut=\"startTimer()\">", 
				this.items[i].name, "</a></td>")
		}
		document.write("</tr>")
		break
	case "out":
		for(i=0; i<this.items.length; i++) {
			document.write("<tr align=", this.align, ">")
			document.write("<td><a href=\"", this.items[i].url, "\"")
			if(this.items[i].hasSub) {
				document.write(" onMouseover=\"pullDown(\'", 
					this.items[i].submenuId, "\', ", 
					this.items[i].submenuLevel, ")\"")
			}
			document.write(" onMouseOut=\"startTimer()\">", 
				this.items[i].name, "</a>")
			if(this.items[i].hasSub) {
				for(j=0; j<this.items[i].nbsps; j++) {
					document.write("&nbsp;")
				}
				document.write("<img src=\"", this.arrow, "\" ",
				"alt=\"&gt;\" align=bottom>")
			}
			document.write("</td></tr>")
		}
		break
	}	
	document.write("</table>")
}

function CreateSubmenus() {
	for(i=0; i<this.menus.length; i++) {
		document.write("<div class=menu id=\"", this.menus[i].id, 
			"\" style=\"position: absolute; left: ",
			this.menus[i].left, "px; top: ", this.menus[i].top,
			"px; visibility: hidden;\">")
		for(j=0; j<this.menus[i].items.length; j++) {
			document.write("<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, ")\"")
			}	
			document.write(" onMouseOut=\"startTimer()\">", 
				this.menus[i].items[j].name, "</a>")
			if(this.menus[i].items[j].hasSub) {
				for(k=0; k<this.menus[i].items[j].nbsps; k++) {
					document.write("&nbsp;")
				}
				document.write("<img src=\"", this.arrow, "\" ",
				"alt=\"&gt;\" align=bottom>")
			}
			document.write("<br>")
		}
		document.write("</div>")
	}
}
