/***********************************************************
 * Author Chris Hobden <chris@impera.co.uk>                *
 * Copyright (c) Oshun Ltd, 2003-2005. All rights reserved.*
 * See http://www.imperal.co.uk/licence/                   *
 ***********************************************************/

function isisToolBar(buttons, callback_func, isisjslib_root){
	this.buttons=buttons;
	this.root=isisjslib_root;
	this.callback_func=callback_func;
	this.buttonList={};
	this.createToolBar();
}
isisToolBar.prototype.getBar = function(){
	return this.bar;
}
isisToolBar.prototype.createToolBar = function(){
	this.bar = document.createElement("div");
	this.bar.style.height='26px';
	this.bar.className='isisToolBar';
	var table = document.createElement("table");
	table.height = "26px";
	table.border = "0px";
	table.cellSpacing = "0px";
	table.cellPadding = "0px";
	this.bar.appendChild(table);
	table.appendChild(document.createElement("tbody"));
	tr = table.insertRow(-1);
	tr.style.height="26px";
	for(var i = 0; i < this.buttons.length; i++){
		tr.appendChild(this.createButton(this.buttons[i]));
	}
};
isisToolBar.prototype.setWidth = function(width){
	this.bar.style.width=parseInt(width);
};

isisToolBar.prototype.createButton = function(button){
	var toolbar = this;
	var td=document.createElement("td");
	var btnDiv=document.createElement("div");
	btnDiv.style.className='isisButton';
	var btn={div: btnDiv,enabled: true,active: false};
	this.buttonList[button[1]]=btn;
	switch(button[0]){
		case "button":
		var img=document.createElement("img");
		img.src=this.root+button[3];
		img.title=button[2];
		img.alt=button[2];
		img.style.zIndex=5;
		isisAddEventHandler(btnDiv, "click", function(e){toolbar.callback_func(e, button[1]);});
		isisAddEventHandler(btnDiv, "mouseover", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]], "over");});
		isisAddEventHandler(btnDiv, "mouseout", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]]);});
		isisAddEventHandler(btnDiv, "mousedown", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]], "pressed");});
		isisAddEventHandler(btnDiv, "mouseup", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]]);});
		btnDiv.appendChild(img);
		break;
		case "devider":
		btnDiv.className='isisDevider';
		break;
		case "text_button":
		isisAddEventHandler(btnDiv, "click", function(e){toolbar.callback_func(e, button[1]);});
		isisAddEventHandler(btnDiv, "mouseover", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]], "over");});
		isisAddEventHandler(btnDiv, "mouseout", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]]);});
		isisAddEventHandler(btnDiv, "mousedown", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]], "pressed");});
		isisAddEventHandler(btnDiv, "mouseup", function(e){toolbar.setButtonClass(toolbar.buttonList[button[1]]);});
		btnDiv.innerHTML=button[2];		
		break;
	}
	this.setButtonClass(toolbar.buttonList[button[1]]);
	td.appendChild(btnDiv);
	return td;
};
isisToolBar.prototype.setButtonClass = function(btn, status){
	if(btn.enabled&&btn.active!=true){
		switch(status){
			case "over":
			btn.div.className="isisButtonOver";
			break;
			case "pressed":
			btn.div.className="isisButtonPressed";
			break;
			default:
			btn.div.className="isisButton";
			break;
		}
	}
};