// JavaScript Document


////Solution 4 Web

function tamanhoDivFundo()
{
    
	document.getElementById('divFundo').style.width=  "770px";
	document.getElementById('divFundo').style.height = document.body.offsetHeight + 'px';	

}

function Loading()
{
	showLoading(); // chame sua função de mostrar camada de loading aqui
	
	if(!document.getElementById("fig").complete)
	{
		setTimeout("Loading()",1);
	}
	else
	{
		hideLoading();		
		verImagem();
	}

}

function showLoading()
{
	document.getElementById('loading').style.display="";
	//document.getElementById('divGaleria').style.display="none";
}

function hideLoading()
{
	document.getElementById('loading').style.display="none";
	document.getElementById('divCentral').style.display="";
}



////Função a ser chamada para iniciar o efeito
////Ela Preenche o valor das variaveis de acordo com a imagem passada
function Iniciar(imagem,altura,largura,anterior,proximo,numeroFotos,idCartao,legenda){
	tamanhoDivFundo();
	
	//mTop = document.body.offsetHeight/2;
	//mLeft = document.body.offsetWidth/2;
	
	mTop = (altura/2) - document.documentElement.scrollTop;
	mLeft = (largura/2);
	
	if(document.getElementById('linkEnviar')!=null)
	{
	    document.getElementById('linkEnviar').href = "CartaoPostalEnviar.aspx?id="+idCartao;
	}
	
	document.getElementById('divNumeroFotos').innerHTML = numeroFotos;
		
	document.getElementById('loading').style.margin =  (altura/2)-60 + "px";
	//document.documentElement.scrollTop
		
	document.getElementById('divCentral').style.display="";
	
	altura = parseInt(altura) + 80; 
	
	if(screen.height>600)
	{
	   mTop+= 50;
	}
	
	document.getElementById('divCentral').style.height= altura  + "px";
	document.getElementById('divCentral').style.margin=""+-mTop+"px "+0+"px "+0+"px "+-mLeft+"px";
	document.getElementById('divImagem').innerHTML='';
	//document.getElementById('divImagem').innerHTML='<img name="fig" width="'+ largura +'" height="'+ altura +'" id="fig" src="'+imagem+'" />';
    document.getElementById('divImagem').innerHTML='<img name="fig" id="fig" src="'+imagem+'" />';
    document.getElementById('lblLegenda').innerHTML = legenda;
    
	lProximo=proximo;
	lAnterior=anterior;
	
	document.getElementById('fig').style.display="none";
	document.getElementById('divFundo').style.display="";
	document.getElementById('divImagem').style.display="";	
	document.getElementById('linkAnterior').href="";
	document.getElementById('linkProximo').href="";
	document.getElementById('linkAnterior').style.display="none";
	document.getElementById('linkProximo').style.display="none";
    
    		
	document.getElementById('divGaleria').style.display="";
	document.getElementById('divFechar').style.display="";
	verificarGaleria();
       
	Loading();
}

///Função que realiza a ação de fechar, ou seja, esconder as divs
function fechar()
{
		document.getElementById('divImagem').style.display="none";
		document.getElementById('divFechar').style.display="none";
		document.getElementById('divCentral').style.display="none";
		document.getElementById('divFundo').style.display="none";
}

function verificarGaleria()
{
	if(lAnterior!="")
	{
		document.getElementById('linkAnterior').href=document.getElementById(lAnterior).href;
		document.getElementById('linkAnterior').style.display="";
	}
	if(lProximo!="")
	{
		document.getElementById('linkProximo').href=document.getElementById(lProximo).href;
		document.getElementById('linkProximo').style.display="";	
	}
}	
	
function verImagem()
{
    document.getElementById('divCentral').style.height= 'auto';
	document.getElementById('divGaleria').style.display="";
	document.getElementById('fig').style.display="";
	document.getElementById('divImagem').style.display="";
}

window.onresize = tamanhoDivFundo;

//////////////////////////////////////////////////////////////////////////////////////

function IniciarVideo(altura,largura)
{
	tamanhoDivFundo();
	
	
	mTop = (altura/2) - document.documentElement.scrollTop;
	mLeft = (largura/2);
	
	document.getElementById('divCentral').style.display="";
	
	altura = parseInt(altura) + 80; 
	
	if(screen.height>600)
	{
	   mTop+= 50;
	}
	
	document.getElementById('divCentral').style.height= altura  + "px";
	document.getElementById('divCentral').style.margin=""+-mTop+"px "+0+"px "+0+"px "+-mLeft+"px";
	document.getElementById('divGaleria').style.display="";

	document.getElementById('divFechar').style.display="";
	document.getElementById('divFundo').style.display="";
	
}	
	