//Funciones utiles

var textos = new Array(2)
textos[0]=new Array("Clic para hacer más grande","Clic para cerrar");
textos[1]=new Array("Clic to Zoom In","Clic to close");
var url=window.location.href;
var idioma = (url.indexOf('english')==-1) ? 0 : 1;

function addClass(element, value) {
	if (!element.className) {
		element.className = value;
	} else {
		var newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
	}
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function borrarFoto(){
	targ=document.getElementById("FotoEnGrande");
	document.body.removeChild(targ);
}

function abrirFoto(e){
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	var ruta = targ.src;
	var rutas = ruta.split("/");
	ruta = rutas[rutas.length-1];
	if (document.getElementById("FotoEnGrande")){
		cosa=document.getElementById("FotoEnGrande");
		document.body.removeChild(cosa);
	}
	var nDiv = document.createElement("div");
	nDiv.innerHTML = "<span class='txt'>" + textos[idioma][1] + "</span><div class='aux'><img src='../../images/vallarta/big/" + ruta + " ' width='533' height='400'></div>";
	nDiv.setAttribute("id", "FotoEnGrande");
	document.body.appendChild(nDiv);
	nDiv=document.getElementById("FotoEnGrande");
	nDiv.title=textos[idioma][1];
	nDiv.style.cursor="pointer";
	if (BrowserDetect.browser=="Explorer" && targ.rel){
		nDiv.style.posTop=targ.rel;
	}
	addEvent(nDiv,"click",borrarFoto,false);
}

function addClick(){
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	var los_pic = document.getElementById('openPic');
	var los_img = los_pic.getElementsByTagName('img');
	for(var i = 0; i < los_img.length; i++){
		los_img[i].title=textos[idioma][0];
		los_img[i].style.cursor="pointer";
		addEvent(los_img[i],"click",abrirFoto,false);
	}
	var linkcss = document.createElement("link");
	linkcss.setAttribute("rel", "stylesheet");
	linkcss.setAttribute("href", "../../css/openPic.css");
	linkcss.setAttribute("type", "text/css");
	document.body.appendChild(linkcss);
}

addEvent(window,"load",addClick,false);
//Fin Funciones utiles