$package("js.ui");

js.ui.ToolBar = function (){

}
js.ui.ToolBar.prototype = new js.ui.Container();

js.ui.ToolBar.prototype.getNativeClass = function (){
	return "js.ui.ToolBar";
}

js.ui.ToolBar.prototype.bindUI = function (){
	this.container = this.ui.getElementsByTagName("tr")[0];
}

js.ui.ToolBar.prototype.add = function (button){
  var newCol = this.container.insertCell(this.container.cells.length-1);
  newCol.appendChild(button.getUI());
}

js.ui.ToolBar.prototype.addSeparator = function (){
  var sep = new js.ui.Img();
  sep.setSrc(imagePath + "toolbar/separator.gif");
  sep.ui.className = "ToolSeparator";
  this.add(sep);
}


js.ui.ToolButton = function (){
}

js.ui.ToolButton.prototype = new js.ui.Component();

js.ui.ToolButton.prototype.align = "hAlign"; //hAlign;vAlign;

js.ui.ToolButton.prototype.getNativeClass = function (){
	var id = "js.ui.ToolButton";
	return id;
}

js.ui.ToolButton.prototype.bindUI = function (){

	var tds = this.ui.getElementsByTagName("tr")[1].getElementsByTagName("td");
	this.iconCell = tds[1];
	this.textCell = tds[2];
	this.text = this.ui.getElementsByTagName("a")[0];
	this.rightCell = tds[3];

	var __this = this;
	this.ui.onmouseover = function(){
		if(__this.disabled) return;
		this.className = "ToolButton Panel Panel_selected";
	}
	this.ui.onmouseout = function(){
		this.className = "ToolButton Panel";
	}
}

js.ui.ToolButton.prototype.setText = function(text){
	if(!this.ui) this.getUI();
	this.text.innerHTML = text;						
}

js.ui.ToolButton.prototype.setIcon = function(url, w, h){
	if(!this.ui) this.getUI();
	if(!this.icon){
		this.icon = new js.ui.Img();
		if(this.align=="vAlign") {
			this.textCell.align = "center";
			this.textCell.insertBefore(this.icon.getUI(), this.text);
		}
		else{
			this.iconCell.appendChild(this.icon.getUI());
		}
	}
	this.icon.setSrc(url, w, h);
}
	
js.ui.ToolButton.prototype.setRightIcon = function(url, w, h){
	if(!this.ui) this.getUI();
	if(!this.rightIcon){
		this.rightIcon = new js.ui.Img();
		this.rightCell.appendChild(this.rightIcon.getUI());
	}
	this.rightIcon.setSrc(url, w, h);
}


js.ui.ToolButton.prototype.setEnabled = function (enabled){
  this.disabled=!enabled;
  if(enabled) {
    if(this.enableImage)
	  this.setIcon(this.enableImage);
	if(this.oldonclick)this.onclick=this.oldonclick;
	this.className = "Toolbar_disable";
  }
  else {
    if(this.disableImage) {
	  if(!this.enableImage)
		 this.enableImage=this.icon.getUI().src;
	  this.setIcon(this.disableImage);
	}
	if(this.onclick)this.oldonclick = this.onclick;
	this.onclick = null;
	this.className = "Toolbutton Panel";
  }
}

