// JavaScript Document

var class_revix = function(){
	
	var $browserName = (navigator.appName.indexOf('Netscape') > -1) ? 'NS' : 'IE';
	
	/*tamanho da janela*/
	if($browserName == 'NS'){
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;			
	}else{
		winWidth = document.documentElement.offsetWidth;
		winHeight = document.documentElement.offsetHeight;
	}
	
	/*metodo para troca BG de um objeto (DIV)
		PARAMENTROS
		EL = String : ID do Elemento conteiner da imagem
		ImgPath = String : Diretorio raiz das imagens
		ImgList = Vetor : lista de imagens
		Speed = Intever : velociadade da exibição [1..N] 'segungos
	*/
	this.slideShow = function(El, ImgPath, ImgList, Speed){		
		var $El = document.getElementById(El);		
		//ajusta ao tamanho da tela
		if ($El.tagName != "body"){
			$El.style.position = 'absolute';
			$El.style.zIndex = -1;
			$El.style.width = '100%';
			$El.style.height = winHeight + 'px';
			window.onresize = function(){
				$El.style.height = winHeight + 'px';
			}
		}		
		//Inicia randomicamente
		$El.style.background = "#000 URL('" + ImgPath + '/' + ImgList[0] + "') no-repeat fixed center";		
		var k=1;
		var $slide = setInterval(
									function(){
										if (k<ImgList.length){																			
											var $imgSrc = ImgPath + '/' + ImgList[k];
											var imgBck = new Image();
											imgBck.src = $imgSrc;
											$El.style.background = "#000 url('" + $imgSrc + "') no-repeat fixed center";
											if($browserName == "NS"){ $El.style.opacity = .0; }else{ $El.style.filter = "alpha(opacity=0)";}			
											var j = 0;
											var $Alpha = setInterval(
																				function(){						
																					if (j<=10){
																						if($browserName == 'NS'){	$El.style.opacity = (j/10); }else{ $El.style.filter = 'alpha(opacity=' + (j*10) + ')'; }																								
																					}else{
																						clearInterval($Alpha);
																					}													
																					j++	;
																				}
																			,50);
											k++;
										}else{
											k=0;
										}
									}
								,(Speed * 1000));
	},
	
	this.sliceBox = function(urlLoad, act, css){
		/*tamanho da janela*/
		var wHeight = document.body.offsetHeight;
		var wHeight = document.documentElement.clientHeight;
		var wWidth = document.body.offsetWidth;

		//cria o elemento conteiner
		var targ = document.createElement('div');
				targ.setAttribute('id','sliceBox');
				targ.setAttribute('class',css);
				targ.className = css;
				targ.style.width = 0;
				targ.style.overflow = 'hidden';
				targ.style.position = 'absolute';
		
		var targ_child = document.createElement('div');
				targ_child.setAttribute('id','sliceBox_frame');
				
		//variavel contadora 
		var i = 0;
		
		function __show(){
			//insere o element no NODE do body, caso ele nao exista			
			document.body.appendChild(targ);
			targ.appendChild(targ_child);
		
			//executar efeito de exibição
			var exec = setInterval(
									function(){					
										if(i<wWidth){											
											i= i+30;
											//centraliza o objeto na tela
											var objH = document.getElementById('sliceBox').offsetHeight;
											document.getElementById('sliceBox').style.top = parseInt((wHeight/2)-(objH/2) - 25) + 'px';
											//redimensiona o objete
											document.getElementById('sliceBox').style.width = i + 'px';
										}else{
											//fixa a largura do elemento
											document.getElementById('sliceBox').style.width = wWidth + 'px';										
											//carregar conteudo html
											AjaxLoad(urlLoad, 'sliceBox_frame',true);
											//interrompe o processo
											clearInterval(exec);
										}					
									}
								 ,1);
		}
		
		function __hidden(){
			i = wWidth;
			document.getElementById('sliceBox').innerHTML = '';
			document.getElementById('sliceBox').style.right = 0;
			//executar efeito de ocultação
			var exec = setInterval(
										function(){					
										if(i>0){											
											document.getElementById('sliceBox').style.width = i + 'px';
											i= i-30;						
										}else{
											document.body.removeChild(document.getElementById('sliceBox'));
											clearInterval(exec);
										}
									}
								,1);
		}
		
		if (act=='show'){
			if(!document.getElementById('sliceBox')){
				__show();
			}else{
				__hidden();
				var $interval = setInterval(
													function(){
														if (i<=0){ 
															__show();																												
															clearInterval($interval);
														}
													}
												, 1);
			}
		}else{
			__hidden();
		}		
	},
	
	this.lightBox = function(img, maxW){
		var $ImgBox = document.createElement("img");
		with($ImgBox){
			setAttribute('id', '$ImgLightBox');
			setAttribute('src', img.src);
			setAttribute('title', 'Clique para fechar');
			style.cursor = 'pointer';
			style.zIndex = '100';
			style.position = 'absolute';
			style.opacity = 0;
		}		
		document.body.appendChild($ImgBox);
		$ImgBox.style.top = (winHeight/2)-($ImgBox.offsetHeight/2) + 'px';
		$ImgBox.style.left = (winWidth/2)-($ImgBox.offsetWidth/2) + 'px';
		
		overLay('create',90);
		
		var a = 0;
		var $Alpha = setInterval(function(){
								 	if(a<=10){										
										if($browserName == 'NS'){	$ImgBox.style.opacity = (a/10); }else{ $ImgBox.style.filter = 'alpha(opacity=' + (a*10) + ')'; }	
										a++;
									}else{
										clearInterval($Alpha);
									}
								 },100);
								 
		//ao clicar
		$ImgBox.onclick = function(){	
			overLay('distroy');
			document.body.removeChild($ImgBox);
		}
		
	}
		
	/*Método de instância do Objeto HTTPREQUEST (Ajax)
		PAREMETROS
		Nenhum
	*/
	objAjax = function(){
		var xmlHttp;		
		try{ 
			xmlHttp = new XMLHttpRequest();
		}catch (e){			
			try{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e){
				try{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e){
					alert("Seu navegador não dá suporte a tecnologia AJAX");
					return false;
				}
			}
		}		
		return xmlHttp;
	},
	
	/*Método para carregar conteudo HTML através de HTTPREQUEST
		PARAMETROS
		URL = String : URL do documento HTML a ser carregado
		TARGET = String : ID do objeto onde será retornado o conteudo carregado
	*/
	
	AjaxLoad = function(url, target, showAlpha){		
		var $Ajax = objAjax();
		var targ = document.getElementById(target);
		$Ajax.onreadystatechange = function(){
				if($Ajax.readyState != 4){	
					targ.innerHTML = "Carregando..." ;
				}else{										
					targ.innerHTML = $Ajax.responseText;
					doScript($Ajax.responseText);					
					//exibe a janela graduativamento									
					if (typeof(showAlpha)=='undefined' || showAlpha!=false){
						if($browserName == "NS"){ targ.style.opacity = .0; }else{ targ.style.filter = "alpha(opacity=0)";}			
						var i = 0;
						var $Alpha = setInterval(
															function(){						
																if (i<=10){
																	if($browserName == 'NS'){	targ.style.opacity = (i / 10); }else{ targ.style.filter = 'alpha(opacity=' + (i*10) + ')'; }																								
																}else{
																	clearInterval($Alpha);
																}													
																i++	;
															}
														,100);
					}
					return false;					
				}
			}		
			with ($Ajax){
				open("GET", url, true);
				send(null);
			}
	},
	
	overLay = function(action, levelAplha){
		//cria a overlay
		if (action=='create'){
			var $overlay = document.createElement('div');
			with ($overlay){
				setAttribute('id', '$revixOverLay');
				style.position = 'absolute';
				style.background = '#000';
				style.opacity = .0;
				style.width = '100%';
				style.zIndex = 99;
				style.height = winHeight + 'px';
				window.onresize = function(){
					$El.style.height = winHeight + 'px';
				}
			}	
			if(!document.getElementById('$revixOverLay')){
				document.body.appendChild($overlay);
				var o = 0;
				var $alpha = setInterval(function(){
												if(o <= (levelAplha/10)){
													if($browserName == 'NS'){	$overlay.style.opacity = (o/10); }else{ $overlay.style.filter = 'alpha(opacity=' + (o*10) + ')'; }	
													o++;
												}else{
													clearInterval($alpha);
												}
											}
										 ,100);
			}
		}else{
			if(document.getElementById('$revixOverLay')){
				document.body.removeChild(document.getElementById('$revixOverLay'));
			}
		}
	}
	
}

