function buttonPatch(imgRef, offImg, onImg) {
	var r = Math.random() * 30000;
	var img = (typeof imgRef == "string") ?	document.getElementById(imgRef) : imgRef;
	img.src = offImg + "?x=" + r;
	img.border = 0;
	img.onSrc = onImg;
	img.offSrc = offImg;
	img.onmouseover = function() {this.src = onImg + "?x=" + r;};
	img.onmouseout = function() {this.src = offImg + "?x=" + r;};
	
	img.dsb_onmouseover = img.onmouseover;
	img.dsb_onmouseout = img.onmouseout;
	
}



// Specific

function createButton(name, selected, altText) {
	var a = document.getElementById(name);
	var img = document.createElement("img");
	var offImg = "img/btn_" + name + "_off.gif";
	var onImg = "img/btn_" + name + "_on.gif";
	var imgId = "imgId_" + name;
	
	a.appendChild(img);
	img.id = imgId;
	
	if (altText) {
		img.alt = altText;
	}
	
	if (selected) {
		img.src = onImg;
	} else {
		buttonPatch(imgId, offImg, onImg);
		a.href = name + ".php";
	}
	
}


function createNonLinkButton(name, altText) {
	var img = document.createElement("img");
	var offImg = "img/btn_" + name + "_off.gif";
	var onImg = "img/btn_" + name + "_on.gif";
	var imgId = name;
	
	img.id = imgId;
	
	if (altText) {
		img.alt = altText;
	}
	
	buttonPatch(img, offImg, onImg);
	return img;
}


function createMenuBar(id, selectedName) {
	var xcoords = [29, 112, 210, 298, 425, 517];
	var names = ["empresa", "productos", "servicios", "repre", "contacto", "inicio"];
	var descs = ["Empresa", "Productos", "Servicios", "Representantes", "Contacto", "Inicio"];
	var n = names.length;
	var div = document.getElementById(id);
	
	for (var i = 0; i < n; i++) {
		var name = names[i];
		var a = document.createElement("a");
		div.appendChild(a);
		a.id = name;
		a.title = descs[i];
		
		createButton(name, name == selectedName, descs[i]);
		a.className = "menuLink";
		a.style.top = "17px";
		a.style.left = xcoords[i];
	}
}



function createProdMenu(id) {
	var ycoords = [0, 44, 90, 120, 164, 195];
	prodNames = ["prod_es", "prod_qs", "prod_vs", "prod_bs", "prod_fs", "prod_hl"];
	var descs = ["Escaleras Mecánicas (ES)",
				 "Ascensores de Pasajeros Standard (QS):",
				 "Ascensores Panorámicos (VS)",
				 "Ascensores Camilleros (BS)",
				 "Montacargas (FS)",
				 "Ascensores Residenciales (HL)"];
	var n = prodNames.length;
	var div = document.getElementById(id);
	
	for (var i = 0; i < n; i++) {
		var img = createNonLinkButton(prodNames[i], descs[i]);
		
		img.style.position = "absolute";
		img.style.left = "0";
		img.style.top = ycoords[i];
		img.style.cursor = "pointer";
		div.appendChild(img);
		img.onclick = selectThisProd;
		img.dsb_onclick = img.onclick;
	}
}


function selectThisProd() {
	if (window.previousProd) {
		deselectProd(previousProd);
	}
	selectProd(this.id);
}

function selectProd(id) {
	img = document.getElementById(id);
	div = document.getElementById("div_" + id);
	div.style.display = "block";
	img.src = img.onSrc;
	img.onmouseover = null;
	img.onmouseout = null;;
	img.onclick = null;
	img.style.cursor = "default";
	previousProd = id;
}

function deselectProd(id) {
	img = document.getElementById(id);
	div = document.getElementById("div_" + id);
	div.style.display = "none";
	img.src = img.offSrc;
	img.onmouseover = img.dsb_onmouseover;
	img.onmouseout = img.dsb_onmouseout;
	img.onclick = img.dsb_onclick;
	img.style.cursor = "pointer";
}


function showOverlay(pId) {
	var id = "grayOverlay";
	var e = document.getElementById(id);
	if (!e) {
		e = document.createElement("div");
		e.id = id;
		e.style.position = "absolute";
		e.style.width = "900px";
		e.style.height = "680px";
		e.style.backgroundColor = "black";
		e.style.opacity = 0.7;
		e.style.filter = 'alpha(opacity=70)';
		e.style.left = 0;
		e.style.top = 0;
		e.style.zIndex = 100;
		e.visibility = "hidden";
		
		var parent = document.getElementById(pId);
		parent.appendChild(e);
	}
	
	e.style.visibility = "visible";
}

function hideOverlay() {
	var e = document.getElementById("grayOverlay");
	if (e) {
		e.style.visibility = "hidden";
	}
}

function showImage(pId, imgSrc, x, y) {
	showOverlay(pId);
	
	var id = "bigImage";
	var img = document.getElementById(id);
	if (!img) {
		img = document.createElement("img");
		img.id = id;
		img.style.position = "absolute";
		img.style.zIndex = 110;
		img.style.visibility = "hidden";
		img.style.border = "4px solid white";
		img.style.cursor = "pointer";
		
		var parent = document.getElementById(pId);
		parent.appendChild(img);
		
		img.onclick = function() {
			hideOverlay();
			img.style.visibility = "hidden";
		};
		
	}
	
	img.src = imgSrc;
	img.style.left = x;
	img.style.top = y;
	img.style.visibility = "visible";
	if (img.scrollIntoView) {
		img.scrollIntoView();
		window.scrollBy(0, -20);
	}
}


function initBltGallery() {
	BLT_pic = 1;
	BLT_names = [
		"Estadio Nacional \"Nido de pájaro\" Edificio  Olímpico 2008 Beijing",
		"Piscina Cubierta Nacional \"Cubo de agua\" - Edificio  Olímpico 2008 Beijing",
		"Shanghai, Edificio Aurora.",
		"Edificio de Federación, Rusia.",
		"Centro de Negocios, Dubai",
		"Torre de la vista al río, Chicago, U.S.A.",
		"Parque Legacy Millennium, Chicago, U.S.A.",
		"Foxwoods, U.S.A.",
		"EPSON, Japón.",
		"Edificio IBM, Singapur.",
		"Edificio North Light, Kazakstan."
	];
	
}

function changePic(dir) {
	BLT_pic += dir;
	if (BLT_pic < 1 || BLT_pic > 12) {
		BLT_pic = 1;
	}
	
	setBltPic(BLT_pic);
}


function setBltPic(n) {
	var intro = document.getElementById("bltIntro");
	var gallery = document.getElementById("bltGallery");

	if (n == 1) {
		gallery.style.display = "none";
		intro.style.display = "block";
		return;
	}

	intro.style.display = "none";
	gallery.style.display = "block";
	
	var name = BLT_names[n - 2];
	var picSrc = "img/blt_photo_" + n + ".jpg";
	var txtSrc = "img/txt_blt_" + n + ".gif";
	
	var picImg = document.getElementById("bltPicture");
	var txtImg = document.getElementById("bltName");
	
	picImg.src = picSrc;
	picImg.alt = name;
	txtImg.src = txtSrc;
	txtImg.alt = name;
}





