// ===============================================
// THE NavBar OBJECT
// ===============================================
	function NavBar(sContainer) {
		this.list = new Array();
		this.container = $("#" + sContainer);
		this.mainCount = 0;
		this.subCount  = 0;
	}
	
	NavBar.prototype.addMain = function(sCaption, sPage) {
		this.mainCount++;
		this.subCount = 0;
		this.list.push(new NavItem(sCaption, sPage, this.mainCount, this.subCount));
	}
	
	NavBar.prototype.addSub = function(sCaption, sPage) {
		this.subCount++;
		this.list.push(new NavItem(sCaption, sPage, this.mainCount, this.subCount));
	}
	
	NavBar.prototype.draw = function(main, sub) {
		var sHeader = "<table cellspacing='0' cellpadding='0' border='0'>"
		var sFooter = "</table>"
		var sBody   = "";
		for (var a=0;a<this.list.length;a++) {
			sBody += this.list[a].draw(main, sub, a);
		}
		this.container.html(sHeader + sBody + sFooter);
	}

	
// ===============================================
// THE NavItem OBJECT
// ===============================================
	function NavItem(sCaption, sPage, sMain, sSub) {
		this.caption = sCaption;
		this.page    = sPage;
		this.main    = sMain;
		this.sub     = sSub;
	}
	
	NavItem.prototype.draw = function(sMain, sSub, iIndex) {
		var sHeader = ""
		if (this.sub == 0) {
			if (iIndex > 0) sHeader = "<tr height='6px'><td></td></tr>";
			return sHeader + this.drawMain(sMain)
		}
		else {
			if (this.main == sMain) return this.drawSub(sMain, sSub)
		}
		return "";
	}
	
	NavItem.prototype.drawMain = function(sMain) {
		var sClass = "menuItem";
		var sReturn;
		if (this.main == sMain) {
			sReturn = [
				"<tr>",
					"<td class='menuItemSelected' onmouseup=\"goNavItem('" + this.page + "', " + this.main + ", " + this.sub + ")\" nowrap>",
						this.caption,
					"</td>",
				"</tr>"
			];
		}
		else {
			sReturn = [
				"<tr onmouseover=\"setBGColor(this, '#caf1ff')\" onmouseout=\"setBGColor(this, '')\">",
					"<td class='menuItem' onmouseup=\"goNavItem('" + this.page + "', " + this.main + ", " + this.sub + ")\" nowrap>",
						this.caption,
					"</td>",
				"</tr>"
			];
		}
		return sReturn.join("");
	}

	NavItem.prototype.drawSub = function(sMain, sSub) {
		var sClass = "subItem";
		var sReturn;
		if (this.sub == sSub) {
			sReturn = [
				"<tr>",
					"<td class='subItemSelected' onmouseup=\"goNavItem('" + this.page + "', " + this.main + ", " + this.sub + ")\" nowrap>",
						this.caption,
					"</td>",
				"</tr>"
			];
		}
		else {
			sReturn = [
				"<tr onmouseover=\"setBGColor(this, '#caf1ff')\" onmouseout=\"setBGColor(this, '')\">",
					"<td class='subItem' onmouseup=\"goNavItem('" + this.page + "', " + this.main + ", " + this.sub + ")\" nowrap>",
						this.caption,
					"</td>",
				"</tr>"
			];
		}
		return sReturn.join("");
	}




// ===============================================
// HOME PAGE BUTTONS
// ===============================================

function homeButton(sBase, sTarget, x, y) {
	var oBuffer = [
		"<img class='buttonimg' src='images/buttons/" + sBase + "-0.png'",
		" onmouseover=\"setImage(this, '" + sBase + "-1.png')\"",
		" onmouseout=\"setImage(this, '" + sBase + "-0.png')\"",
		" style='position:absolute;top:" + y + "px;left:" + x + "px;cursor:pointer;'",
		" onmouseup=\"goPage('" + sTarget + "')\"",
		">" 
	]
	return oBuffer.join("");
}
	



function navButton(sBase, sTarget, x, y) {
	var oBuffer = [
		"<img class='buttonimg' src='images/buttons/" + sBase + "S-0.png'",
		" onmouseover=\"setImage(this, '" + sBase + "S-1.png')\"",
		" onmouseout=\"setImage(this, '" + sBase + "S-0.png')\"",
		" style='position:absolute;top:" + y + "px;left:" + x + "px;cursor:pointer;'",
		" onmouseup=\"goPage('" + sTarget + "')\"",
		">" 
	]
	return oBuffer.join("");
}



// ===============================================
// SUPPORTING FUNCTIONS
// ===============================================

	function setImage(obj, sImage) {
		obj.src = "images/buttons/" + sImage;
	}
	
	function setBGColor(obj, sColor) {
		obj.style.backgroundColor = sColor;
	}
	
	function goPage(sPage) {
		self.location = sPage;
	}
	
	function goNavItem(sPage, sMain, sSub) {
		self.location = sPage + "?main=" + sMain + "&sub=" + sSub; 
	}

