tempo = '';
w = 1;
h = 1;
parar = '';
primeiro = '';
quando = '';
hehe_p = '';
var principal = new Array();
var imgs = new Array();
var widtha = new Array();
var heighta = new Array();

function divs(){
var layer = document.createElement("div");
layer.setAttribute("id","eta");
document.body.appendChild(layer);

eta.innerHTML = '<table id="tabela" style="background-color:#000000; filter: alpha(opacity=50);"><tr><td align="center" valign="top">';   
eta.innerHTML +='</td></tr></table>';
eta.style.position = 'absolute';
eta.style.top = 0;
eta.style.left = 0;
eta.style.display = 'none';
   
var layer = document.createElement("div");
layer.setAttribute("id","eta2");
document.body.appendChild(layer);
eta2.style.display = 'none';
}

function fechar(){
   eta.style.display = 'none';
   eta2.style.display = 'none';
}
function car(hum){
   if(hum == 1){
      carregando.innerHTML = 'Carregando.';
   }
   if(hum == 2){
      carregando.innerHTML = 'Carregando..';
   }
   if(hum == 3){
      carregando.innerHTML = 'Carregando...';
   }
   if(hum < 3){
      hum++;
   }else{
      hum = 1;
   }
   parar = setTimeout("car("+hum+")", 100);
}
function hehe(){
	if(hehe_p == ''){
	if(h != 'sim'){
	   h += 50;
	}
	
	if(h < document.getElementById('heighta['+cod+']').value){
	   ta.height = h;
	}else{
      ta.height = document.getElementById('heighta['+cod+']').value;
	   h = 'sim';
	   if(w != 'sim'){
	      w += 50;
	   }
	   if(w < document.getElementById('widtha['+cod+']').value){
	      ta.width = w;
	   }else{
	      ta.width = document.getElementById('widtha['+cod+']').value;
	      w = 'sim';
	   }
	}
	
	if(h == 'sim' && w == 'sim'){
	   imagem.style.display = '';
	   eta2.style.left = (document.body.clientWidth/2)-(document.getElementById('widtha['+cod+']').value/2);
	   if(document.getElementById('principal['+cod+']').value != 'sim'){
	      linki.style.display = '';  
       }
	   hehe_p = 'sim';
	   clearTimeout(tempo);
	}
	}
	tempo = setTimeout("hehe()", 20);
}
function abrir(di){      
   hehe_p = '';
   
   w = 1;
   h = 1;
   if(primeiro == ''){
      primeiro = 'sim';
	  divs();
   }
   
   eta.style.display = '';
   eta2.style.display = '';
   
   if(document.getElementById('principal['+di+']').value > total_thumbs){
	  razao = 1;   
   }else{
	  razao = 2;   
   }

   if(di == 0){
      die = total_thumbs-razao;
   }else{
      die = di-1;
   }
   
   if(di == total_thumbs-razao){
      dii = 0;
   }else{
      dii = di+1;
   }
   
   codigo = '<table align="center"><tr><td align="center" valign="top"><table id="ta" bgcolor="#FFFFFF" align="center"><tr><td valign="middle" align="center" colspan="3"><font face="Verdana, Arial, Helvetica, sans-serif" pointsize="10"><img id="imagem" src="'+document.getElementById('imgs['+di+']').value+'"><div id="carregando" style="color:#000000;"></div></font></td></tr><tr><td align="left" valign="bottom">&nbsp;<a href="javascript:fechar();"><img src="'+site+'admin/lib.imgs/fechar.gif" border=0></a></td><td valign="bottom"><table><tr><td class="texto" colspan="2">Envie essa foto para um amigo:</td></tr><tr><td><input type="text" id="email" class="caixatexto"></td><td><input type="button" class="botao" id="botao" value="Enviar" onclick="enviar_foto(\''+document.getElementById('imgs['+di+']').value+'\');"></td></tr></table></td>';
   
   codigo += '<td align="right" valign="bottom"><img src="'+site+'admin/lib.imgs/setas.png" width="51" height="37" border="0" usemap="#Map" id="linki" style="display:none"/><map name="Map" id="Map"><area shape="poly" coords="24,11,27,15,27,21,21,26,14,27,9,21,8,15,13,9,21,9,24,11" alt="Anterior" href="javascript: javascript:alfa(1, 100, '+die+');" id="ant"/><area shape="poly" coords="38,12,42,16,42,21,38,25,34,25,30,21,30,15,34,12,36,12,38,12" alt="Pr&oacute;ximo" href="javascript:alfa(1, 100, '+dii+');" id="pro" /></map></td>';
   
   codigo += '</tr></table></td></tr></table>';
   
   eta2.innerHTML = codigo;
   eta2.style.position = 'absolute';
   eta2.style.top = 0;
   tabela.width = document.body.clientWidth;
   tabela.height = document.body.clientHeight;
   imagem.style.display = 'none';
   eta2.style.left = (document.body.clientWidth/2)-(document.getElementById('widtha['+di+']').value/2);
   
   car(1);
   cod = di;
   
   imagem.onload = function(){
     clearTimeout(parar)
	 carregando.style.display = 'none';
	 hehe();
   }
}

function alfa(tipo, valore, diq){
   if(tipo == 0){
      if(valore < 100){
	     valore += 20;
	     imagem.style.filter = 'alpha(opacity='+(valore)+')';
	  }
   }
   if(tipo == 1){
      if(valore > 0){
	     valore -= 20;
	     imagem.style.filter = 'alpha(opacity='+(valore)+')';
	  }else{
	     
		 imagem.src = document.getElementById('imgs['+diq+']').value;
         if(imagem.readyState == 'complete'){
	     hehe_p = '';
		 cod = diq;
		 tipo = 0;
		 if(diq == 0){
            die2 = total_thumbs-razao;
         }else{
            die2 = diq-1;
         }
		 ant.href = "javascript:alfa(1, 100, "+die2+"); "
	    
		 if(diq == total_thumbs-razao){
            dii2 = 0;
         }else{
            dii2 = diq+1;
         }
		 pro.href = "javascript:alfa(1, 100, "+dii2+");"
		 }
	  }
   }
   quando = setTimeout("alfa("+tipo+","+valore+","+diq+")", 100);
}

function enviar_foto(nom_img){
	botao.value = 'Enviando...';
	botao.disabled = true;
	var data = new Date();
	ajax = conectar();
	
	ajax.open('GET', root+'admin/lib.arq/cod.php?f=enviar_foto&email='+email.value+'&imagem='+nom_img+'&'+data.getMilliseconds(), true);
	ajax.onreadystatechange = function(){
		if(ajax.readyState == 4){
			botao.value = 'Enviado!';
			botao.disabled = false;
		}
	}
	
	ajax.send();
}