// JavaScript Document
function Instalacoes(){
	this.foto = null;
	this.legenda = null;
	this.pasta = null;
	this.pastaRaiz = null;
	this.page = null;
	this.intervalo = null;
	
	this.width = screen.width;
	this.height = screen.height;
	/* Estrutura da pagina */
	this.iframe = null;
	this.bodyPage = document.body;
	this.bodyBlock = null;
	this.anterior = null;
	this.proximo = null;
	this.pagina = null;
	this.rodape = null;
	this.imagem = null;
	this.legendaD = null;
	this.span = null;
	this.marcador = null;
	this.fundoC = null;
	this.efeito = null;
	this.carregando = null;
	this.fechar = null;
	this.ifrm = null;
	/* Fim Estrutura da pagina */
}

Instalacoes.prototype.montaPagina = function(){
	if (this.indice == null) this.indice = 0;
	this.bodyBlock = document.createElement("div");
	this.bodyBlock.id = "bodyBlock";
	this.anterior = document.createElement("img");
	this.anterior.src = this.pastaRaiz+'anterior.jpg';
	this.anterior.style.position = 'absolute';
	this.anterior.style.left = '0';
	this.anterior.style.top = '0';
	this.anterior.style.cursor = 'pointer';
	this.anterior.style.visibility = 'hidden';
	this.proximo = document.createElement("img");
	this.proximo.src = this.pastaRaiz+'proximo.jpg';
	this.proximo.style.position = 'absolute';
	this.proximo.style.top = '0';
	this.proximo.style.right = '0px';
	this.proximo.style.visibility = 'hidden';
	this.proximo.style.cursor = 'pointer';
	
	this.pagina = document.createElement("div");
	this.pagina.id = "pagina";
	this.pagina.style.left = (((this.width/2)-365))+"px";
	
	this.imagem = document.createElement("img");
	this.imagem.className = 'foto';
	this.imagem.alt = '';
	this.imagem.title = '';
	this.imagem.style.visibility = 'hidden';
	
	this.fundoC = document.createElement("div");
	this.fundoC.id = "fundoControle";
	this.fundoC.innerHTML = "&nbsp;";
	
	this.efeito = document.createElement("div");
	this.efeito.id = "efeito";

	this.carregando = document.createElement("img");
	this.carregando.src = this.pastaRaiz+'carregando.gif';
	this.carregando.style.position = 'absolute';

	this.rodape = document.createElement("rodape");
	this.rodape.id = "paginaRodape";
	this.rodape.style.paddingTop = "10px";

	this.legendaD = document.createElement("div");
	this.legendaD.id = "paginaLegenda";
	
	this.legendaD.innerHTML = ((this.legenda.length == this.foto.length) ? this.legenda[this.indice] : this.legenda);
	this.span = document.createElement("span");
	this.span.innerHTML = '|';
	this.marcador = document.createElement("div");
	this.marcador.id = "paginaMarcador";
	
	this.marcador.innerHTML = this.foto.length > 1 ? ((this.indice+1)+' de '+this.foto.length) : "&nbsp;";
	if (this.foto.length > 1)
		this.span.style.display = "block";
	else
		this.span.style.display = "none";
	
	this.fechar = document.createElement("img");
	this.fechar.src = this.pastaRaiz+'icon_fechar.gif';
	this.fechar.style.position = 'absolute';
	this.fechar.style.right = '10px';
	this.fechar.style.cursor = 'pointer';
	
	this.ifrm = document.createElement("iframe");
	this.ifrm.id = 'ifrm';
	this.ifrm.name = 'ifrm';
	this.ifrm.frameBorder = "no";
	this.ifrm.src = this.page+"?dummy="+new Date().getTime();
	

	var x = this.criaObj(this.foto,this.legenda,this.pasta,this.pastaRaiz, this.indice,this.bodyBlock,this.anterior,this.proximo,this.pagina,this.rodape,this.imagem,this.legendaD,this.span,this.marcador,this.fundoC,this.efeito,this.carregando,this.fechar, this.ifrm, this.page, this.intervalo);
	/*->*/
	var carregandoI = document.createElement("img");
	setTimeout(function(){carregandoI.src = x.pastaRaiz+'carregando2.gif';},50);
	carregandoI.style.position = 'absolute';
	carregandoI.style.float = 'left';
	carregandoI.style.zIndex = '2';
	carregandoI.style.right = '70px';
	carregandoI.style.top = '170px';
	/*<-*/	

	this.addEvent(this.ifrm,"load",function(){ /*->*/ x.pagina.removeChild(carregandoI); /*<-*/ x.setaLinks(x)});
	
	setTimeout(function(){ x.imagem.src = x.pasta+x.foto[x.indice];},50);
	this.addEvent(this.imagem,"load",function(){
		x.pagina.style.top = ((x.getScrollXY()[1]+(x.height/3))-(x.imagem.height/2))+"px";
		x.pagina.style.width = (x.imagem.width+175)+"px";
		x.pagina.style.height = (x.imagem.height+30)+"px";
		x.fundoC.style.width = x.imagem.width+'px';
		x.fundoC.style.height = x.imagem.height+'px';
		x.efeito.style.width = x.imagem.width+'px';
		x.carregando.style.left = ((x.imagem.width/2)-(x.carregando.width/2))+'px';
		x.carregando.style.marginTop = ((x.imagem.height/2)-25)+'px';
		x.effect(0,'abrir',x);
		if (x.pagina.childNodes.length == 0){
			x.bodyPage.appendChild(x.bodyBlock);
			x.bodyPage.appendChild(x.pagina);
			x.pagina.appendChild(x.fundoC);
			x.fundoC.appendChild(x.imagem);
			x.fundoC.appendChild(x.anterior);
			x.fundoC.appendChild(x.proximo);
			x.fundoC.appendChild(x.efeito);
			x.efeito.appendChild(x.carregando);
			/*>-*/x.pagina.appendChild(carregandoI);/*<-*/
			x.pagina.appendChild(x.ifrm);
			x.pagina.appendChild(x.rodape);
			x.rodape.appendChild(x.legendaD);
			x.rodape.appendChild(x.span);
			x.rodape.appendChild(x.marcador);
			x.rodape.appendChild(x.fechar);
		
			x.setaAltura();
			x.fechar.onclick = function(){ x.effect(75,'opacidadeFechar',x); };
		}
	});
}


Instalacoes.prototype.setaAltura = function(){
	var ie = /msie/i.test(navigator.userAgent);
	var ieBox = ie && (document.compatMode == null || document.compatMode == "BackCompat");
	var canvasEl = ieBox ? document.body : document.documentElement;
	var h = window.innerHeight || canvasEl.clientHeight;

	if (h > document.documentElement.scrollHeight){
		this.bodyBlock.style.height = parseInt(document.documentElement.scrollHeight + (h - document.documentElement.scrollHeight)) + "px";
	}else
		this.bodyBlock.style.height = document.documentElement.scrollHeight + 'px';
}

Instalacoes.prototype.getScrollXY = function(){
	var scrOfX = 0;
	var scrOfY = 0;
	if (typeof(window.pageYOffset) == "number"){
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}else if (document.body && ( document.body.scrollLeft || document.body.scrollTop)){
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX,scrOfY];
}

Instalacoes.prototype.paginacao = function(sentido,obj){
	this.efeito.style.display = 'none';
	this.efeito.style.height = '0';
	clearTimeout(this.intervalo);
	if (sentido == "controlS"){
		this.indice = 0;
		this.foto = obj.foto;
		this.legenda = obj.legenda;
	}else if (sentido == "proximo")
		this.indice++;
	else
		this.indice--;
		
	if (this.indice == -1)
		this.indice = this.foto.length - 1;
	else if (this.indice == this.foto.length)
		this.indice = 0;

	if (this.foto.length > 1){
		this.anterior.onclick = function(){ obj.paginacao('anterior',obj);}
		this.proximo.onclick = function(){ obj.paginacao('proximo',obj);}
		this.imagem.onmousemove = function(event){  obj.mouse(event,obj) };
		this.anterior.onmousemove = function(event){ obj.mouse(event,obj) };
		this.proximo.onmousemove = function(event){ obj.mouse(event,obj) };
		this.imagem.onmouseout = function(){ obj.anterior.style.visibility = 'hidden';obj.proximo.style.visibility = 'hidden'; };
	}else{
		this.imagem.onmousemove = function(){ obj.anterior.style.visibility = 'hidden';obj.proximo.style.visibility = 'hidden'; };
		this.imagem.onmousemove = function(){ obj.anterior.style.visibility = 'hidden';obj.proximo.style.visibility = 'hidden'; };
		this.imagem.style.cursor = "default";
		this.imagem.onclick = function(){ void(0) };
	}

	this.marcador.innerHTML = (this.indice+1)+' de '+this.foto.length;
	this.legendaD.innerHTML = this.legenda[this.indice];
	if (this.legenda[this.indice] == null || this.legenda[this.indice] == "") 
		this.span.style.display = "none";
	else
		this.span.style.display = "block";

	obj.imagem.style.visibility = 'hidden';
	obj.efeito.style.display = 'block';
	setTimeout(function(){ obj.imagem.src = obj.pasta+obj.foto[obj.indice];	obj.imagem.alt = '';obj.imagem.title = ''; },50);
}

Instalacoes.prototype.closeP = function(obj){
	while(this.rodape.lastChild)
		this.rodape.removeChild(this.rodape.lastChild);
	while(this.efeito.lastChild)
		this.efeito.removeChild(this.efeito.lastChild);
	while(this.pagina.lastChild)
		this.pagina.removeChild(this.pagina.lastChild);
		
	this.bodyPage.removeChild(this.pagina);
	this.bodyPage.removeChild(this.bodyBlock);
}

Instalacoes.prototype.effect = function(i,funcao,obj){
	
	if (funcao == "abrir"){
		if (i <= this.imagem.height){
			this.effectT(i);
			this.intervalo = setTimeout(function(){obj.effect(i,funcao,obj); },0);
			i = i + 15;
		}else{
			clearTimeout(this.intervalo);
			this.intervalo = setTimeout(function(){ obj.effect(obj.imagem.height,'fechar',obj); } ,1000);
		}
	}
	if (funcao == "fechar"){
		if (i >= 0){
			this.effectT(i);
			this.intervalo = setTimeout(function(){ obj.effect(i,funcao,obj); },0);
			i = i - 15;
		}else{
			clearTimeout(this.intervalo);
			this.imagem.style.visibility = 'visible';
			this.efeito.style.display = 'none';
		}
	}
	if (funcao == "opacidadeFechar"){
		if (i > 0){
			this.effectO(i);
			i = i - 8;
			this.intervalo = setTimeout(function(){ obj.effect(i,funcao,obj);},5);
		}else{
			clearTimeout(this.intervalo);
			this.closeP(obj);
			try{
				objDGlobal.play(objDGlobal);
			}catch(e){};
		}
	}
}

Instalacoes.prototype.effectT = function(tamanho){this.efeito.style.height = tamanho+'px';}

Instalacoes.prototype.effectO = function(valor){
	this.bodyBlock.style.filter = 'alpha(opacity='+valor+')';
	this.bodyBlock.style.opacity = valor/100;
	this.pagina.style.filter = 'alpha(opacity='+valor+')';
	this.pagina.style.opacity = valor/100;
}


Instalacoes.prototype.addEvent = function(obj, evType, fn){
    if (obj.addEventListener)
        obj.addEventListener(evType, fn, true)
    if (obj.attachEvent)
        obj.attachEvent("on"+evType, fn)
}

Instalacoes.prototype.setaLinks = function(obj){
	var oDoc = this.ifrm.contentWindow || this.ifrm.contentDocument;
	
	if (oDoc.document)oDoc = oDoc.document.body.getElementsByTagName("a");
	
	this.addEvent(oDoc[0],"click",function(){
		obj.foto = ['fachada1.jpg','fachada2.jpg'];
		obj.legenda = ['','']; //legenda com vetor -> legenda para cada foto; legenda com atribuicao simples obj.legenda = 'a' -> legenda geral
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/fachada/';
		obj.paginacao('controlS',obj);
	});//fachada
	this.addEvent(oDoc[1],"click",function(){
		obj.foto = ['central1.jpg'];
		obj.legenda = [''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/jardim-central/';
		obj.paginacao('controlS',obj);
	});// jardim central
	this.addEvent(oDoc[2],"click",function(){
		obj.foto = ['biblioteca1.jpg','biblioteca2.jpg','biblioteca3.jpg','biblioteca4.jpg'];
		obj.legenda = ['','','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/biblioteca/';
		obj.paginacao('controlS',obj);
	}); // biblioteca
	this.addEvent(oDoc[3],"click",function(){
		obj.foto = ['cantina1.jpg','cantina2.jpg','cantina3.jpg','cantina4.jpg'];
		obj.legenda = ['','','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/cantina/';
		obj.paginacao('controlS',obj);
	}); // Praça de alimentacao
	this.addEvent(oDoc[4],"click",function(){
		obj.foto = ['clinica1.jpg','clinica2.jpg','clinica3.jpg','clinica4.jpg'];
		obj.legenda = ['','','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/clinica/';
		obj.paginacao('controlS',obj);
	}); // Clínica multidisciplinar
	this.addEvent(oDoc[5],"click",function(){
		obj.foto = ['ginasio1.jpg','ginasio2.jpg','ginasio3.jpg','ginasio4.jpg','ginasio5.jpg'];
		obj.legenda = ['','','','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/ginasio/';
		obj.paginacao('controlS',obj);
	}); // Ginásio de esporte
	this.addEvent(oDoc[6],"click",function(){
		obj.foto = ['campo1.jpg','campo2.jpg','campo3.jpg'];
		obj.legenda = ['','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/campo/';
		obj.paginacao('controlS',obj);
	}); // Campo de futebol
	this.addEvent(oDoc[7],"click",function(){
		obj.foto = ['piscina1.jpg','piscina2.jpg','piscina3.jpg','piscina4.jpg','piscina5.jpg'];
		obj.legenda = ['','','','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/piscinas/';
		obj.paginacao('controlS',obj);
	}); // piscinas
	this.addEvent(oDoc[8],"click",function(){
		obj.foto = ['pista1.jpg'];
		obj.legenda = [''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/pista/';
		obj.paginacao('controlS',obj);
	}); // pista de atletismo
	this.addEvent(oDoc[9],"click",function(){
		obj.foto = ['academia1.jpg','academia2.jpg','academia3.jpg','academia4.jpg','academia5.jpg'];
		obj.legenda = ['','','','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/academia/';
		obj.paginacao('controlS',obj);
	}); // acadmia
	this.addEvent(oDoc[10],"click",function(){
		obj.foto = ['anatomia1.jpg','anatomia2.jpg','anatomia3.jpg'];
		obj.legenda = ['','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/anatomia/';
		obj.paginacao('controlS',obj);
	}); // Anatomia e biologia
	this.addEvent(oDoc[11],"click",function(){
		obj.foto = ['info1.jpg','info2.jpg','info3.jpg'];
		obj.legenda = ['','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/informatica/';
		obj.legenda = ['',''];
		obj.paginacao('controlS',obj);
	}); // Informatica
	this.addEvent(oDoc[12],"click",function(){
		obj.foto = ['linguas1.jpg','linguas2.jpg'];
		obj.legenda = ['',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/linguas/';
		obj.paginacao('controlS',obj);
	}); // Linguas
	this.addEvent(oDoc[13],"click",function(){
		obj.foto = ['nutricao1.jpg','nutricao2.jpg','nutricao3.jpg'];
		obj.legenda = ['','',''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/nutricao/';
		obj.paginacao('controlS',obj);
	}); // Nutricao
	this.addEvent(oDoc[14],"click",function(){
		obj.foto = ['analisefisica1.jpg'];
		obj.legenda = [''];
		obj.pasta = 'http://www.claretiano.edu.br/instalacoes/imagens/analisefisica/';
		obj.paginacao('controlS',obj);
	}); // Analise Fisica
}

Instalacoes.prototype.mouse = function(e,obj){
	if (!e) var e = window.event;
	var pos = e.screenX;
	
	var centro = ((this.width/2)-400)+300;
	
	if (pos > centro+25){
		this.anterior.style.visibility = 'hidden';
		this.proximo.style.visibility = 'visible';
		this.imagem.onclick = function(){ obj.paginacao('proximo',obj);}
		this.imagem.style.cursor = 'pointer';
	}else if (pos < centro-25){
		this.anterior.style.visibility = 'visible';
		this.proximo.style.visibility = 'hidden';
		this.imagem.onclick = function(){ obj.paginacao('anterior',obj);}
		this.imagem.style.cursor = 'pointer';
	}else{
		this.imagem.style.cursor = 'auto';
		this.anterior.style.visibility = 'hidden';
		this.proximo.style.visibility = 'hidden';
		this.imagem.onclick = function(){ void(0);}
	}
}

Instalacoes.prototype.criaObj = function(foto,legenda,pasta,pastaRaiz,indice,bodyBlock,anterior,proximo,pagina,rodape,imagem,legendaD,span,marcador,fundoC,efeito, carregando,fechar,ifrm,page,intervalo){
	var obj = new Instalacoes();	
	
	obj.foto = foto;
	obj.legenda = legenda;
	obj.pasta = pasta;
	obj.pastaRaiz = pastaRaiz;
	obj.indice = indice;
	obj.page = page;
	obj.intervalo = intervalo;
	
	/* Estrutura da pagina */
	obj.bodyBlock = bodyBlock;
	obj.anterior = anterior;
	obj.proximo = proximo;
	obj.pagina = pagina;
	obj.rodape = rodape;
	obj.imagem = imagem;
	obj.legendaD = legendaD;
	obj.span = span;
	obj.marcador = marcador;
	obj.fundoC = fundoC;
	obj.efeito = efeito;
	obj.carregando = carregando;
	obj.fechar = fechar;
	obj.ifrm = ifrm;
	/* Fim Estrutura da pagina */	
	return obj;
}