new Image().src="/images/comen_abajo.gif";
new Image().src="/images/comen_arriba.gif";
estado=0;
estadoG=0;
estadoF=0;

fb1 = '<fb:like href=\"http://www.enfocado.com/?foto=';
fb2 = '\" layout=\"button_count\" send=\"true\" font=\"tahoma\" width="220"></fb:like>';

fb3 = '<fb:comments href=\"http://www.enfocado.com/?foto=';
fb4 = '" num_posts=\"2\" width=\"600\"></fb:comments>';

$(document).ready(function(){
	$("#muestraCom").click(function () {
		if(estado==0){
			// Cierro GPS
			$("#mapG").fadeOut("slow");
			GUnload();
			document.getElementById('cflechagps').src = '/images/comen_abajo.png';
			estadoG=0;
			// Fin
			//Cierro Comentarios FB
			$("#fcomentarios").fadeOut("slow");
			document.getElementById('cflechafb').src = '/images/comen_abajo.png';
			estadoF=0;
			//Fin
			document.getElementById('cflecha').src = '/images/comen_arriba.png';
			estado=1;
		}else{
			document.getElementById('cflecha').src = '/images/comen_abajo.png';
			estado=0;
		}
		$("#comentarios").toggle("slow");
	}); 
	$("#muestraFbCom").click(function () {
		if(estadoF==0){
			// Cierro GPS
			$("#mapG").fadeOut("slow");
			GUnload();
			document.getElementById('cflechagps').src = '/images/comen_abajo.png';
			estadoG=0;
			// Fin
			//Cierro Comentarios
			$("#comentarios").fadeOut("slow");
			document.getElementById('cflecha').src = '/images/comen_abajo.png';
			estado=0;
			//Fin
			document.getElementById('cflechafb').src = '/images/comen_arriba.png';
			estadoF=1;
		}else{
			document.getElementById('cflechafb').src = '/images/comen_abajo.png';
			estadoF=0;
		}
		$("#fcomentarios").toggle("slow");
	});
	$("#muestraGps").click(function () {
		$("#mapG").toggle("slow");
		if(estadoG==0){
			//Cierro Comentarios
			$("#comentarios").fadeOut("slow");
			document.getElementById('cflecha').src = '/images/comen_abajo.png';
			estado=0;
			//Fin
			//Cierro Comentarios FB
			$("#fcomentarios").fadeOut("slow");
			document.getElementById('cflechafb').src = '/images/comen_abajo.png';
			estadoF=0;
			//Fin
			document.getElementById('cflechagps').src = '/images/comen_arriba.png';
			estadoG=1;
			load();
		}else{
			GUnload();
			document.getElementById('cflechagps').src = '/images/comen_abajo.png';
			estadoG=0;
		}
	});
	$("#cierrabeta").click(function () {
		$.ajax({ url: "/cbeta/", context: document.body, success: function(){
			$("#beta").fadeOut("slow");
		}});
	});
});

new Image().src='/images/estrella_off.png';
new Image().src='/images/estrella_on.png';
function cambiaVal(estrella){
	if (estrella>=1){
		document.getElementById('imgval-1').src = '/images/estrella_on.png';
	}else{
		document.getElementById('imgval-1').src = '/images/estrella_off.png';
	}
	if (estrella>=2){
		document.getElementById('imgval-2').src = '/images/estrella_on.png';
	}else{
		document.getElementById('imgval-2').src = '/images/estrella_off.png';
	}
	if (estrella>=3){
		document.getElementById('imgval-3').src = '/images/estrella_on.png';
	}else{
		document.getElementById('imgval-3').src = '/images/estrella_off.png';
	}
	if (estrella>=4){
		document.getElementById('imgval-4').src = '/images/estrella_on.png';
	}else{
		document.getElementById('imgval-4').src = '/images/estrella_off.png';
	}
	if (estrella>=5){
		document.getElementById('imgval-5').src = '/images/estrella_on.png';
	}else{
		document.getElementById('imgval-5').src = '/images/estrella_off.png';
	}
}

function onoff(id,estado){
	document.getElementById(id).style.display = estado;
}

//AJAX ****************************

function handleHttpResponse() { 
	if (http.readyState == 4) { 
		if (http.status == 200) { 
			if (http.responseText.indexOf('invalid') == -1) {
            	// Armamos un array, usando la coma para separar elementos
            	results = http.responseText.split("|"); 
            	document.getElementById("votos").innerHTML = results[0];
            	document.getElementById("media").innerHTML = results[1];
            	document.getElementById("estrel").innerHTML = results[2];
				vest = Math.round(parseInt(results[1]));
            	enProceso = false;
          	}
       	}
    }
}
function valorado(valor,foto) {
	if (!enProceso && http) {
	   var rr = Math.round(Math.random()*1000);
       var url = "/valorado/?val="+ valor +"&foto="+ foto + "&rr=" + rr;
       http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponse;
       enProceso = true;
       http.send(null);
    }
	return false;
}

function handleHttpResponse2() { 
	if (http2.readyState == 4) { 
		if (http2.status == 200) { 
			if (http2.responseText.indexOf('invalid') == -1) {
            	document.getElementById("resto").innerHTML = http2.responseText;
            	enProceso2 = false;
          	}
       	}
    }
}
function restajax(foto,pag) {
	if (!enProceso2 && http2) {
	   var rr = Math.round(Math.random()*1000);
       var url = "/resto/?foto="+ foto +"&pag="+ pag + "&rr=" + rr;
       http2.open("GET", url, true);
       http2.onreadystatechange = handleHttpResponse2;
       enProceso2 = true;
       http2.send(null);
    }
	return false;
}

function handleHttpResponse4() { 
	if (http4.readyState == 4) { 
		if (http4.status == 200) { 
			if (http4.responseText.indexOf('invalid') == -1) {
            	document.getElementById("nuevocom").innerHTML = document.getElementById("nuevocom").innerHTML + http4.responseText;
				li = "#li"+c;
				$(li).toggle("slow");
            	enProceso4 = false;
          	}
       	}
    }
}
cc=0;
function comajax() {
	foto=$("#foto").val();
	nick=$("#nick").val();
	email=$("#email").val();
	www=$("#www").val();
	comentario=$("#comentario").val();
	asimg=$("#asimg").val();
	c=parseInt($("#c").val()) + cc;
	if (!enProceso4 && http4) {
	   var rr = Math.round(Math.random()*1000);
       var url = "/comentado/?foto="+ foto +"&nick="+ nick +"&email="+ email +"&www="+ www +"&comentario="+ comentario +"&asimg="+ asimg +"&c="+ c + "&rr=" + rr;
       http4.open("GET", url, true);
       http4.onreadystatechange = handleHttpResponse4;
       enProceso4 = true;
       http4.send(null);
    }
	$("#comentario").val("");
	$("#asimg").val("");
	cc=cc+1;
	return false;
}
function getHTTPObject(){
	var xmlhttp=false; 
/* Compatibilidad con FireFox, Opera y cualquier otro BUEN navegador */
	if(typeof(XMLHttpRequest) != 'undefined'){
    	try{
      		var xmlhttp = new XMLHttpRequest();
    	}
    	catch(e){ }
  	}else{
    /* Compatibilidad para el navegador más ASQUEROSO del planeta [ IE ] */
    	try{
      		var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    	}
    	catch(e){
      		var xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
    	}
  	}
  	return xmlhttp;
}

var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest
var enProceso2 = false; // lo usamos para ver si hay un proceso activo
var http2 = getHTTPObject(); // Creamos el objeto XMLHttpRequest
var enProceso4 = false; // lo usamos para ver si hay un proceso activo
var http4 = getHTTPObject(); // Creamos el objeto XMLHttpRequest


// ********** EN DESUSO  ***************
function valora(id){
	window.open('/valora/?idfoto='+id,'Valorar','width=250,height=250,directories=0,resizable=0,location=0,status=0,scrollbars=0,toolbar=0,menubar=0,titlebar=0');
}
function localiza(id){
	window.open('/maps/?idfoto='+id,'Localizado','width=500,height=500,directories=0,resizable=0,location=0,status=0,scrollbars=0,toolbar=0,menubar=0,titlebar=0');
}
function muestra(){
	if(document.all){
		estado = comentarios.style.display;
		if (estado == 'none' || estado == ''){
			comentarios.style.display = 'block';
			document.getElementById('cflecha').src = '/images/comen_arriba.png';
		}else{
			comentarios.style.display = 'none';
			document.getElementById('cflecha').src = '/images/comen_abajo.png';
		}
	}else{
		estado = document.getElementById("comentarios").style.display; 
		if(estado == 'none' || estado == ''){
			document.getElementById("comentarios").style.display = 'block';
			document.getElementById('cflecha').src = '/images/comen_arriba.png';
		}else{
			document.getElementById("comentarios").style.display = 'none';
			document.getElementById('cflecha').src = '/images/comen_abajo.png';
		}
	}
}
function muestragps(){
	if(document.all){
		estadogps = mapG.style.display;
		if (estadogps == 'none' || estadogps == ''){
			mapG.style.display = 'block';
			document.getElementById('cflechagps').src = '/images/comen_arriba.png';
			// ** cierro los comentarios
			comentarios.style.display = 'none';
			document.getElementById('cflecha').src = '/images/comen_abajo.png';
			load();
		}else{
			GUnload();
			mapG.style.display = 'none';
			document.getElementById('cflechagps').src = '/images/comen_abajo.png';
		}
	}else{
		estadogps = document.getElementById("mapG").style.display; 
		if(estadogps == 'none' || estadogps == ''){
			document.getElementById("mapG").style.display = 'block';
			document.getElementById('cflechagps').src = '/images/comen_arriba.png';
			// ** cierro los comentarios
			document.getElementById("comentarios").style.display = 'none';
			document.getElementById('cflecha').src = '/images/comen_abajo.png';
			load();
		}else{
			GUnload();
			document.getElementById("mapG").style.display = 'none';
			document.getElementById('cflechagps').src = '/images/comen_abajo.png';
		}
	}
}

// ********** EN DESARROLLO ************
function handleHttpResponse3() { 
	if (http3.readyState == 4) { 
		if (http3.status == 200) { 
			if (http3.responseText.indexOf('invalid') == -1) {
            	document.getElementById("etiquetas").innerHTML = http3.responseText;
            	enProceso3 = false;
          	}
       	}
    }
}
function netiqueta() {
	foto=document.getElementById("etifoto").value
	etiqueta=document.getElementById("etiqueta").value
	alert(foto+' '+etiqueta)
	if (!enProceso3 && http3) {
	   var rr = Math.round(Math.random()*1000);
       var url = "/etiquetado/etiquetalo.asp?foto="+ foto +"&etiqueta="+ etiqueta + "&rr=" + rr;
       http3.open("GET", url, true);
       http3.onreadystatechange = handleHttpResponse3;
       enProceso3 = true;
       http3.send(null);
    }
	return false;
}
var enProceso3 = false; // lo usamos para ver si hay un proceso activo
var http3 = getHTTPObject(); // Creamos el objeto XMLHttpRequest

function etiquetalo(){
	/*if(document.all){
		estadoeti = etiquetalo.style.display;
		if (estadoeti == 'none' || estadoeti == ''){
			etiquetalo.style.display = 'block';
		}else{
			etiquetalo.style.display = 'none';
		}
	}else{*/
		estadoeti = document.getElementById("etiquetalo").style.display; 
		if(estadoeti == 'none' || estadoeti == ''){
			document.getElementById("etiquetalo").style.display = 'block';
		}else{
			document.getElementById("etiquetalo").style.display = 'none';
		}
	//}
}

