// JavaScript Document
$(document).ready(function() { 
	var ie = document.getElementById("ie").value;
	$(".slide").fadeOut(1); 
	$("#slide1").fadeIn(2000);
	$(".slide div").hide(); 
	if (ie == "no"){
		$("#slide1 div").delay(1200).fadeIn(3000); 
	}else{
		$("#slide1 div").delay(2000).fadeIn(1); 
	}
	cargar_puntos(1);
	
	//abrimos el popup de inicio
	//$("#popup").fadeIn(2000);
});

$(document).everyTime(1000, function() {
	
	var play = document.getElementById("play").value;
	
	if (play == "si"){
	
		var tiempo = parseInt(document.getElementById("tiempo").value);
		
		if (tiempo < 10) { 
			tiempo++; document.getElementById("tiempo").value = tiempo;
		}else{
			document.getElementById("tiempo").value = 0;
			transicion();
		}
	}
	
}, 0);

function transicion() {
	
	var ie = document.getElementById("ie").value;
	var slider = document.getElementById("contador").value;
	var cant_sliders = document.getElementById("cant_sliders").value;
	
	if (slider == cant_sliders) { document.getElementById("contador").value = slider; };
	
	
	if (ie == "no"){
		$("#slide" + slider + " div").fadeOut(3000);
	}else{
		$("#slide" + slider + " div").fadeOut(1);
	}
	$(".slide").fadeOut(3000);
		
	slider++; document.getElementById("contador").value = slider;
	if (slider > cant_sliders) { document.getElementById("contador").value = 1; slider = 1 };
	
	
	$("#slide" + slider).fadeIn(3000);
	if (ie == "no"){
		$(".slide div").fadeOut(1500);
		$("#slide" + slider + " div").delay(1200).fadeIn(3000);
	}else{
		$(".slide div").hide(1);
		$("#slide" + slider + " div").delay(2000).fadeIn(1);
	}
	cargar_puntos(slider);
}

function cambiar_slide(slide){
	var cant_sliders = document.getElementById("cant_sliders").value;
	var slide_actual = slide;
	if (slide <= cant_sliders && slide > 1){slide_actual--;}else{slide_actual = cant_sliders;}
	document.getElementById("contador").value = slide_actual;
	document.getElementById("tiempo").value = 0;
	transicion();
}

function submenu(menu) {
	$(".sub_container").hide();
	$(".flecha").hide();
	$("#sub_" + menu).show();
	$("#flecha_" + menu).show();
}

function ocultar_submenu(menu) {
	$("#sub_" + menu).delay(500).hide();
	$("#flecha_" + menu).hide();
}

function cargar_puntos(punto) {
		
	$.post("puntos.php", {
		punto: punto
		}, function(response){
		//$("#controles").fadeOut();
		setTimeout("finishAjax('controles', '"+escape(response)+"')", 450);
	});
			
}

function cargar_contenido(pagina) {
		
		document.getElementById("play").value = "no";
		$.post("content.php", {	
			pagina : pagina
			}, function(response){
			//$("#content_frame").fadeOut();
			setTimeout("finishAjax('content_frame', '"+escape(response)+"')", 450);
		});
	
}

function cerrar_contenido() {
	
	document.getElementById("play").value = "si";
	$("#content_frame").fadeOut(1000);
			
}

function finishAjax(id, response){
		 
	$('#'+id).html(unescape(response));
	$('#'+id).fadeIn(1000);
		  
}

function ver_captcha(public_key,elemento) {

           Recaptcha.create(public_key, elemento, {
             theme: "clean",
             callback: Recaptcha.focus_response_field});
}

function enviar_correo(){
	
	
	$.post("content/contacto.php", {	
			nombre : cpid("in_nombre"),
			correo : cpid("in_correo"),
			telefono : cpid("in_telefono"),
			ciudad : cpid("in_ciudad"),
			asunto : cpid("in_asunto"),
			comentarios : cpid("in_comentarios"),
			recaptcha_response_field : cpid("recaptcha_response_field"),
			recaptcha_challenge_field : cpid("recaptcha_challenge_field"),
			funcion : 'enviar'
			}, function(response){
			//$("#content_frame").fadeOut();
			setTimeout("finishAjax('content_frame', '"+escape(response)+"')", 450);
		});

		
}

function cpid(id){
	return document.getElementById(id).value;
}

//cerrar pop up
function cerrar_popup() {
	$("#popup").fadeOut(1000);	
}
