$(document).ready(inicia);

function inicia(){	
	// CUFON
	llamaCufon();
	thumbClonicos();	
	
	// PORTADA
	$("#btn_numerologia").click(function (){ $("#contenidoNumerologia").load("/internal/numerologia.php?id="+Math.random(), llamaCufon); return false; });
	$("#btn_leyes").click(function (){ $("#contenidoLeyes").load("/internal/leyes.php?id="+Math.random()); return false; });
	$("#btn_citas").click(function (){ $("#contenidoCitas").load("/internal/citas.php?id="+Math.random()); return false; });
	$("#btn_clonicos").click(thumbClonicos);
	
	
	// ENLACES EXTERNOS
	$("#articulo a").filter( function (){ return $(this).attr("target") == "_blank" }).css({ background: "url(http://www.cronicagolf.com/wp-content/themes/cronicaGolf/_img/external.gif) no-repeat right center", paddingRight: "13px",  display: "inline" });
	$(".itemListaBlog a").filter( function (){ return $(this).attr("target") == "_blank" }).css({ background: "url(http://www.cronicagolf.com/wp-content/themes/cronicaGolf/_img/external.gif) no-repeat right center", paddingRight: "13px",  display: "inline" });
	$(".aExterno").attr("target", "_blank");
	$("#suscripcion .redSocial").attr("target", "_blank");
	$("#enlacesExternos li a").attr("target", "_blank");
	
	// REGISTRO
	$("#registroFront form").submit(chequeaFormRegistro);
	$("#registroFront .mensajeAyuda").click(muestraMensaje);
	$("#registroFront #tituloCondiciones a").click( function(){ $("#textoLegal").slideToggle(500); return false; })
	$("#condiciones2 #tituloCondiciones2 a").click( function(){ $("#textoLegal2").slideToggle(500); return false; })

	// BUSCADOR
	$("#buscador").hover( function (){	$(this).stop().animate( { height: "64px" }, 200);	}, function(){ /*$(this).stop().animate( { height: "40px" }, 600);*/   });
	$("#buscador span").click( function(){ $(this).find("input").attr("checked", "checked"); });
	$("#buscador .radioNews input").attr("checked", "checked");
	
	// AVISO LEGAL
	$(".avisoLegal").click( function(){
										params = "width=500px, height=600px, statusbar=no, location=no, scrollbars=yes";
										window.open($(this).attr("href"), "legal", params);
										return false;
									})
	
	
	
	
	// GALERIA
	$("#.gallery a").attr("rel", "prettyPhoto[gallery]").prettyPhoto({ theme: 'light_square', showTitle: false });
	
	// CENTRADO DE IMÁGENES EN ARTÍCULOS
	$("#articulo p:has(img.aligncenter)").addClass("centeredContent");
	
	
	
}

function muestraMensaje(){
	var mensaje = $(this).attr("id");
	switch (mensaje) {
		case "msg1":
			alert("El nombre de usuario será el alias o apodo que utilizarás en Crónica Golf para publicar comentarios.");
		break;
		case "msg2":
			alert("Tus datos personales jamás serán publicados ni cedidos. Solo utilizaremos tu nombre y apellidos si tenemos que ponernos en contacto contigo para comunicarte que has sido agraciado con algún premio.");
		break;
		case "msg3":
			alert("Escribe una dirección de correo electrónico válida y operativa.");
		break;
	}
	return false;
}


function chequeaFormRegistro(){
	var mensajeError = false;
	// ALERTA VACIOS
	$("#registroFront form input:text").click( function (){ $(this).css({ background:"#FFF" }); })
	$("#registroFront form input:text").focus( function (){ $(this).css({ background:"#FFF" }); })

	// TODOS COMPLETOS
	$("#registroFront form input:text").each( function (){
			if ($(this).val()==""){
				$(this).css({ background:"#F00" });
				mensajeError = true;
			}
	})
	
	if(mensajeError){
		alert("Todos los campos son obligatorios");
	} else{
		// EMAIL BIEN
		if($("#registroFront form input:text:eq(2)").val() != $("#registroFront form input:text:eq(3)").val()){
			alert("Las direcciones de e-mail que has escrito no coinciden. Revísalas y vuelve a escribirlas.");
		}else{	
			var valorCheck = $("#registroFront form #reg_legal:checked").val();
			if (valorCheck=="acepto"){
				return true;
			} else{
				alert("Debe aceptar las condiciones.");
				return false;
			}
		}
	}
	return false;
}



function llamaCufon(){
 	Cufon.replace('h2');
}

function pintaFecha(){
	var fecha = new Date();
	var meses = ["ENE", "FEB", "MAR", "ABR", "MAY", "JUN", "JUL", "AGO", "SEP", "OCT", "NOV", "DIC"];
	$("#fechaNoticias .dia").text(fecha.getDate());
	$("#fechaNoticias .mes").text(meses[fecha.getMonth()]);
	$("#fechaNoticias .anyo").text(fecha.getFullYear()); 
}	

function thumbClonicos(){
	var aleatorio = Math.ceil(Math.random()*10);
	var imagen = "/internal/clonicos/thumb_clonico"+aleatorio+".jpg";
	$("#thumbClonicos").attr("src", imagen);
	return false;
}















