// JavaScript Document
var pathGal = "";
var pathUrl = "";
var pathAdm = 0;
var rodaImgDest = "";
//
var Img = new Object();
Img.Request = function(imagem, galeria, path, nmImg, loga, adm){
	if(loga==null){ loga = 1;}
	if(adm==null){	adm = 1; }
	pathAdm = adm;
	pathGal = path+"galerias/"+galeria;
	pathUrl = path;
	rodaImgDest = nmImg;
	Img.request = Img.createRequestObject();
	Img.request.onreadystatechange = Img.Response;
	Img.request.open("POST", pathAJ+"__js/buscaIMG.php?img="+imagem+"&gal="+galeria+"&log="+loga, true);
	Img.request.send(pathAJ+"__js/buscaIMG.php");
}
Img.Response = function (){
	if(Img.CheckReadyState(Img.request)==200){		
		var response = Img.request.responseXML.documentElement;
		var _data = response.getElementsByTagName('gal');
		if(_data.length == 0){
			// achou nada;	
		}else{
			var localRes = response.getElementsByTagName('id')[0].firstChild.data;
			//
			if(localRes.length>0){
				resp = localRes.split("|");
				txtResp = '<div style="border:1px solid #BFBDAC;padding:8px;"><center>';
				if(resp[1].length>0 && resp[1]!=0){
					/*
					Largura
					*/
					if(resp[6]>300){
						wImg = 300;
					}else{
						wImg = resp[6];
					}
					//
					txtResp+= '<a href="javascript:zoomDestaque(\''+resp[1]+'\');" title="Clique na imagem para ampliar"><img src="'+pathGal+"/"+resp[1]+'" width="'+wImg+'" border="0" style="padding-bottom:3px"></a><br>';
					ativa = parseInt(resp[0])*1015;
				}else{
					txtResp+= '<strong><font color="#990000" style="border:1px solid #990000;padding:10px;">imagem não encontrada!</font></strong><br><br><br>';
					ativa = 0;
				}
				txtResp+= '<font class="bold">'+resp[2]+'</font><br>';
				txtResp+= resp[4]+'</center><br>';
				if(resp[3].length>0){
					txtResp+= '"<em>'+resp[3]+'</em>"</div><br><br>';
				}else{
					txtResp+= '</div><br><br>';
				}
				txtResp+= '<font class="artigos-subtitulo">Comentários:</font><br /><br />';
				//
				// Link para próxima ou imagem anterior
				//
				tmpLink = resp[7].split(";");
				codLink = resp[8].split(";");
				txtLink1 = txtLink2 = '';
				if(tmpLink[0].length>0){
					txtLink1 = '<a href="javascript:zoomImg(\''+codLink[0]+'\',\''+tmpLink[0]+'\');" title="imagem anterior"><span style="font-size:10px;"><strong>&laquo;&nbsp;anterior</strong></span></a>';
				}
				if(tmpLink[1].length>0){
					txtLink2 = '<a href="javascript:zoomImg(\''+codLink[1]+'\',\''+tmpLink[1]+'\');" title="próxima imagem"><span style="font-size:10px;"><strong>próximo&nbsp;&raquo;</strong></span></a>';
				}
				document.getElementById("botoesZoom1").innerHTML = txtLink1;
				document.getElementById("botoesZoom2").innerHTML = txtLink2;
				//
				// Comentarios
				//
				if(resp[9].length>0){
					com = resp[9].split("#");
					if(com.length>1){
						txtResp+= "<img src='"+pathUrl+"__img/plus.png'> Até o momento "+com.length+" comentários para a imagem.";
					}else{
						txtResp+= "<img src='"+pathUrl+"__img/plus.png'> Até o momento "+com.length+" comentário para a imagem.";
					}
					txtResp+= "<br><br>";
					for(n=0;n<com.length;n++){
						tmp_resp = com[n].split(";");
						txtResp+= '<table width="100%" border="0" cellspacing="0" cellpadding="10" bgcolor="#EBEAE0">';
						txtResp+= '<tr><td>';
						txtResp+= '	<table width="100%" cellspacing="0" cellpadding="0">';
						if(pathAdm=="adm"){
							txtResp+= '	<tr><td width="100%" height="25" valign="top"><span style="font-size:10px">'+tmp_resp[0]+', '+tmp_resp[1];
							txtResp+= '  <a href="javascript:delCom('+tmp_resp[3]+');"><img src="'+pathUrl+'__img/del.png" alt="Excluir comentário" border="0" align="absmiddle" /></a>';
							txtResp+= '	</span></td></tr>';
						}else{
							txtResp+= '	<tr><td width="100%" height="25" valign="top"><span style="font-size:10px">'+tmp_resp[0]+', '+tmp_resp[1]+'</span></td></tr>';
						}
						txtResp+= '	<tr><td>'+tmp_resp[2]+'</td></tr>';
						txtResp+= ' </table>';
						txtResp+= ' </td></tr>';
						txtResp+= '</table><br />';
					}
				}else{
					txtResp+= "<img src='"+pathUrl+"__img/minus.png'> Até o momento nenhum comentário para a imagem.<br><br>";
				}
				// Escreve resposta na Tela
				document.getElementById('zoomGaleria').innerHTML = txtResp;
				// Mostra o zoom
				if(rodaImgDest.length>0){
				   rodaDestaque(rodaImgDest);
				}
			}
		}	
	}
}
Img.createRequestObject = function(){
	var obj;
	if(window.XMLHttpRequest)	{
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		obj = new ActiveXObject("MSXML2.XMLHTTP");
	}
	return obj;
}
Img.CheckReadyState = function(obj){
	if(obj.readyState < 4) {		
		window.status = "Loading...";
	}
	if(obj.readyState == 4){
		if(obj.status == 200){
			window.status = "Loaded!";
			return obj.status;
		}else{
			window.status = "HTTP " + obj.status;
		}
	}
}
//
function zoomImg(cod, nmImg){
	if(cod==0){
		cod = cod_abertura;
	}
	if(passou>0){
		document.getElementById("msg_com").innerHTML = "";
	}	
	passou++;
	if(cod>0){
		txtwait = '<div style="border:1px solid #BFBDAC;padding:8px;"><center>';
		txtwait+= '<table width="100%" border="0" cellspacing="0" cellpadding="10">';
		txtwait+= '	<tr><td width="100%" height="200" valign="middle" align="center"><img src="'+pathAJ+'__img/waiting_p.gif"><br><br>Carregando...</center></td></tr>';
		txtwait+= '</table></div>';
		document.getElementById("zoomGaleria").innerHTML = txtwait; 
		//--
		if(reloadImg>0){
			document.getElementById("imgZoom").innerHTML = "<table width='100%'><tr><td align='right'><a href='javascript:fechaDestaque()'><strong>[Fechar]</strong></a>&nbsp;&nbsp;&nbsp;</td></tr><tr><td height='600px' width='100%' align='center' valign='middle'><a href='javascript:fechaDestaque()' title='Clique na imagem para fechar o zoom'><img src='"+pathAJ+"__img/waiting_p.gif' border='0'></a></td></tr></table>";
		}
		//--
		Img.Request(cod,codGaleria,pathAJ, nmImg);
	}	
}
function zoomPerfil(cod){
	if(passou>0){
		document.getElementById("msg_com").innerHTML = "";
	}	
	passou++;
	if(cod>0){
		Perfil.Request(cod);
	}	
}
function validar_comenta(op){
	obj = document.getElementById("Comentar");
	if(emBranco(obj.comentario.value)){
	    alert("Você aind não colocou o seu comentário!");
		obj.comentario.focus();
		return false;
	}
	if(op=="g"){
		obj.action = "galeria.php?ID=003005eb8887731f4ef029993d4c354d&c="+ativa;
	}else{
		obj.action = "imagens.php?ID=003005eb8887731f4ef029993d4c354d&c="+ativa+"&r="+(codGaleria*1015);
	}
	obj.comentario.value.replace('"',"'");
	obj.submit();
}
function editaCont(){
	obj = document.getElementById("boxCont"); 
	if(view==0){
		obj.style.visibility = "visible";
		obj.style.height = "400px";
		view = 1;
		window.status = "";
	}else{
		obj.style.visibility = "hidden";
		obj.style.height = "0px";
		view = 0;
	}	
}
function editaMens(){
	obj = document.getElementById("boxMens"); 
	if(view==0){
		obj.style.visibility = "visible";
		obj.style.height = "340px";
		view = 1;
		window.status = "";
	}else{
		obj.style.visibility = "hidden";
		obj.style.height = "0px";
		view = 0;
	}	
}
function validar_mens(){
	obj = document.getElementById("Mens"); 
	if(emBranco(obj.de.value)){
	   showMsgAlert("Por favor informe o seu nome!", 1, obj.de);
	   return false;
	}
	if(!validaMail(obj.__de.value, 1)){
	   return false;
	}
	if(emBranco(obj.msg_texto.value) || obj.msg_texto.value.length<5){
	   showMsgAlert("Você não informou a mensagem!", 1, obj.msg_texto);
	   return false;
	}
	obj.submit();
}
function editaGaleria(){
	obj = document.getElementById("boxGaleria"); 
	if(view_g==0){
		obj.style.visibility = "visible";
		obj.style.height = "100px";
		view_g = 1;
		window.status = "";
	}else{
		obj.style.visibility = "hidden";
		obj.style.height = "0px";
		view_g = 0;
	}	
}

// controle do zoom da galeria
nZoom = 0;
nLarg = 200;
nAlt = 150;
reloadImg = 0;
nomeImg = "";
function zoomDestaque(nmImg){
	//
	// Imagem para zoom
	//
	nomeImg = nmImg;
	if(nZoom==0){
		if(nLarg==200){
			MM_showHideLayers("fundoZoom","","show","imgZoom","","show","iconeZoom","","show");
			document.getElementById("fundoZoom").style.height = (screen.height-20)+"px";
			document.getElementById("fundoZoom").style.width = (screen.width-20)+"px";
			document.getElementById("iconeZoom").style.top = ((screen.height/2)-100)+"px";
			document.getElementById("iconeZoom").style.left = ((screen.width/2)-100)+"px";
		}
		//
		// Medidas para animação na tela
		//
		nLarg = nLarg+26;
		nAlt = nAlt+20;
		//
		//Se passou do limite interrompe animação e mostra imagem
		//
		if(nAlt>595){
			reloadImg = 1;
			nAlt = 610;
			nLarg = 800;
			nZoom = 1;
			imgTop = 5;
			imgLeft =  (screen.width/2)-(nLarg/1.9);
			// imagem
			MM_showHideLayers("iconeZoom","","hide");
			document.getElementById("imgZoom").innerHTML = "<table width='100%'><tr><td align='right'><a href='javascript:fechaDestaque()'><span style='font-size:10px'><strong>[Fechar]</strong></span></a>&nbsp;&nbsp;&nbsp;</td></tr><tr><td height='100%' width='100%' align='center' valign='middle'><a href='javascript:fechaDestaque()' title='Clique na imagem para fechar o zoom'><img src='"+pathAJ+"galerias/"+codGaleria+"/"+nomeImg+"' border='0'></a></td></tr></table>";
			// botões
			MM_showHideLayers("botoesZoom1","","show");
			document.getElementById("botoesZoom1").style.top = "9px";
			document.getElementById("botoesZoom1").style.left = (screen.width/2.4)+"px";
			MM_showHideLayers("botoesZoom2","","show");
			document.getElementById("botoesZoom2").style.top = "9px";
			document.getElementById("botoesZoom2").style.left = (screen.width/2)+"px";
		}else{
			//
			//Ajusta o tamanho da janela e continua a animação
			//
			imgTop = (screen.height/2)-(nAlt/1.6);
			imgLeft =  (screen.width/2)-(nLarg/1.9);
			setTimeout("zoomDestaque('"+nomeImg+"')", 5);
		}
		// Animação 
		document.getElementById("imgZoom").style.width = nLarg+"px";
		document.getElementById("imgZoom").style.height = nAlt+"px";
		document.getElementById("imgZoom").style.top = imgTop+"px";
		document.getElementById("imgZoom").style.left = imgLeft+"px";
	}
}
function rodaDestaque(nomeImg){
	document.getElementById("imgZoom").innerHTML = "<table width='100%'><tr><td align='right'><a href='javascript:fechaDestaque()'><strong>[Fechar]</strong></a>&nbsp;&nbsp;&nbsp;</td></tr><tr><td height='600px' width='100%' align='center' valign='middle'><a href='javascript:fechaDestaque()' title='Clique na imagem para fechar o zoom'><img src='"+pathAJ+"galerias/"+codGaleria+"/"+nomeImg+"' border='0'></a></td></tr></table>";
}
function fechaDestaque(){
	reloadImg = 0;
	MM_showHideLayers("botoesZoom1","","hide","botoesZoom2","","hide");
	MM_showHideLayers("fundoZoom","","hide","imgZoom","","hide");
	document.getElementById("imgZoom").innerHTML = '';
	nZoom = 0;
	nLarg = 200;
	nAlt = 150;
	nomeImg = "";
}
