// JavaScript Document
//Programado por Marcelo Tobal
//Todos los derechos reservados al autor

//DEGRADES
var alturaDEGRADES = 0;
var velocidadDEGRADES = 10;

var opacity= 0.0;//PARA FIREFOX, GOOGLE, OPERA
var velocidadOPACITY = 0.10;//PARA FIREFOX, GOOGLE, OPERA
var existedegrades=false;

function mostrarDEGRADES(alto) {

	if(!existedegrades)
	{
		cuadro = document.createElement('div');
		cuadro.id ='degrades';
		cuadro.style.height=(document.body.scrollHeight)+'px';
		contenedor.appendChild(cuadro);
		existedegrades=true;
	}

	var capa='degrades';

	document.getElementById(capa).style.display='block';
	alturaDEGRADES += velocidadDEGRADES;
	opacity += velocidadOPACITY;//PARA FIREFOX, GOOGLE, OPERA
	if (!(alturaDEGRADES >= alto)) {
		document.getElementById(capa).style.opacity=opacity;//PARA FIREFOX, GOOGLE, OPERA
		document.getElementById(capa).style.filter='alpha(opacity='+alturaDEGRADES+')';
		window.setTimeout ("mostrarDEGRADES('"+alto+"');", 10);
	}
}//fin de Mostrar Degrades
function ocultarDEGRADES(alto) {
	var capa='degrades';
	document.getElementById(capa).style.display='block';
	alturaDEGRADES -= velocidadDEGRADES;
	opacity -= velocidadOPACITY;//PARA FIREFOX, GOOGLE, OPERA
	if (!(alturaDEGRADES <= alto)) {
		document.getElementById(capa).style.opacity=opacity;//PARA FIREFOX, GOOGLE, OPERA
		document.getElementById(capa).style.filter='alpha(opacity='+alturaDEGRADES+')';//PARA IE
		window.setTimeout ("ocultarDEGRADES('"+alto+"');", 10);
	}
	else
		document.getElementById(capa).style.display='none';
}//fin de Ocultar Degrades
function mostrar_ocultar_DEGRADES() {

	if (alturaDEGRADES<=0) {
		mostrarDEGRADES(70);
	} else {
		ocultarDEGRADES(0)
	}
}//Funcion detectar si muestra on oculta degrades	


//Ampliar Imagen
var existeImagen=false;
var capaOculta="";
function ampliar(img,ocultar,epigrafetxt,epigrafeurl)
{	
	
	mostrar_ocultar_DEGRADES();
	//Creamos el div para visualizar al imagen
	if(!existeImagen)
	{
		//Creacion del div contenedor de la imagen
		cuadro = document.createElement('div');
		cuadro.id ='imagen_ampliada';
		cuadro.name='imagen_ampliada';
		cuadro.style.position="absolute";
		cuadro.style.zIndex="2";
		cuadro.style.backgroundColor="#FFF";
		cuadro.style.display="block";
		cuadro.style.textAlign="center";

	
	    //Creacion de la imagen
		imagen = document.createElement('img');
		imagen.id = 'foto_ampliada';
		imagen.alt ='';	
		cuadro.appendChild(imagen);
		existeImagen=true;
		
		epigrafe = document.createElement('div');
		epigrafe.innerHTML='<div id="epigrafeFoto"></div><br><a  href="javascript:cerrarampliar()"><img align="right" src="img/cerrar_foto.gif" border="0" alt="" /></a>';
		cuadro.appendChild(epigrafe); 
		
		//Anexamos el visualizador de imagenes a la pagina
		contenedor.appendChild(cuadro); 
	}
	imagen.src = "img/cargando.gif";
	imagen.style.padding="40px";
	
	//URL de la imagen a mostrar
	setTimeout("imagenload('"+img+"');",500);
	
	
	//Hacer visible la capa de mostrar imagen
	cuadro.style.display='block';
	
	//Epigrafe
	if(epigrafetxt!="")
		document.getElementById("epigrafeFoto").innerHTML=epigrafetxt;
	else if(epigrafeurl!="")
		llamarasincrono(epigrafeurl,"epigrafeFoto");
	
	
    //Capa a ocultar
	if(ocultar!="")
	{
		document.getElementById(ocultar).style.display="none";
		capaOculta=ocultar;
	}
}
var existeImagenTEMP=false;
function imagenload(img)
{
	if(!existeImagenTEMP)
	{
		//Precargamos la imagen
		impgPre = document.createElement('img');
		impgPre.id ='imagen_ampliada';
		impgPre.style.display="none";
		existeImagenTEMP=true;
	}
	impgPre.src=img+'?'+Math.random();
	impgPre.onload=function (){
	
	//Ubicar el marco en el centro de la pagina
	var ancho= impgPre.width+20;
	//cuadro.style.display='block';
	//cuadro.style.width=ancho+'px';
	//cuadro.style.height=alto+'px';
	//cuadro.style.top=document.documentElement.scrollTop;
	if(navigator.appName == "Microsoft Internet Explorer")
		cuadro.style.top =document.documentElement.scrollTop+"px";
	else
		cuadro.style.top = window.scrollY+"px";
	
	cuadro.style.left="50%";
	cuadro.style.marginLeft='-'+(ancho/2)+'px';
	cuadro.style.marginTop='50px';	
	cuadro.style.width=ancho;
	document.getElementById('epigrafeFoto').style.width=ancho+'px';
	
	imagen.style.padding="0px";
	document.getElementById('foto_ampliada').src=img;
	}
	
}
function cerrarampliar()
{	
	//document.getElementById('degrades').style.visibility="hidden"; 
	mostrar_ocultar_DEGRADES();
	document.getElementById('imagen_ampliada').style.display='none';
	if(capaOculta!="")
	{
		document.getElementById(capaOculta).style.display="block";
	}
}