	//Array com todas as janelas abertas
	var janelasAbertas = new Array();
	
	function tamanhoJanela(tipojanela){
		
		//criando variavel altura do navegador
		var alturautilNavegador = 0;
		
		//verifiando se o browser é IE, caso for pega a area util do navegador IE, caso contrário pega o do firefox.
		if(navigator.appName =='Microsoft Internet Explorer'){/* pode ser assim tb: if(typeof( window.innerWidth ) !='number'), dae não é firefox */
			//alert('Internet Explorer');
			alturaUtilNavegador = document.body.clientHeight;
		}else{
			//alert(navigator.appName);
			alturaUtilNavegador = window.innerHeight;
		}
		
		
		var alturaJanela = document.getElementById(tipojanela).offsetHeight;//Altura da janela
		alturaUtilNavegador -= 40;
		if(alturaJanela > alturaUtilNavegador ){
			var idScroll = tipojanela+"scroll";
			var alturaScroll = document.getElementById(idScroll).offsetHeight;
			var redimensionar = alturaScroll - (alturaJanela - alturaUtilNavegador);
			document.getElementById(idScroll).style.height = redimensionar;
			document.getElementById(idScroll).style.width = document.getElementById(idScroll).offsetWidth+20;
		}
	}
	
	//Função para centralizar a pagina na tela
	function mostraDiv(idDiv){
		document.getElementById(idDiv).style.marginTop = -600;
		document.getElementById(idDiv).style.marginLeft = -600;
		document.getElementById(idDiv).style.display = "block";
		//Centraliza a janela no meio da tela
		tamanhoJanela(idDiv);
		//alert(document.getElementById(idDiv).offsetWidth);
		document.getElementById(idDiv).style.marginTop = -((document.getElementById(idDiv).offsetHeight/2) - ((document.all)?document.body.scrollTop:window.pageYOffset));
		document.getElementById(idDiv).style.marginLeft = -( document.getElementById(idDiv).offsetWidth /2);
	}
	
	//função para fechar o div
	function fechaDiv(idDiv)
	{
		document.getElementById(idDiv).style.display = "none";	
	}
	
	//Abre as janelas uma por cima da outra, coloca o zindex da que está embaixo com 0, fazendo com que a outra fique por cima, 
	//nome do div tb fica com o nome do tipojanela
 	function abrirJanela(tipojanela,parametros){		
		if(janelasAbertas.length>0){
			for(i=0;i<janelasAbertas.length;i++){
				$(janelasAbertas[i]).style.zIndex = 1;
			}
		}

		peliculaTela.display();
		mostraDiv("carregando");
		
		/* 
			*** Para não ter que ficar dando escape() nos parâmetros passados faz-se o seguinte, var par recebe parametros quebrados no &,
			*** percorre-se esse array par(split('&') com isso torna-se um array) fazendo a mesma coisa na var parunico separados por =,
			*** depois novoparametros recebe nome do atributo concatenado com seu valor(parunico[0]+'='+escape(parunico[1])), e a cada ite-
			*** ração do forverifica se novoparametros != "", caso sim é pq temos um novo parâmetro então concatena-se com &.
			*** Ex. nome=teste&idade=25  => nome=Teste|&|idade=24 => nome|=|Teste, idade|=|24
		*/
		
		
		var novoparametros = '';
		var par = parametros.split('&');
		for(var i = 0; i < par.length; i++){
			var parunico = par[i].split('=');
			if(novoparametros!=''){
				novoparametros += '&';
			}

			novoparametros += parunico[0]+'='+escape(parunico[1]);
		}
		
		//Envia para conteudojanela.php tipojanela e parametros se houver
		var url = "janelas/conteudojanela.php?"+antiCache()+"&tipojanela="+tipojanela;
		if(parametros!=""){
			url += "&"+novoparametros;
		}
		new Ajax(url, {
		method: 'get',
		update: tipojanela,
		evalScripts: true,
		onComplete: function() {
				janelasAbertas.push(tipojanela);//joga pra dentro do array
				fechaDiv("carregando");
				mostraDiv(tipojanela);
			}
		}).request();
	}
	function vit_aj(tipojanela,parametros){
		abrirJanela(tipojanela,parametros);
	}

	//função responsavel por fechar a janela
 	function fecharJanela(){
		var janela = janelasAbertas.pop();
		fechaDiv(janela);//tira da ultima posição

		if(janelasAbertas.length==0){
			peliculaTela.close();
			
			if (typeof window.atualizaFlexFilmes == 'function') {
				atualizaFlexFilmes();
			}
			
		}else{
			$(janelasAbertas[(janelasAbertas.length-1)]).style.zIndex = 2;
		}		
	}
	
	function vit_fj(){
		fecharJanela();
	}
	
	function vit_fj_todas(){
		while (janelasAbertas.length > 0){
		     var janela = janelasAbertas.pop();
		     fechaDiv(janela);//tira da ultima posição
		}
		if ( janelasAbertas.length==0){
			 peliculaTela.close();
		}
	}
	
	function fechaDadosFilme()
	{
		fecharJanela();
	}
	
	function escondeTabelaTrailer(){
		document.getElementById("tabelaTrailer").style.display = "none";
	}
	
	function mostraCarregando(){
		if(janelasAbertas.length>0){
			for(i=0;i<janelasAbertas.length;i++){
				$(janelasAbertas[i]).style.zIndex = 1;
			}
		}

		peliculaTela.display();
		mostraDiv("carregando");		
	}

    function vit_mc(){
		mostraCarregando();
	}
	
	
	function fechaCarregando(){
		fechaDiv("carregando");
		if(janelasAbertas.length==0){
			peliculaTela.close();
		}else{
			$(janelasAbertas[(janelasAbertas.length-1)]).style.zIndex = 2;
		}
	}
	function vit_fc(){
		fechaCarregando();
	}
	
	function mostraDadosFilme(chavefilme,tipotela,paginacao,posicao){
  
		/*peliculaTela.display();
		mostraDiv("carregando");
		
		var url = "ajax_dadosfilme.php?"+antiCache();
		url += "&chavefilme="+chavefilme;
		url += "&tipotela="+tipotela;
		new Ajax(url, {
		method: 'get',
		update: $('retornoAjax'),
		evalScripts: true,
		onComplete: function() {
				fechaDiv("carregando");
				mostraDiv("fichaFilme");
				mostraPaginacaoFichaFilme(tipotela,posicao,paginacao);
			}
		}).request();*/
		
		abrirJanela('filme','chavefilme='+chavefilme+'&tipotela='+tipotela+'&paginacao='+paginacao+'&posicao='+posicao);  
  	}
  
  function fechaPapelDeParede()
	{		
		fechaDiv("PAPELDEPAREDE");	
		peliculaTela.close();
	}
  
  function mostraPapelDeParede(chavepapeldeparede,titulo,largura){
  	var altura = 0;
  	if(largura==0){
		largura = screen.width;
	}
	if(largura >= 1024) {
		largura = 1024;
		altura = 768;
	} else {
		if(largura >= 800) {
			largura = 800;
			altura = 600;
		} else {
			largura = 640;
			altura = 480;
		}
	}
		
	peliculaTela.display();
	mostraDiv("carregando");
	
	document.getElementById("TITULOPAPELDEPAREDE").innerHTML = titulo;
	document.getElementById("IMGPAPELDEPAREDE").innerHTML = '<img src="http://www.wfilmes.com.br/papeldeparede'+largura+'x'+altura+'/'+chavepapeldeparede+'.jpg" onClick="fechaPapelDeParede()" style="cursor:pointer;" title="Clique com botão esquerdo para fechar janela!" height="402" width="525">';
	document.getElementById("RESOLUCAO").innerHTML = 'Resolu&ccedil;&atilde;o da imagem:' +largura+ ' X ' +altura;
	document.getElementById("ALTERAR").innerHTML = 'Alterar para: <a class="text_normal" onClick="mostraPapelDeParede('+chavepapeldeparede+',\''+titulo+'\',640)" style="cursor:pointer;">640x480</a> | <a class="text_normal" onClick="mostraPapelDeParede('+chavepapeldeparede+',\''+titulo+'\',800)" style="cursor:pointer;">800x600</a> | <a class="text_normal" onClick="mostraPapelDeParede('+chavepapeldeparede+',\''+titulo+'\',1024)" style="cursor:pointer;">1024x768</a>';
	
	fechaDiv("carregando");
	mostraDiv("PAPELDEPAREDE");
  
  }
  
  	//codigo html proximo, anterior
  	function mostraPaginacaoFichaFilme(tipotela,posicao,paginacao){
		
			var html = '';
			if(paginacao == 1){
				if(posicao > 0){
					html +=  '<a title="Anterior." onClick="paginacaoFichaFilme('+(posicao-1)+',\''+tipotela+'\');" style="cursor:pointer;"><< .: FILME ANTERIOR</a> | ';
				}
			}
			
			html += '<a onClick="fechaDadosFilme(\'fichaFilme\');" style="cursor:pointer;" title="Fechar Janela."><font color="red">.: FECHAR JANELA :.</font></a>';
			
			if(paginacao == 1){
				if(posicao < (arrayFilmes.length - 1)){
					html += ' | <a style="cursor:pointer;" title="Próxima página." onClick="paginacaoFichaFilme('+(posicao+1)+',\''+tipotela+'\');">PRÓXIMO FILME :. >></a>';
				}
			}
			document.getElementById('PAGINACAOFICHAFILME').innerHTML = html;
	}
	
	function paginacaoFichaFilme(posicao,tipotela){
		fecharJanela();
		mostraDadosFilme(arrayFilmes[posicao].chavefilme,tipotela,1,posicao);
	}
  
	function antiCache(){
		var dt = new Date();
		return encodeURI(Math.random() + "_" + dt.getTime());
	}
	function trocaDados(idFrom,idTo){
		document.getElementById(idTo).innerHTML = document.getElementById(idFrom).innerHTML;
	}	

	function MostraListaRelacao(TeclaPress){
	   if( (TeclaPress.keyCode==13) && (document.formIndicacao.nome.value == 'filme') ){
		    window.open('http://www.videotecaonline.com.br/listarelacoesdeumfilme.php?chavefilme='+document.formIndicacao.chavefilme_indicacao.value,'lista','top=0,left=0,scrollbars=yes');
	   }
	}

	function enviaIndicacaoFilme(){
		
			var ok = 1;
			if( (document.formIndicacao.nome.value == '') && (ok==1)){
				alert("Preencha o campo Seu nome corretamente!");
				ok = 0;
				document.formIndicacao.nome.focus();
			}
			if( (document.formIndicacao.email.value == '' || document.formIndicacao.email.value.indexOf('@')==-1 ||document.formIndicacao.email.value.indexOf('.')==-1 ) && (ok==1) ){
				
				alert("Preencha o campo de Seu e-mail corretamente!");
				ok = 0;
				document.formIndicacao.email.focus();
			}
			if((document.formIndicacao.nomeamigo.value=='' ) && (ok==1)){
				alert("Preencha o campo Nome do seu amigo corretamente!");
				ok = 0;
				document.formIndicacao.nomeamigo.focus();
			}
			if((document.formIndicacao.emailamigo.value=='' || document.formIndicacao.emailamigo.value.indexOf('@')==-1 || document.formIndicacao.emailamigo.value.indexOf('.')==-1 ) && (ok==1)){
				alert("Preencha o campo E-mail do seu amigo corretamente!");
				ok = 0;
				document.formIndicacao.emailamigo.focus();
			}
			
			if(ok==1){
				var url = "indicacao.php?"+antiCache();
				url += "&nome="+document.formIndicacao.nome.value;
				url += "&email="+document.formIndicacao.email.value;
				url += "&nomeamigo="+document.formIndicacao.nomeamigo.value;
				url += "&emailamigo="+document.formIndicacao.emailamigo.value;
				url += "&mensagem="+document.formIndicacao.mensagem.value;
				url += "&chavefilme="+document.formIndicacao.chavefilme_indicacao.value;
				
				
				new Ajax(url, {
				method: 'post',
				update: $('retornoAjax'),
				evalScripts: true,
				onComplete: function() {
					}
				}).request();
			}
		
	}
	
	function get_cookie(c_name){				
		var nameEQ = c_name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
		}
		return "0";
	}
	
	function addSwfObject(swfUrl, id, width, height) {
		var params = {
		  quality: "high",
		  wmode: "transparent",
		  allowScriptAccess: "always"
		};
		var flashvars = {};
		var attributes = {};			
		swfobject.embedSWF(swfUrl, id, width, height, "8","", flashvars, params, attributes);		
	}
	
	/*********************************************************************************************/
	//Funcões responsáveis por fazer o fundo escuro
	DHTML_peliculaTela = function()
	{
		var divs_transparentDiv; //Transparent div covering page content
	}
	
	DHTML_peliculaTela.prototype = {
	
		display : function()
		{
			if(!this.divs_transparentDiv){
				this.__createDivs();
			}	
			this.divs_transparentDiv.style.display='block';
			this.__repositionTransparentDiv();
			
		}
		,
		close : function()
		{
			this.divs_transparentDiv.style.display='none';
		}	
		,
		addEvent : function(whichObject,eventType,functionName,suffix)
		{ 
		  if(!suffix)suffix = '';
		  if(whichObject.attachEvent){ 
			whichObject['e'+eventType+functionName+suffix] = functionName; 
			whichObject[eventType+functionName+suffix] = function(){whichObject['e'+eventType+functionName+suffix]( window.event );} 
			whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName+suffix] ); 
		  } else 
			whichObject.addEventListener(eventType,functionName,false); 	    
		} 
		,
		__createDivs : function()
		{
			// Creating transparent div
			this.divs_transparentDiv = document.createElement('DIV');
			this.divs_transparentDiv.className='modalDialog_transparentDivs';
			this.divs_transparentDiv.style.left = '0px';
			this.divs_transparentDiv.style.top = '0px';
			
			document.body.appendChild(this.divs_transparentDiv);
	
			window.refToModMessage = this;
			this.addEvent(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() });
		}
		,
		__getBrowserSize : function()
		{
			
			var bodyWidth, bodyHeight; 
			   bodyWidth = document.body.clientWidth;
				bodyHeight = document.body.clientHeight;
			   //if(document.body.scrollHeight > 100){
					if(document.body.scrollHeight > document.body.clientHeight){
						bodyHeight = document.body.scrollHeight ;
					}
			  // }
			return [bodyWidth,bodyHeight];		
			
		}
		,
		__repositionTransparentDiv : function()
		{
		
			//this.divs_transparentDiv.style.height = 0;
			var brSize = this.__getBrowserSize();
			var bodyWidth = brSize[0];
			var bodyHeight = brSize[1];
			this.divs_transparentDiv.style.width = bodyWidth + 'px';
			this.divs_transparentDiv.style.height = bodyHeight + 'px';
					
		}
	}

	function carregaTrailer(trailer){
		var FO = {	movie:"trailer/flvplayer.swf",id:"mediaplayerfilme",width:"288",height:"225",majorversion:"7",build:"0",bgcolor:"#FFFFFF",wmode:"transparent",
		flashvars:"file="+trailer+"&showdigits=true&autostart=false&showfsbutton=false&fsreturnpage=index.html" };
		UFO.create(	FO, "playerTrailer");
		setTimeout("enviaEvento('volume',100)", 2000);	
	}
	
	function enviaEvento(typ,prm) {
	   thisMovie("mediaplayerfilme").sendEvent(typ,prm);
	}
	
	function thisMovie(movieName) {
	   if(navigator.appName.indexOf("Microsoft") != -1) {
		  return window[movieName];
	   } else {
		  return document[movieName];
	   }
	}

	peliculaTela = new DHTML_peliculaTela();//Termina as funções responsáveis pelo fundo escuro
	document.write('<div id="carregando" style="display:none;position:absolute;top:50%;left:50%; z-index:2;" align="center"><img src="imgvideoteca/ajax-loader.gif" border="0"></div>');
