/*
Titulo: Efecto Lightbox
Autor:Ignacio Jacob Gonz‡lez PŽrez
Empresa: Smartcomtec
Fecha: 9-oct-08
Version: 1.1



*/

var objetoOriginal=null;

function showLightBox(id){
	closeLightBox();
	//creacion de la pantalla negra
	var cuerpo=document.body;
	var pantalla=document.createElement("div");
	var alturaDocumento=getWindowHeight();
	
	getWindowHeight();
	
	pantalla.id="pantalla0101";
	pantalla.style.background="black";
	pantalla.style.position="absolute";
	pantalla.style.zIndex="9800";
	pantalla.style.width="100%";
	pantalla.style.height=alturaDocumento+"px";
	pantalla.style.top="0";
	pantalla.style.left="0";
	pantalla.style.right="0";
	pantalla.style.bottom="0";
	pantalla.style.opacity=0.0;
	pantalla.style.filter="alpha(opacity=0)";
	pantalla.style.top=getWindowTopScroll()+"px";

	
	
	window.onresize=function(){
		var altowindow=getWindowHeight();
		pantalla.style.height=altowindow+"px";
	}
	
	window.onscroll=function(){
		var topscroll=getWindowTopScroll();
		pantalla.style.top=topscroll+"px";
		}
		
	
		
	cuerpo.appendChild(pantalla);

	//asignacion de transparencia en fracciones de segundo
	var pasos=20;// cantidad de pasos para llegar al limite de transparencia
	var transparencia=0.8;// transparencia final de la pantalla negra
	var tiempo=0;
	for(var i=0;i<=pasos;i++){
		var fraccion = transparencia/pasos;
		var opacidad=i*fraccion;
		tiempo=i*12;
		setTimeout("pantSetOpac("+opacidad+",'pantalla0101')",tiempo);

	}
	
	
	//transformacion del div elegido
	var ventana=document.getElementById(id);
	var altura=ventana.offsetHeight;
	var anchura=ventana.offsetWidth;
	//alert(anchura);
	setTimeout("groundWhiteWindow("+altura+","+anchura+",'"+id+"')",tiempo);
	//groundWhiteWindow(altura,anchura)
	
	
	

}
function getWindowHeight(){
	var altura=0;
	if(checkNavigator()=="opera" ){
			altura=document.body.clientHeight;
	}else{
			altura=document.documentElement.clientHeight;
	}
	return(altura);
}
function getWindowTopScroll(){
	var scrollTop=0;
	if(checkNavigator()=="safari" ){
		scrollTop=document.body.scrollTop;
	}else{
		scrollTop=document.documentElement.scrollTop;

	}
	return(scrollTop);
}


function checkNavigator(){
	var navnombre=navigator.userAgent;
	var nombrereal="";
	if(navnombre.indexOf("Mozilla")!=-1) nombrereal="firefox";
	if(navnombre.indexOf("Opera")!=-1)  nombrereal="opera";
	if(navnombre.indexOf("Safari")!=-1)  nombrereal="safari";
	if(navnombre.indexOf("MSIE")!=-1)  nombrereal="explorer";
	if(navnombre.indexOf("MSIE 6")!=-1)  nombrereal="explorer 6";
	if(navnombre.indexOf("MSIE 7")!=-1)  nombrereal="explorer 7";
	return(nombrereal);
	}
function groundWhiteWindow(alto,ancho,selectedDiv){
	
	var cuerpo=document.body;
	var whiteWindow=document.createElement("div");
	var divOriginal=document.getElementById(selectedDiv);
	whiteWindow.id="pantalla0202";
	whiteWindow.style.background="white";
	whiteWindow.style.zIndex="9900";

	whiteWindow.style.margin="auto";
	whiteWindow.style.position="absolute";
	whiteWindow.style.width="1px";
	whiteWindow.style.height="1px";
	whiteWindow.style.left="50%";
	whiteWindow.style.top="50%";
	

	whiteWindow.style.marginLeft="0px";
	whiteWindow.style.marginTop=(-(alto/2))+"px";;
	
	
	cuerpo.appendChild(whiteWindow);
	
	var pasos=30;// cantidad de pasos para llegar al limite de altura
	var tiempo=0;
	for(var i=0;i<=pasos;i++){
		var altofraccion = alto/pasos;
		var anchofraccion =ancho/pasos;
		var transpfraccion = 1/pasos;
		
		var alturaTot=i*altofraccion;
		var anchoTot=i*anchofraccion;
		var transpTot=i*transpfraccion;
		//	alert(alturaTot);
		tiempo=i*12;
		setTimeout("setHeight("+alturaTot+",'pantalla0202')",tiempo);
		setTimeout("setWidth("+anchoTot+",'pantalla0202')",tiempo+200);
		setTimeout("setLeftMargin("+anchoTot+",'pantalla0202')",tiempo+200);
		setTimeout("pantSetOpac("+transpTot+",'pantalla0202')",tiempo*2.5);
	}
	setTimeout("showWindowDiv('"+selectedDiv+"',"+ancho+","+alto+")",tiempo+250);

	
	
}
function showWindowDiv(objeto,anchura,altura){
	var ventana=document.getElementById(objeto);
	var copia=ventana;
	//var copia=ventana.cloneNode(false);
	objetoOriginal = ventana;
	
	//alert(objetoOriginal);
	
	document.body.appendChild(copia);
	//copia.id="pantalla0303";
	copia.innerHTML=ventana.innerHTML;
	copia.style.zIndex="10000";
	copia.style.position="absolute";
	copia.style.top="50%";
	copia.style.left="50%";
	copia.style.marginLeft=(-(anchura/2))+"px";
	copia.style.marginTop=(-(altura/2))+"px";
	copia.style.display="block";
	copia.style.visibility="visible";
	pantSetOpac(0.0,'pantalla0303');
	
	
	var pasos=20;// cantidad de pasos para llegar al limite de transparencia
	var tiempo=0;
	for(var i=0;i<=pasos;i++){
		var transpfraccion = 1/pasos;
		
		var transpTot=i*transpfraccion;
		tiempo=i*12;
		setTimeout("pantSetOpac("+transpTot+",'pantalla0303')",tiempo);
	}
}

//funciones para controlar temporalmente 
function pantSetOpac(opacidad,objeto,browser){
	var pantalla=document.getElementById(objeto);
	pantalla.style.opacity=opacidad;
	
	var opacidadIE=opacidad*100;
	pantalla.style.filter="alpha(opacity='"+opacidadIE+"')";
}

function setHeight(altura,objeto){
	var whiteWindow=document.getElementById(objeto);
	whiteWindow.style.height=altura+"px";
}
function setWidth(anchura,objeto){
	var whiteWindow=document.getElementById(objeto);
	whiteWindow.style.width=anchura+"px";
	
	
}
function setLeftMargin(anchura,objeto){
//alert("asd");
	var whiteWindow=document.getElementById(objeto);
	//whiteWindow.style.height=altura+"px";
	whiteWindow.style.marginLeft=(-(anchura/2))+"px";
}

function closeLightBox(){
	//alert(objetoOriginal);
	var original=objetoOriginal;
	//var original=document.getElementById("pantalla0303");
	var pantallaNegra=document.getElementById("pantalla0101");
	var pantallaBlanca=document.getElementById("pantalla0202");
	if(pantallaNegra!=undefined) document.body.removeChild(pantallaNegra);
	if(pantallaBlanca!=undefined) document.body.removeChild(pantallaBlanca);
	//if(original!=undefined) document.body.removeChild(original);
	if(original!=undefined) original.style.visibility = "hidden";
}


function setMargin(anchura,objeto){
	var whiteWindow=document.getElementById(objeto);
	whiteWindow.style.marginLeft=anchura+"px";
	
	
}

function gradientSetWidth(ancho,objeto){
	var anchoneg=ancho*-1;
	
	var pasos=46;// cantidad de pasos para llegar al limite de altura
	var tiempo=0;
	for(var i=0;i<pasos;i++){
			var anchofraccion =ancho/pasos;
			
			anchoneg+=anchofraccion;
			tiempo=i*12;
			setTimeout("setMargin("+anchoneg+",'"+objeto+"')",tiempo);
		}
	
	}