var dir_img = "/elementos/";
var ext_img = ".gif";
var ext_logo = ".png";
var frm_target = "frm_contenidos";
var frm_unlock = "";
var botones = new Array;
var nboton = 0;

function add_btn (img,url_dest){
	var nombre = "btn" + nboton;
	botones[nboton] = new boton(img,url_dest,nombre);
	nboton++;
}

function set_frm_unlock(_frm_unlock){
		frm_unlock = _frm_unlock;
}

function btn_unlock_all(){
	for (i=0;i<nboton;i++)
		botones[i].btn_unlock();
}

function boton(_img,_url_dest,_nombre){
	this.img_n  = new Image;
	this.img_o  = new Image;
	this.img_c  = new Image;
	this.img_co = new Image;
	this.img_n.src  = dir_img + "n/" + _img + ext_img;
	this.img_o.src  = dir_img + "o/" + _img + ext_img;
	this.img_c.src  = dir_img + "c/" + _img + ext_img;
	this.img_co.src = dir_img + "co/" + _img + ext_img;
	this.lock 		 = false;
	this.nombre    = _nombre;
	this.url_dest	 = _url_dest;

	nombre_boton = "botones[" + nboton + "]";
	document.write ("<td class='actiu' ");
	document.write ("onmouseover='" + nombre_boton + ".btn_over()' ");
	document.write ("onmouseout='" + nombre_boton + ".btn_out()' ");
	document.write ("onclick='" + nombre_boton + ".btn_click()'>");
	document.write ("<img name='" + _nombre + "_img' src='" + dir_img + "n/" + _img + ext_img + "'>");
	document.write ("</td>");

	this.btn_over = function(){
		if (this.lock == false)
			document.images[this.nombre + "_img"].src = this.img_o.src;
	}

	this.btn_unlock = function(){
		if (this.lock == true){
			this.lock = false;
			document.images[this.nombre + "_img"].src = this.img_n.src;
    }
	}

	this.btn_out = function(){
		if (this.lock == false)
			document.images[this.nombre + "_img"].src = this.img_n.src;
	}

	this.btn_click = function(){
		if (frm_unlock != ""){
			top.frames[frm_unlock].btn_unlock_all();
		}
		btn_unlock_all();
		document.images[this.nombre + "_img"].src = this.img_c.src;
		if (this.url_dest.substr(0,7) == "http://"){
			window.open(this.url_dest);
		}
		else{
			top.frames[frm_target].location = this.url_dest;
		}
		this.lock = true;
	}
}

