// JavaScript Document
var $ = function (i){
	return document.getElementById(i);
}

window.oFotoFavorita = new function(){
	var loaderFoto = null;
	var cuadroFoto = null;
	var fotoFavorita = null;
	var indiceActualFoto = null;
	var arregloFotos = new Array();
	var iniciado = false;

	var iniciar = function(){
		iniciado = true;
		loaderFoto = $('loaderFavorita');
		cuadroFoto = $('cuadroFavorita');
		fotoFavorita = $('fotoFavoritaGrande');
		AddEvent(fotoFavorita,'load',mostrarImagen);
		AddEvent($('fotoAnterior'),'click',function(){fotoTransicion(-1)});
		AddEvent($('fotoSiguiente'),'click',function(){fotoTransicion(+1)});
		AddEvent($('fotoVolver'),'click',volverListaFotos);
		
	}

	this.setearArreglo = function(arreglo){
		arregloFotos = arreglo;
	}
	this.mostrarFoto = function(obj){
		if(!iniciado)iniciar();
		indiceActualFoto = obj.indice;
		fotoFavorita.style.display = 'none';
		loaderFoto.style.display = 'block';
		ubicarContenido(cuadroFoto);
		cuadroFoto.style.visibility = 'visible'
		fotoFavorita.src = obj.nombreGrande.substr(3);

		setearFlechas();
	}
	var mostrarImagen = function(){
		fotoFavorita.style.display = 'block';
		loaderFoto.style.display = 'none';

	}

	var fotoTransicion = function(suma){
		this.mostrarFoto(arregloFotos[indiceActualFoto+suma]);
	}.closure(this);
	var setearFlechas = function(){
		if((indiceActualFoto) > 0){
			$('fotoAnterior').style.display = '';
			$('fotoAnteriorOff').style.display = 'none';
		}
		else{
			$('fotoAnterior').style.display = 'none';
			$('fotoAnteriorOff').style.display = '';			
		}

		if(indiceActualFoto < arregloFotos.length-1){
			$('fotoSiguiente').style.display = '';
			$('fotoSiguienteOff').style.display = 'none';
		}
		else{
			$('fotoSiguiente').style.display = 'none';
			$('fotoSiguienteOff').style.display = '';			
		}
	
	}
	var volverListaFotos = function(){
		cuadroFoto.style.visibility = 'hidden';
		cuadroFoto.style.top = '-1000px';
	}
	var ubicarContenido = function(objeto){
		var dims = getWindowDims();
		var left = Math.round((dims.w-objeto.offsetWidth)/2);	
		objeto.style.top = $('contenedorGeneral').offsetTop+"px";
		objeto.style.left = left+"px";	
	}
	function getWindowDims(){
		if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight};
		else if(Nav.esMz) return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
		else if(Nav.esIE) return {w:document.body.clientWidth, h:document.body.clientHeight};
		else return {w:0, h:0}
	}
	function getBodyDims(){
		if(Nav.esOp) return {w:document.body.clientWidth, h:document.body.clientHeight};
		else if(Nav.esIE || Nav.esMz) return {w:document.body.offsetWidth, h:document.body.offsetHeight};
		else return {w:0, h:0}
	}
}
