function Boton() {}

Boton.setColor = function( nombre, color ) {
	document.getElementById( nombre ).style.color = color;
}

Boton.unsetColor = function( nombre ) {
	if ( botonActivo != nombre ) {
		document.getElementById( nombre ).style.color = "";
	}
}

Boton.sustituir = function(nombre,fichero) {
	if ( botonActivo != nombre ) {
		document.getElementById( nombre ).style.backgroundImage = 'url(' + fichero + ')';
	}
}

Boton.ponerFondo = function(nombre,alto) {
	if ( botonActivo != nombre ) {
		document.getElementById( nombre ).style.backgroundPosition = '0px ' + alto + 'px';
	}
}



Boton.getImagenBase = function( nombre ) {
	var fuente = document.getElementById( nombre ).style.backgroundImage;
	return fuente.replace( /_.*\./, "." ).replace( "url(","").replace( ")", "");
}

Boton.getImagenAbajo = function( nombre ) {
	return Boton.getImagenBase( nombre ).replace( ".", "_abajo." );
}

Boton.activar = function( nombre, color ) {
	if ( botonActivo != nombre ) {
		if ( document.getElementById( botonActivo ) ) {
			document.getElementById( botonActivo ).style.color = '';
			anteriorActivo = botonActivo;
			botonActivo = "";
			Boton.ponerFondo( anteriorActivo, '0' );
		}
	}
	botonActivo = nombre;
	if ( color )
		document.getElementById( nombre ).style.color = color;
	else
		document.getElementById( nombre ).style.color = '#FFFFFF';
}

Boton.activarYPulsar = function( nombre, color ) {
	Boton.ponerFondo( nombre, '-' + ( document.getElementById(nombre).offsetHeight * 2 ) );
	Boton.activar( nombre, color );
}

Boton.alinearTodos = function() {
	var anclas = document.getElementsByTagName( 'a' );
	var i = 0;
	for ( i = 0; i < anclas.length; i++ ) {
            if ( anclas[i].className.indexOf( 'botonConTexto' ) >= 0  )
                Boton.alinearUno( anclas[i] );
	}
}

Boton.alinearUno = function( boton ) {
    boton.style.visibility = 'visible';
    var spans = boton.getElementsByTagName('span');
    var alto = 0;
    var altoBoton = parseInt( boton.style.height );
    var paddingInicial = parseInt( boton.style.paddingTop );
    var altoLinea = 14;
    if ( spans.length > 0 && !isNaN( spans[0].offsetHeight ) )
        altoLinea = spans[0].offsetHeight;
    for(var i=0; i < spans.length; i++){
        if( spans[i].offsetTop > alto )
            alto = spans[i].offsetTop;
    }
    alto += altoLinea;
    var paddingTop = ( altoBoton - alto ) / 2;

    boton.style.paddingTop = ( paddingInicial + paddingTop ) + 'px';

    boton.style.height = ( altoBoton - paddingTop ) + 'px';
}

