// 
// Copyright (c) 2002, ThoughtByDesign. All rights reserved.
// 
// This computer program is protected by copyright law and international treaties.
// Unauthorized reproduction or distribution of this program, or any portion of it,
// may result in severe civil and criminal penalties, and will be prosecuted to the
// maximum extent possible under the law.
// 
// Class: NavigationBar
// Author: Rob Allen
// Created: November 22, 2001
//
// Purpose: Provides a vertical navigation bar. Use this object with the NavigationElement object.
//



function NavigationBar(targetFrame) 
{
	this.elementList = new Array();
	this.activeElement = "";
	this.targetFrame = targetFrame;
	this.name = "bar"+NavigationBar.barList.length;
	NavigationBar.barList[this.name] = this;
} // NavigationBar()


NavigationBar.barList = new Array();


NavigationBar.prototype.add = function(navigationElement) {
	navigationElement.setHoverAction("NavigationBar.prototype.handleHover('"+this.name+"', '"+navigationElement.buttonID+"')");
	navigationElement.setUnhoverAction("NavigationBar.prototype.handleUnhover('"+this.name+"', '"+navigationElement.buttonID+"')");
	navigationElement.setClickAction("NavigationBar.prototype.handleClick('"+this.name+"', '"+navigationElement.buttonID+"')");
	navigationElement.setTarget(this.targetFrame);
	this.elementList[navigationElement.buttonID] = navigationElement;
} // NavigationBar.prototype.add()


NavigationBar.prototype.deselectAll = function() {
	for (var elem in this.elementList) {
		if (this.elementList[elem].isActive() == true) {
			document.images[this.elementList[elem].buttonID].src = this.elementList[elem].normalImage;
			this.elementList[elem].setActive(false);
		}
	}
} // NavigationBar.prototype.deselectAll()


NavigationBar.prototype.handleHover = function(barName, buttonID) {
	
	var navBar = NavigationBar.barList[barName];
	var element = navBar.elementList[buttonID];
	if (element != null) {
		element.hover();
	}
}


NavigationBar.prototype.handleUnhover = function(barName, buttonID) {
	var navBar = NavigationBar.barList[barName];
	var element = navBar.elementList[buttonID];
	if (element != null) {
		element.unhover();
	}
}


NavigationBar.prototype.handleClick = function(barName, buttonID) {
	var navBar = NavigationBar.barList[barName];
	navBar.selectActive(buttonID);
}


/* 
 * Change the active button to the indicated button
 * @param whichOne whichOne is the button id being actived.
 */
NavigationBar.prototype.selectActive = function(whichOne) {

	if (this.activeElement == "" || whichOne != this.activeElement) {
		if (this.activeElement != null && this.activeElement != "") {
			// shut off previously activated element.
			document.images[this.elementList[this.activeElement].buttonID].src = this.elementList[this.activeElement].normalImage;
			this.elementList[this.activeElement].setActive(false);
		}
		this.activeElement = whichOne;
		var elem = this.elementList[whichOne];
		if (elem != null) {
			document.images[elem.buttonID].src = elem.selectImage;
			elem.setActive(true);
		}
	}

} // NavigationBar.prototype.selectActive()


NavigationBar.prototype.getHTML = function() {
	html = "";
	html += "<div style='margin-right:5px; padding-right: 5px'>";
	for (var elem in this.elementList) {
		html += this.elementList[elem].getHTML()+"<br>";
	}
	html += "</div>";
	return html;
}


NavigationBar.prototype.toString = function() {
	return "[object NavigationBar]";
}

