/*
	Programador .......: Marcelo Salton Disconzi
	Empresa ...........: Dataview Soluções Tecnológicas
	Data de criação ...: 11/05/2009
	Ultima Alteração ..: 15/03/2009
	Classe de Arquivo .: Componente
	Classes necessárias: Util
	Projeto ...........: Reformulação do modelo de Intranets, DVFrameWork 2.0
	Funcionalidades....: 
	
	Future Features ...: colocar botão sem fundo igual ao yahoomail, posteriormente adicionar botões com submenus se for o caso
*/

document.write("<link rel = 'stylesheet' type = 'text/css' href = 'source/script/components/DVButton/DVButton.css' />");
function DVButton(obj,str)
{	
	this.obj = obj;
	this.str = str;
	this.style = 0;//default
	arguments[0] = this;
	this.itens = {left:null,iconbg:null,icon:null,str:null,right:null};
	this.listeners = [];
	//----------------------------------------------------------------------------------------------
	this.constructor = function()
	{
		this.obj.className='DVButton';
		this.obj.innerHTML = "<b class = 'bleft'></b><b class = 'biconbg'></b><b class = 'bicon'></b><b class = 'bstr'>"+this.str+"</b><b class = 'bright'></b>";
		var itens = this.obj.getElementsByTagName('b');
		this.itens = {left:itens[0],iconbg:itens[1],icon:itens[2],str:itens[3],right:itens[4]};
		
		switch(arguments[0].length)
		{
			case 3:
				this.setIcon(arguments[0][2]);
				break;
			case 4:
				this.setIcon(arguments[0][2]);
				this.setStyle(arguments[0][3]);
				break;
			default:
		}
		
		//84 é o tamanho dos segmentos
		util.addEvent(this.obj,"mouseover",function()
		{
			obj.itens.str.style.backgroundPosition='left -'+((obj.style*84)+63)+'px';
			obj.itens.iconbg.style.backgroundPosition='left -'+((obj.style*84)+63)+'px';
			obj.itens.left.style.backgroundPosition='left -'+((obj.style*84)+21)+'px';
			obj.itens.right.style.backgroundPosition='right -'+((obj.style*84)+21)+'px';
			obj.itens.icon.className = 'bicon_hover';
			obj.itens.iconbg.className = 'biconbg_hover';
			obj.itens.str.className = 'bstr_hover';
		},"effecthover",this);
		
		util.addEvent(this.obj,"mouseout",function()
		{
			obj.itens.str.style.backgroundPosition='left -'+((obj.style*84)+42)+'px';
			obj.itens.iconbg.style.backgroundPosition='left -'+((obj.style*84)+42)+'px';
			obj.itens.left.style.backgroundPosition='left -'+((obj.style*84))+'px';
			obj.itens.right.style.backgroundPosition='right -'+((obj.style*84))+'px';
			obj.itens.str.className = 'bstr';
			obj.itens.icon.className = 'bicon';
			obj.itens.iconbg.className = 'biconbg';
		},"effectout",this);
	}
	//----------------------------------------------------------------------------------------------
	this.alignTo = function(side)
	{
		try
		{
			this.obj.style.cssFloat=side;
			this.obj.style.styleFloat=side;
		}
		catch(err){}
	}
	//----------------------------------------------------------------------------------------------
	this.setTitle = function(str)
	{
		this.obj.title = str;
	}
	//----------------------------------------------------------------------------------------------
	this.setValue = function(str)
	{
		this.itens.str.firstChild.nodeValue = str;
	}
	//----------------------------------------------------------------------------------------------
	this.setIcon = function(pos)
	{
		this.itens.icon.style.display='inline';
		this.itens.icon.style.backgroundPosition = '-'+(pos[0]*16)+'px -'+(pos[1]*16)+'px';
	}
	
	this.setStyle = function(pos)
	{
		this.style = pos;
		
		this.itens.str.style.backgroundPosition='left -'+((this.style*84)+42)+'px';
		this.itens.iconbg.style.backgroundPosition='left -'+((this.style*84)+42)+'px';
		this.itens.left.style.backgroundPosition='left -'+((this.style*84))+'px';
		this.itens.right.style.backgroundPosition='right -'+((this.style*84))+'px';
		this.itens.str.className = 'bstr';
		this.itens.icon.className = 'bicon';
		this.itens.iconbg.className = 'biconbg';
	}

	this.showIcon = function(bool)
	{
		if(!bool)
		{
			this.itens.icon.style.display='none';
			this.itens.iconbg.style.display='none';
		}
		else
		{
			this.itens.icon.style.display='inline';
			this.itens.iconbg.style.display='inline';
		}
	}
	
	//Simula Construtores
	//----------------------------------------------------------------------------------------------
	this.constructor(arguments);
}	
