function Button(){
	
	this.Id;
	
	this.Text;
	this.Link;
	this.Width;
	this.Height;
	
	this.Container;
	this.htmlDiv;
	
	this.htmlBrdLeft;
	this.htmlBrdRight;
	this.htmlFnd;
	this.htmlText;
	this.htmlEventos;
	
	this.cssText;
	this.cssTextOver;
	this.cssTextPress;
	
	this.cssBrdLeft;
	this.cssBrdLeftOver;
	this.cssBrdLeftPress;
	
	this.cssBrdRight;
	this.cssBrdRightOver;
	this.cssBrdRightPress;
	
	this.cssFnd;
	this.cssFndOver;
	this.cssFndPress;
	
	this.BorderWidth = 5;
	
	this.PonerEventos = function(){
	
		this.htmlEventos.mover(function(me){
			
			var Boton = ButtonsManager.Buttons.GetObjectById(me.getAttribute('BotonId'));
			
			if(Boton.cssBrdLeftOver){
				Boton.htmlBrdLeft.cssClass(Boton.cssBrdLeftOver);
			}else{
				Boton.htmlBrdLeft.cssClass('btn_brd_left_hover');
			}
			
			if(Boton.cssBrdRightOver){
				Boton.htmlBrdRight.cssClass(Boton.cssBrdRightOver);
			}else{
				Boton.htmlBrdRight.cssClass('btn_brd_right_hover');
			}
			
			if(Boton.cssFndOver){
				Boton.htmlFnd.cssClass(Boton.cssFndOver);
			}else{
				Boton.htmlFnd.cssClass('btn_fnd_hover');
			}
			
			if(Boton.cssTextOver){
				Boton.htmlText.cssClass(Boton.cssTextOver);
			}else{
				Boton.htmlText.cssClass('btn_text_hover');
			}
			
		});
		
		this.htmlEventos.mout(function(me){
			
			var Boton = ButtonsManager.Buttons.GetObjectById(me.getAttribute('BotonId'));
			
			if(Boton.cssBrdLeft){
				Boton.htmlBrdLeft.cssClass(Boton.cssBrdLeft);
			}else{
				Boton.htmlBrdLeft.cssClass('btn_brd_left_normal');
			}
			
			if(Boton.cssBrdRight){
				Boton.htmlBrdRight.cssClass(Boton.cssBrdRight);
			}else{
				Boton.htmlBrdRight.cssClass('btn_brd_right_normal');
			}
			
			if(Boton.cssFnd){
				Boton.htmlFnd.cssClass(Boton.cssFnd);
			}else{
				Boton.htmlFnd.cssClass('btn_fnd_normal');
			}
			
			if(Boton.cssText){
				Boton.htmlText.cssClass(Boton.cssText);
			}else{
				Boton.htmlText.cssClass('btn_text_normal');
			}
			
		});
		
		this.htmlEventos.mdown(function(me){
			
			var Boton = ButtonsManager.Buttons.GetObjectById(me.getAttribute('BotonId'));
			
			if(Boton.cssBrdLeftPress){
				Boton.htmlBrdLeft.cssClass(Boton.cssBrdLeftPress);
			}else{
				Boton.htmlBrdLeft.cssClass('btn_brd_left_press');
			}
			
			if(Boton.cssBrdRightPress){
				Boton.htmlBrdRight.cssClass(Boton.cssBrdRightPress);
			}else{
				Boton.htmlBrdRight.cssClass('btn_brd_right_press');
			}
			
			if(Boton.cssFndPress){
				Boton.htmlFnd.cssClass(Boton.cssFndPress);
			}else{
				Boton.htmlFnd.cssClass('btn_fnd_press');
			}
			
			if(Boton.cssTextPress){
				Boton.htmlText.cssClass(Boton.cssTextPress);
			}else{
				Boton.htmlText.cssClass('btn_text_press');
			}
			
		});
		
		this.htmlEventos.mup(function(me){
			
			var Boton = ButtonsManager.Buttons.GetObjectById(me.getAttribute('BotonId'));
			
			if(Boton.cssBrdLeft){
				Boton.htmlBrdLeft.cssClass(Boton.cssBrdLeft);
			}else{
				Boton.htmlBrdLeft.cssClass('btn_brd_left_normal');
			}
			
			if(Boton.cssBrdRight){
				Boton.htmlBrdRight.cssClass(Boton.cssBrdRight);
			}else{
				Boton.htmlBrdRight.cssClass('btn_brd_right_normal');
			}
			
			if(Boton.cssFnd){
				Boton.htmlFnd.cssClass(Boton.cssFnd);
			}else{
				Boton.htmlFnd.cssClass('btn_fnd_normal');
			}
			
			if(Boton.cssText){
				Boton.htmlText.cssClass(Boton.cssText);
			}else{
				Boton.htmlText.cssClass('btn_text_normal');
			}
			
		});
		
		this.htmlEventos.mup(function(me){
			
			var Boton = ButtonsManager.Buttons.GetObjectById(me.getAttribute('BotonId'));
			
			if(Boton.Link){
				gotourl(Boton.Link);
			}
			
		});
		
	}
	
	this.Init = function(){
	
		this.htmlDiv = go(this.Id);
		
		this.htmlDiv.css('position', 'relative');
		this.htmlDiv.css('overflow', 'hidden');
		this.htmlDiv.html('&nbsp;');
		this.htmlDiv.setW(this.Width);
		this.htmlDiv.setH(this.Height);
		
		this.Container = this.htmlDiv.parentNode;
		
		//Creo el div del fondo.
		this.htmlFnd = this.htmlDiv.newdiv(this.Id+'.Fnd');
		this.htmlFnd.css('position', 'absolute');
		this.htmlFnd.css('overflow', 'hidden');
		this.htmlFnd.html('&nbsp;');
		this.htmlFnd.setX(0);
		this.htmlFnd.setY(0);
		this.htmlFnd.setW(this.Width);
		this.htmlFnd.setH(this.Height);
		
		//Creo el div del borde izquierdo.
		this.htmlBrdLeft = this.htmlDiv.newdiv(this.Id+'.BrdLeft');
		this.htmlBrdLeft.css('position', 'absolute');
		this.htmlBrdLeft.css('overflow', 'hidden');
		this.htmlBrdLeft.html('&nbsp;');
		this.htmlBrdLeft.setX(0);
		this.htmlBrdLeft.setY(0);
		this.htmlBrdLeft.setW(this.BorderWidth);
		this.htmlBrdLeft.setH(this.Height);
		
		//Creo el div del borde derecho.
		this.htmlBrdRight= this.htmlDiv.newdiv(this.Id+'.BrdRight');
		this.htmlBrdRight.css('position', 'absolute');
		this.htmlBrdRight.css('overflow', 'hidden');
		this.htmlBrdRight.html('&nbsp;');
		this.htmlBrdRight.setX(this.Width-this.BorderWidth);
		this.htmlBrdRight.setY(0);
		this.htmlBrdRight.setW(this.BorderWidth);
		this.htmlBrdRight.setH(this.Height);
		
		//Creo el div para el texto.
		this.htmlText= this.htmlDiv.newdiv(this.Id+'.Text');
		this.htmlText.css('position', 'absolute');
		this.htmlText.css('overflow', 'hidden');
		this.htmlText.html(this.Text);
		this.htmlText.css('background-color', 'transparent');
		this.htmlText.setX(0);
		this.htmlText.setY(0);
		this.htmlText.setW(this.Width);
		this.htmlText.setH(this.Height);
		
		//creo el div para los eventos.
		
		this.htmlEventos= this.htmlDiv.newdiv(this.Id+'.Eventos');
		this.htmlEventos.css('position', 'absolute');
		this.htmlEventos.css('overflow', 'hidden');
		this.htmlEventos.css('cursor', 'pointer');
		this.htmlEventos.html('&nbsp;');
		this.htmlEventos.css('background-color', '#f5f5f5');
		this.htmlEventos.alpha(1);
		this.htmlEventos.setX(0);
		this.htmlEventos.setY(0);
		this.htmlEventos.setW(this.Width);
		this.htmlEventos.setH(this.Height);
		this.htmlEventos.raiseTop();
		this.htmlEventos.setAttribute('BotonId', this.Id);
		
		//asigno las clases de css a los objetos
		
		if(this.cssBrdLeft){
			this.htmlBrdLeft.cssClass(this.cssBrdLeft);
		}else{
			this.htmlBrdLeft.cssClass('btn_brd_left_normal');
		}
		
		if(this.cssBrdRight){
			this.htmlBrdRight.cssClass(this.cssBrdRight);
		}else{
			this.htmlBrdRight.cssClass('btn_brd_right_normal');
		}
		
		if(this.cssFnd){
			this.htmlFnd.cssClass(this.cssFnd);
		}else{
			this.htmlFnd.cssClass('btn_fnd_normal');
		}
		
		if(this.cssText){
			this.htmlText.cssClass(this.cssText);
		}else{
			this.htmlText.cssClass('btn_text_normal');
		}
		
		this.PonerEventos();
		
	}
	
}

function ButtonsMngr(){

	this.Buttons = new ObjectsList();
	
	this.Init = function(){
		
		go('div{Type}{Button}').Walk(function(pIndex, pButton, pMe){
			
			if(pButton.getAttribute('id')){
				
				var newBtn = new Button();
				
				newBtn.Id = pButton.id;
				
				if(pButton.getAttribute('Text')){
					newBtn.Text = pButton.getAttribute('Text');
				}
				
				if(pButton.getAttribute('Link')){
					newBtn.Link = pButton.getAttribute('Link');
				}
				
				if(pButton.getAttribute('Width')){
					newBtn.Width = pButton.getAttribute('Width');
				}
				
				if(pButton.getAttribute('Height')){
					newBtn.Height = pButton.getAttribute('Height');
				}
				
				if(pButton.getAttribute('BorderWidth')){
					newBtn.BorderWidth = pButton.getAttribute('BorderWidth');
				}
				
				if(pButton.getAttribute('cssText')){
					newBtn.cssText = pButton.getAttribute('cssText');
				}
				
				if(pButton.getAttribute('cssTextOver')){
					newBtn.cssTextOver = pButton.getAttribute('cssTextOver');
				}
				
				if(pButton.getAttribute('cssTextPress')){
					newBtn.cssTextPress = pButton.getAttribute('cssTextPress');
				}
				
				if(pButton.getAttribute('cssBrdLeft')){
					newBtn.cssBrdLeft = pButton.getAttribute('cssBrdLeft');
				}
				
				if(pButton.getAttribute('cssBrdLeftOver')){
					newBtn.cssBrdLeftOver = pButton.getAttribute('cssBrdLeftOver');
				}
				
				if(pButton.getAttribute('cssBrdLeftPress')){
					newBtn.cssBrdLeftPress = pButton.getAttribute('cssBrdLeftPress');
				}
				
				if(pButton.getAttribute('cssBrdRight')){
					newBtn.cssBrdRight = pButton.getAttribute('cssBrdRight');
				}
				
				if(pButton.getAttribute('cssBrdRightOver')){
					newBtn.cssBrdRightOver = pButton.getAttribute('cssBrdRightOver');
				}
				
				if(pButton.getAttribute('cssBrdRightPress')){
					newBtn.cssBrdRightPress = pButton.getAttribute('cssBrdRightPress');
				}
				
				if(pButton.getAttribute('cssFnd')){
					newBtn.cssFnd = pButton.getAttribute('cssFnd');
				}
				
				if(pButton.getAttribute('cssFndOver')){
					newBtn.cssFndOver = pButton.getAttribute('cssFndOver');
				}
				
				if(pButton.getAttribute('cssFndPress')){
					newBtn.cssFndPress = pButton.getAttribute('cssFndPress');
				}
				
				newBtn.Init();
				
				pMe.Buttons.Add(newBtn);
				
			}
			
		}, this);
		
	}
}

var ButtonsManager = new ButtonsMngr();

Page.OnLoad(function(){
	ButtonsManager.Init();
});
