// JavaScript Document
function Cargador(){
	this.cambiando = 0;
	this.ocurrio = 0;
}
Cargador.prototype.tomarDimension = function(div,objeto){
	var principal = document.getElementById(div);	
	objeto.div = principal;
	objeto.alto = principal.offsetHeight;
	objeto.ancho = principal.offsetWidth;
}
Cargador.prototype.crearOpacity = function(div,objeto,divContenedor){
	objeto.intervalo = setInterval(function(){objeto.crearOpacity2(div,objeto,divContenedor)},100);	
}
Cargador.prototype.crearOpacity2 = function(div,objeto,divContenedor){
	var cont = document.getElementById(div);
	var cont2 = document.getElementById(divContenedor);
	if(cont && cont2){
		clearInterval(objeto.intervalo);
		if(cont2.childNodes[0].id){
			if(cont2.childNodes[0].innerHTML != "")objeto.crearEstructura(div,objeto,divContenedor);
		}
		else{
			if(cont2.childNodes[1])if(cont2.childNodes[1].innerHTML != "")objeto.crearEstructura(div,objeto,divContenedor);
		}
	}
	if(this.cont)if(this.cont.style.visibility == 'hidden')this.cont.style.visibility = "visible";
	contenedor.style.visibility = "visible";
}
Cargador.prototype.crearEstructura = function(div,objeto,divContenedor){
	
	var principal = document.createElement("div");
	var hijo1 = document.createElement("div");
	var hijo2 = document.createElement("iframe");
	principal.style.position = "absolute";
	hijo1.style.position = "absolute";
	hijo2.style.position = "absolute";	
	objeto.tomarDimension(div,objeto);
	principal.style.height = objeto.alto+"px";
	principal.style.width = objeto.ancho+"px";	
	hijo1.style.height = objeto.alto+"px";
	hijo1.style.width = objeto.ancho+"px";	
	hijo2.style.height = objeto.alto+"px";
	hijo2.style.width = objeto.ancho+"px";	
	hijo2.frameBorder = 0;
	hijo1.style.filter="alpha(opacity=100)";
	hijo2.style.filter="alpha(opacity=100)";	
	hijo1.style.MozOpacity = 0.999;
	hijo2.style.MozOpacity = 0.999;
	hijo2.style.zIndex = 2;
	hijo1.style.zIndex = 3;
	hijo1.style.overflow = "hidden";
	var cont = document.getElementById(divContenedor);
	this.cont = cont;
	var navegador = 0;
	if(cont.childNodes[1])navegador=1;
	hijo1.appendChild(cont.childNodes[navegador]);
	objeto.navegador = navegador;
	cont.innerHTML = "";
	principal.appendChild(hijo1);
	principal.appendChild(hijo2);
	principal.style.top = 0;
	principal.style.left = 0;
	hijo1.style.top = 0;
	hijo1.style.left = 0;
	hijo2.style.top = 0;
	hijo2.style.left = 0;
	principal.style.visibility = "hidden";
	objeto.principal = principal;
	objeto.hijo1 = hijo1;
	objeto.hijo2 = hijo2;
	document.body.appendChild(principal);
	objeto.CentrarLayer(objeto);
}
Cargador.prototype.CentrarLayer = function(objeto){
	var element = objeto.principal;
	if(element.style.visibility=='hidden'){
		
		var pos = objeto.getScrollPos();
		var dim = objeto.getWindowDims();
		
		var height = element.offsetHeight;
		var width = element.offsetWidth;
		
		if(Nav.esIE7) dim.w = document.documentElement.clientWidth;
		
		element.style.left = (((dim.w-width)/2)+pos.x)+"px";
		//element.style.top = (((dim.h-height)/2)+pos.y)+"px";
		element.style.visibility = 'visible';
	}
	else element.style.visibility = 'hidden';
}
//
Cargador.prototype.getScrollPos = function(){
	if(Nav.esOp) return {y:window.pageYOffset, x:window.pageXOffset};
	else if(Nav.esMz || Nav.esIE) return {y:document.documentElement.scrollTop, x:document.documentElement.scrollLeft};
	else return {x:0, y:0};
}
Cargador.prototype.getWindowDims = function(){
	if(Nav.esOp) return {w:window.innerWidth, h:window.innerHeight, a:'a'};
	else if(Nav.esMz || Nav.esIE) return {w:document.documentElement.clientWidth, h:document.documentElement.clientHeight};
	else return {w:0, h:0}
}
Cargador.prototype.sacarOpacity = function(objeto){
	if(objeto.hijo1){
		var inte = 0;
		if(objeto.ocurrio == 1)inte = 10;
		else{
			objeto.ocurrio = 1;
			var inte = 1000;
		}		
		if(objeto.navegador == 0){
			var val = objeto.obtenerNumero(objeto.hijo1.style.filter);
			if((val - 10) > 0){
				objeto.hijo1.style.filter = "alpha(opacity="+(val-10)+")";
				objeto.hijo2.style.filter = "alpha(opacity="+(val-10)+")";
				objeto.intervalo = setTimeout(function(){objeto.sacarOpacity(objeto)},inte);
			}
			else{
				if(objeto.hijo1)objeto.hijo1.style.filter = "alpha(opacity="+(0)+")";
				if(objeto.hijo2)objeto.hijo2.style.filter = "alpha(opacity="+(0)+")";			
				if(objeto.principal)objeto.principal.style.display  = "none";
				objeto.principal = null;
				objeto.hijo1 = null;
				objeto.hijo2 = null;
			}
		}
		else{
			var valor = parseFloat(parseFloat(objeto.hijo1.style.MozOpacity)-.10);
			if(valor >0){
				objeto.hijo1.style.MozOpacity = parseFloat(valor);
				objeto.hijo2.style.MozOpacity = parseFloat(valor);
				objeto.intervalo = setTimeout(function(){objeto.sacarOpacity(objeto)},inte);
			}
			else{
				objeto.hijo1.style.MozOpacity = 0;
				objeto.hijo2.style.MozOpacity = 0;
				if(objeto.principal)objeto.principal.style.display = "none"; 
				objeto.principal = null;
				objeto.hijo1 = null;
				objeto.hijo2 = null;
			}
		}
	}
}
Cargador.prototype.obtenerNumero = function(valor){
	var primer = valor.split("=");
	var segundo = primer[1].split(")");
	return parseInt(segundo);
}