var _foto = "";
var _pieFoto = "";
var _totalFotos = 0;
var contador = 1;
var fadeWin = 0;
var fadeWinFoto = 0;
var fadeFireFox = 0;
var fadeFireFoxFoto = 0;
var listadoFotos = Array();
var listadoPies = Array();

function addListadoFotos(cual){
	listadoFotos.push(cual.substring(0,cual.indexOf("_")));
}

function addListadoPiesFoto(cual){
	listadoPies.push(cual);
}

function verFotos(foto,totalFotos){
	contador = foto;
	_foto = listadoFotos[contador];
	_totalFotos = totalFotos;
	
	var h,w,posicionScroll;
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
		posicionScroll = document.documentElement.scrollTop;
	}else{
		h = window.innerHeight;
		w = window.innerWidth - 15;
		posicionScroll = window.scrollY;
	}
	
	document.getElementById('fondoFotos').style.top = posicionScroll + "px";
	document.getElementById('fondoFotos').style.width = w + "px";
	document.getElementById('fondoFotos').style.height = h + "px";
	document.getElementById('fondoFotos').style.visibility = 'visible';
	
	setTimeout(aplicarFadeFondoFotos, 10);
	
	montarFotos();
}

function verVideo(cual){
	var h,w,posicionScroll;
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
		posicionScroll = document.documentElement.scrollTop;
	}else{
		h = window.innerHeight;
		w = window.innerWidth - 15;
		posicionScroll = window.scrollY;
	}
	
	document.getElementById('fondoFotos').style.top = posicionScroll + "px";
	document.getElementById('fondoFotos').style.width = w + "px";
	document.getElementById('fondoFotos').style.height = h + "px";
	document.getElementById('fondoFotos').style.visibility = 'visible';
	
	setTimeout(aplicarFadeFondoFotos, 10);
	
	document.getElementById('fotos').style.visibility = 'hidden';
	
	htmlFoto = "<div id='izquierda' style='width:340px;'>&nbsp;</div>";
	htmlFoto += "<div id='cerrar'><a href='javascript:cerraGaleria()'><img src='gallery/cerrar.jpg' alt='cerrar' border='0'></a></div>";
	htmlFoto += "<div id='foto' style='width:320px;'>";
		htmlFoto += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="320" height="240" id="cronicajarama" align="middle">	<param name="allowScriptAccess" value="sameDomain" />	<param name="allowFullScreen" value="false" />	<param name="movie" value="gallery/' + cual + '.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="gallery/' + cual + '.swf" quality="high" bgcolor="#ffffff" width="320" height="240" name="cronicajarama" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_es" />	</object>';
	htmlFoto += "</div>";
	
	document.getElementById('fotos').innerHTML = htmlFoto;
	
	if (navigator.appVersion.indexOf("MSIE") != -1){
		document.getElementById('fotos').style.filter = "alpha(opacity=100)";
	}else{
		document.getElementById('fotos').style.opacity = 1;
	}
	
	document.getElementById('fotos').style.height = 260 + 20 + "px";
	document.getElementById('fotos').style.width = 320 + 40 + "px";
	document.getElementById('fotos').style.top = posicionScroll + h/2 - (260 + 45)/2 + "px";
	document.getElementById('fotos').style.left = w/2 - (350 + 40)/2 + "px";
	document.getElementById('fotos').style.visibility = 'visible';
}

function montarFotos(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
		posicionScroll = document.documentElement.scrollTop;
	} 
	else{
		h = window.innerHeight;
		w = window.innerWidth;
		posicionScroll = window.scrollY;
	}
	
	document.getElementById('loading').style.top = posicionScroll + h/2 - 22/2 + "px";
	document.getElementById('loading').style.left = w/2 - 126/2 + "px";
	document.getElementById('loading').style.visibility = 'visible';
	
	document.getElementById('fotos').style.visibility = 'hidden';
	
	htmlFoto = "<div id='izquierda'>&nbsp;</div>";
	htmlFoto += "<div id='cerrar'><a href='javascript:cerraGaleria()'><img src='gallery/cerrar.jpg' alt='cerrar' border='0'></a></div>";
	htmlFoto += "<div id='foto'><img src='" + listadoFotos[contador] + ".jpg' alt='' onload='aplicarFadeFoto(this)'></div>";
	if (contador > 0) htmlFoto += "<div id='atras'><a href='javascript:anterior()'><img src='gallery/anterior.jpg' alt='anterior' border='0'></a></div>";
	else htmlFoto += "<div id='atras'>&nbsp;</div>";
	
	if (listadoPies[contador] != undefined) htmlFoto += "<div id='pieFoto'>" + listadoPies[contador] +"</div>";
	else htmlFoto += "<div id='pieFoto'>&nbsp;</div>";
	
	if (contador < _totalFotos-1) htmlFoto += "<div id='siguiente'><a href='javascript:siguiente()'><img src='gallery/siguiente.jpg' alt='siguiente' border='0'></a></div>";
	
	document.getElementById('fotos').innerHTML = htmlFoto;
}

function aplicarFadeFoto(foto){
	document.getElementById('loading').style.visibility = 'hidden';
	
	foto.width = 500;
	
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
		posicionScroll = document.documentElement.scrollTop;
	}else{
		h = window.innerHeight;
		w = window.innerWidth;
		posicionScroll = window.scrollY;
	}
	
	document.getElementById('fotos').style.height = foto.height + 45 + "px";
	document.getElementById('fotos').style.width = foto.width + 40 + "px";
	document.getElementById('fotos').style.top = posicionScroll + h/2 - (foto.height + 45)/2 + "px";
	document.getElementById('fotos').style.left = w/2 - (foto.width + 40)/2 + "px";
	document.getElementById('fotos').style.visibility = 'visible';
	
	if (navigator.appVersion.indexOf("MSIE") != -1){
		fadeWinFoto = fadeWinFoto + 15;
		document.getElementById('fotos').style.filter = "alpha(opacity="+fadeWinFoto+")";
		if (fadeWinFoto < 100 ) setTimeout(aplicarFadeFoto(foto),10);
	}else{
		fadeFireFoxFoto = fadeFireFoxFoto + 0.15;
		document.getElementById('fotos').style.opacity = fadeFireFoxFoto;
		if (fadeFireFoxFoto < 1) setTimeout(aplicarFadeFoto(foto),10);
	}
}

function cerraGaleria(){
	document.getElementById('loading').style.visibility = 'hidden';
	document.getElementById('fotos').style.visibility = 'hidden';
	document.getElementById('fondoFotos').style.visibility = 'hidden';
	document.getElementById('fondoFotos').style.width = "1px";
	document.getElementById('fondoFotos').style.height = "1px";
	document.getElementById('fotos').innerHTML = "";
	fadeFireFoxFoto = 0;
	fadeWinFoto = 0;
	fadeWin = 0;
	fadeFireFox = 0;
	
	if (navigator.appVersion.indexOf("MSIE") != -1) {
		document.getElementById('fotos').style.filter = "alpha(opacity=" + fadeWinFoto + ")";
		document.getElementById('fondoFotos').style.filter = "alpha(opacity=" + fadeWin + ")";
	}else{
		document.getElementById('fotos').style.opacity = fadeFireFoxFoto;
		document.getElementById('fondoFotos').style.opacity = fadeFireFox;
	} 
}

function aplicarFadeFondoFotos(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		fadeWin = fadeWin + 15;
		document.getElementById('fondoFotos').style.filter = "alpha(opacity="+fadeWin+")";
		if (fadeWin < 75 ) setTimeout(aplicarFadeFondoFotos,10);
	}else{
		fadeFireFox = fadeFireFox + 0.15;
		document.getElementById('fondoFotos').style.opacity = fadeFireFox;
		if (fadeFireFox < 0.75) setTimeout(aplicarFadeFondoFotos,10);
	}
}

function siguiente(){
	contador++;
	montarFotos();
}

function anterior(){
	contador--;
	montarFotos();
}

function moverFotos(){
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		w = document.documentElement.clientWidth;
	}else{
		h = window.innerHeight;
		w = window.innerWidth;
	}
	
	document.getElementById('fondoFotos').style.width = w + "px";
	document.getElementById('fondoFotos').style.height = h + "px";
	
	document.getElementById('fotos').style.top = h/2 - parseInt(document.getElementById('fotos').style.height)/2 + "px";
	document.getElementById('fotos').style.left = w/2 - parseInt(document.getElementById('fotos').style.width)/2 + "px";
	
	document.getElementById('loading').style.top = h/2 - 22/2 + "px";
	document.getElementById('loading').style.left = w/2 - 126/2 + "px";
}

function moverFotosScroll(){
	var h,posicionScroll;
	
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.documentElement.clientHeight;
		posicionScroll = document.documentElement.scrollTop;
	}else{
		h = window.innerHeight;
		posicionScroll = window.scrollY;
	} 
	
	document.getElementById('fotos').style.top = posicionScroll + (h/2 - parseInt(document.getElementById('fotos').style.height)/2) + "px";
	document.getElementById('fondoFotos').style.top = posicionScroll + "px";
}
