// Scriptname: toolbar_object.js
//
// Author: Wolfgang Schröder
// Date  : 09.06.2001
// Copyright: free
//
// Usage/Description:
//
// constructor:
// myToolbar = new toolbar(string yourID, string activeButtonName);
//
// add Buttons:
// myToolbar.addButton(string buttonName,string url2inactiveButtonImage,string url2activeButtonImage,string url2mouseOverButtonImage)
//
// create html for one button:
// myToolbar.writeButton(string buttonName);
//
// create html for all buttons:
// myToolbar.writeToolbar();
//
// creates an object to preload all buttonimages and creates the neccessary html including
// events for mouseover/out and onclick. Each event calls TBaction() with the buttonname
// as a calling argument (string). Overwrite TBaction in your html-page and use the argument
// to call your custom-functions or execute any javascript.
// TBaction must return "true" to activate the onclick-image.



function TBbutton (s_buttonName,s_html) {
	this.name = s_buttonName;
	this.html = s_html;
}

function toolbar (s_id, s_buttonName) {
	this.id           = s_id;
	this.activeButton = s_buttonName;
	
	this.buttons      = new Array();

	this.addButton    = TBaddButton;
	this.writeButton  = TBwriteButton;
	this.writeToolbar = TBwriteToolbar;
	this.activateButton  = TBactivateButton;
	this.highlightButton = TBhighlightButton;
	this.normalizeButton = TBnormalizeButton;
	this.setButton       = TBsetButton;
	this.unsetButton     = TBunsetButton;
	this.action          = TBaction;
	
	eval("obj_" + this.id + " = this;");
}

function TBaddButton(s_buttonName,url_inactive,url_active,url_mouseOver) {
	eval( s_buttonName + "_inactive = new Image;");
	eval( s_buttonName + "_active = new Image;");
	eval( s_buttonName + "_mouseOver = new Image;");
	
	eval( s_buttonName + "_inactive.src = '"  + url_inactive + "';");
	eval( s_buttonName + "_active.src = '"    + url_active + "';");
	eval( s_buttonName + "_mouseOver.src = '" + url_mouseOver + "';");
	
	if (this.activeButton == s_buttonName) {
		var s_html = "<a href='#' onmouseover='obj_" + this.id + ".highlightButton(" + s_buttonName + ");' onmouseout='obj_" + this.id + ".normalizeButton(" + s_buttonName + ");' onclick='obj_" + this.id + ".activateButton(" + s_buttonName + ")'><img src='" + url_active + "' name='" + s_buttonName + "' alt='" + s_buttonName + "' border='0'></a>"
	} else {
		var s_html = "<a href='#' onmouseover='obj_" + this.id + ".highlightButton(" + s_buttonName + ");' onmouseout='obj_" + this.id + ".normalizeButton(" + s_buttonName + ");' onclick='obj_" + this.id + ".activateButton(" + s_buttonName + ")'><img src='" + url_inactive + "' name='" + s_buttonName + "' alt='" + s_buttonName + "' border='0'></a>"
	}
	this.buttons[s_buttonName] = new TBbutton(s_buttonName,s_html);
}

function TBwriteToolbar() {
	for (s_buttoname in this.buttons) {
		document.write(this.buttons[s_buttoname].html);
	}
}

function TBwriteButton(s_buttoname) {
	document.write(this.buttons[s_buttoname].html);
}

function TBhighlightButton(obj_button) {
	if (obj_button.name != this.activeButton)
		eval("document.images." + obj_button.name + ".src = " + obj_button.name + "_mouseOver.src;");
}

function TBnormalizeButton(obj_button) {
	if (obj_button.name != this.activeButton)
		eval("document.images." + obj_button.name + ".src = " + obj_button.name + "_inactive.src;");
}

function TBactivateButton(obj_button) {
	if (obj_button.name != this.activeButton) {
		if (!this.action(obj_button.name)) return;
		eval("document.images." + obj_button.name + ".src = " + obj_button.name + "_active.src;");
		if (this.activeButton != "")
			eval("document.images." + this.activeButton + ".src = " + this.activeButton + "_inactive.src;");
		this.activeButton = obj_button.name;
	}
}

function TBsetButton(obj_button) {
	if (obj_button.name != this.activeButton) {
		eval("document.images." + obj_button.name + ".src = " + obj_button.name + "_active.src;");
		eval("document.images." + this.activeButton + ".src = " + this.activeButton + "_inactive.src;");
		this.activeButton = obj_button.name;
	}
}

function TBunsetButton() {
	if (this.activeButton != "") {
		eval("document.images." + this.activeButton + ".src = " + this.activeButton + "_inactive.src;");
		this.activeButton = "";
	}
}

function TBaction(s_buttoname) {
	return true;
}

