ljex.Button = function(args){
	var thisObj = this;
	$assimilate.call(this, args);

	var defaults = {
		id: 'lx-btn#'+$genid(),
		scope: this
	};

	$setdef.call(this, defaults);

	this.el=null;
}

ljex.Button.prototype.render = function(){
	var thisObj=this;
	this.el = document.createElement("div");
	this.el.id = this.id;

	this.btnCt = document.createElement("table");
	this.btnCt.id=this.id+'-btnct';
	this.btnCt.cellPadding=0; this.btnCt.cellSpacing=0;
	var btnRow=this.btnCt.insertRow(0);

	var tbLeft = $create();
	tbLeft.className='lx-toolbar-button-left';
	var leftCell=btnRow.insertCell(0);
	leftCell.appendChild(tbLeft);

	var tbCenter = $create();
	tbCenter.className='lx-toolbar-button-center';

	var centerTbl = document.createElement("table");
	centerTbl.cellPadding=0; centerTbl.cellSpacing=0;
	var centerRow = centerTbl.insertRow(0);

	if(this.icon){
		var centerIconCell=centerRow.insertCell(0);

		var icon=document.createElement("img");
		icon.className="lx-toolbar-button-icon";
		icon.src=this.icon;
		
		centerIconCell.appendChild(icon);
	}

	if(this.text){
		var centerTextCell=centerRow.insertCell( (this.icon)?1:0 );

		var text=$create();
		text.className="lx-toolbar-button-text";
		if(this.icon) text.style.marginLeft='5px';

		text.innerHTML=this.text;
		text.style.whiteSpace="nowrap";
		centerTextCell.appendChild(text);
	}

	tbCenter.appendChild(centerTbl);

	if(this.tooltip){
		this.el.onmouseover = function(e){
			var ev = e || window.event;

			ljex.showToolTip(ev, thisObj.tooltip);
		}
	}

	var middleCell = btnRow.insertCell(1);
	middleCell.appendChild(tbCenter);


	var tbRight = $create();
	tbRight.className='lx-toolbar-button-right';
	var rightCell=btnRow.insertCell(2);
	rightCell.appendChild(tbRight);

	this.el.appendChild(this.btnCt);

/*
	if(this.menu){

		this.menuBtn = $create(this.id+'-menuct'); 
		this.menuBtn.className='lx-toolbar-button-menu'; 
	
		this.menuBtn.onclick = function(e){
			
			if($(this.id+'-button-menu')){
				document.body.removeChild($(this.id+'-button-menu'));
			}else{
				var men = new ljex.buttonMenu({
					id: this.id+'-button-menu',
					width: 80,

					items: thisObj.menu
				},e);	
			}
		}

		this.menuBtn.onmouseover = function() { this.style.backgroundPosition="0px -26px"; }

		this.menuBtn.onmouseout= function() { this.style.backgroundPosition="0px -0px"; }
		
		this.btnCt.style.cssFloat='left';
		this.menuBtn.style.cssFloat='right';
		var br=$create(); br.style.clear='both';
		this.el.appendChild(this.menuBtn);
		this.el.appendChild(br);
		
	}
*/

	this.btnCt.onmouseover = function(){
		var comp = this.getElementsByTagName("div");
		for(var i=0;i<comp.length;i++){
			comp[i].style.backgroundPosition="0px -26px";
		}
	}

	this.btnCt.onmouseout = function(){
		var comp = this.getElementsByTagName("div");
		for(var i=0;i<comp.length;i++){
			comp[i].style.backgroundPosition="0px 0px";
		}
	}

	if(this.enabled!=undefined && !this.enabled){
		this.btnCt.style.opacity='0.5';
	}else{
		this.btnCt.onclick = function(e){
			thisObj.onclick.call(thisObj.scope,e); 
		}
	}

	if(this.renderTo!=undefined){
		$(this.renderTo).appendChild(this.el);
	}else{
		return this.el;
	}
}

ljex.ToolBar = function(args){
	$assimilate.call(this, args);
	this.args = args;
}

ljex.ToolBar.prototype.render = function(){
	this.el = document.createElement("table");
	this.el.id = this.id;
	this.el.className="lx-toolbar";
	this.el.cellPadding=0; this.el.cellSpacing=0;

	with(this.el.style){
		if(this.width)
			width=(ljex.isIE())?this.width-2+'px':this.width+'px';
		else
			width='100%';

		backgroundColor=(this.args.bgColor!=undefined)?this.args.bgColor:'#ccc';
		if(this.args.border===false){
			borderWidth="0px";
			if(ljex.isIE()) width=(parseInt(width)+2)+'px';
		}
	}

	var row = this.el.insertRow(0);

	for(var i=0;i<this.items.length;i++){
		var btnEl = new ljex.Button(this.items[i]).render();
		btnEl.className="lx-toolbar-button-horizontal";
		
		var cell=row.insertCell(i);
		cell.appendChild(btnEl);
	}
	var dummyCell=row.insertCell(i);
	dummyCell.style.width="100%";

	if(this.args.renderTo!=undefined){
		$(this.args.renderTo).appendChild(this.el);
	}else{
		return this.el;
	}
}
