// *****************************
// HTML Navigation Bar
// *****************************
// (c) 2006 Jason Christy - www.jchristy.com
// *****************************
// Global Variables
var navBarSpacerSrc; //this must be set to output html!
// Nav Bar Object
function navBarObj(iPAD, iSPACE, iWIDTH, iIHEIGHT, iINDENT, sISTYLE, sIOVER, sCOLOR) {
	this.padding = iPAD;
	this.spacing = iSPACE;
	this.width = iWIDTH;
	this.itemHeight = iIHEIGHT;
	this.itemIndent = iINDENT;
	this.itemStyle = sISTYLE;
	this.itemOverStyle = sIOVER;
	this.bgcolor = sCOLOR;
	this.navItem = new Array();
}
navBarObj.prototype.outputHTML = function() {
	if (!navBarSpacerSrc) { alert("Spacer SRC not set!\n\nnavBarSpacerSrc = null;"); }
	var bgcolor = (this.bgcolor) ? 'bgcolor="' + this.bgcolor + '"' : "";
	var html = '<table width="' + this.width + '" border="0" cellpadding="' + this.padding + '" cellspacing="' + this.spacing + '" ' + bgcolor + '>\n';
		for (var i = 0; i < this.navItem.length; i++) {
			html += this.navItem[i].outputHTML();	
		}
		html += '</table>\n';
		
	return html;
}
navBarObj.prototype.addNavItem = function(sLABEL, sURL, sTYPE, iHEIGHT, iINDENT, sSTYLE, sOVER, sCELLSTYLE, sALIGN, sVALIGN) {
	var width = this.width - (this.spacing * 2);
	var height = (iHEIGHT) ? iHEIGHT - (this.spacing * 2) : this.itemHeight - (this.spacing * 2);
	var indent = (iINDENT) ? iINDENT - this.spacing : this.itemIndent - this.spacing;
	var style = (sSTYLE) ? sSTYLE : this.itemStyle;
	var overStyle = (sOVER) ? sOVER : this.itemOverStyle;
	var type = (sTYPE) ? sTYPE : "URL";
	this.navItem[this.navItem.length] = new navItemObj(sLABEL, sURL, type, width, height, indent, style, overStyle, sCELLSTYLE, sALIGN, sVALIGN);
}
// Nav Item Object
function navItemObj(sLABEL, sURL, sTYPE, iWIDTH, iHEIGHT, iINDENT, sSTYLE, sOVER, sCELLSTYLE, sALIGN, sVALIGN) {
	this.label = sLABEL;
	this.url = sURL;
	this.type = sTYPE;
	this.width = iWIDTH;
	this.height = iHEIGHT;
	this.indent = iINDENT;
	this.style = sSTYLE;
	this.overStyle = sOVER;
	this.cellStyle = sCELLSTYLE;
	
	this.align = (sALIGN) ? sALIGN : "left";
	this.valign = (sVALIGN) ? sVALIGN : "middle";

	this.mouseOverCode = "";
	this.mouseOutCode = "";
}
navItemObj.prototype.addPopMenu = function(sMENUID) {
	//NOTE THIS FEATURE REQUIRES POP MENU
	this.mouseOverCode += 'closeAllMenus(); showPopMenu(\'' + sMENUID + '\');';
	this.mouseOutCode += ' hidePopMenu(\'' + sMENUID + '\');';
}
navItemObj.prototype.outputHTML = function() {
	var url;
	switch (this.type) {
		case "URL" :
			url = "window.location='" + this.url + "'";
			break;
		case "NEW" :
			url = "window.open('" + this.url + "')";
			break;
		case "SCRIPT" :
			url = this.url;
			break;
		default :
			alert("Unsupported URL type: " + this.type);
			break;
	}
	
	var mouseover = this.mouseOverCode + " this.style.cursor='pointer'; ";
	var mouseout = this.mouseOutCode + " this.style.cursor='default'; ";
	
	if (this.overStyle) { 
		mouseover += "this.className='" + this.overStyle + "'; ";
		mouseout += "this.className='" + this.style + "'; ";
	}
	
	var contentTable =  '<table width="' + this.width + '" cellpadding="0" cellspacing="0" border="0">\n';
		contentTable += '<tr>\n';
		contentTable += '<td width="' + (this.width - 1) + '" style="padding-' + this.align + ': ' + this.indent + 'px;" align="' + this.align + '" valign="' + this.valign + '">' + this.label + '</td>\n';
		contentTable += '<td width="1"><img src="' + navBarSpacerSrc + '" width="1" height="' + this.height + '" /></td>\n';
		contentTable += '</tr>\n';
		contentTable += '</table>\n';
	
	var rowstyle = (this.style) ? ' class="' + this.style + '"' : "";	
	var cellstyle = (this.cellStyle) ? ' class="' + this.cellStyle + '"' : "";
	
	var html =  '<tr' + rowstyle + ' onclick="' + url + '" onmouseover="' + mouseover + '" onmouseout="' + mouseout + '">\n';
		html += '<td' + cellstyle + '>' + contentTable + '</td>\n';
		html += '</tr>\n';
	return html;
}

