$(document).ready(function() {
	
	


	//FORMULARIO INSERTAR ENLACE
	$("#formulario_enlaces").validate({
	debug: true,
		
      rules: { 
			
			email: { required: true, email: true},
			url: { required: true, url: true},
			url_reciproco: { url: true},
			comentario: { required: true, maxlength: 255},
			nombre: { required: true }
      },
	  messages:	{
			email:	{required: "Introduzca e-mail", email: "E-mail no válido"},
			nombre: "Introduzca el nombre de la Web",
			url:	{required: "Introduzca la URL de su web", url: "URL no válida"},
			url_reciproco:	{url: "URL no válida"},
			comentario:	{required: "Explícanos algo de tu web", maxlength: "Demasiado largo. Máximo 255 caracteres."}
	},
		submitHandler: function() {
			$('#formulario_enlaces').hide();
			$('#precarga').fadeIn(200, function () {
			$.ajax({
				type: 'POST',
				url: '/paginas/enlaces_formulario.php',
				data: $('#formulario_enlaces').serialize() + '&action=send',
				cache:false,
				dataType: 'html',
				async:false,
				// Mostramos un mensaje con la respuesta de PHP
				success: function(data) {
					$('#enlaces').fadeTo('slow', 0.3, function() {
						$('#enlaces').html(data);
						$('#enlaces').fadeTo('fast', 1);
					});

					 
					}
				});
			});
		}
		
   }); 
	///VALIDACION DE CAMPOS DEL FORMULARIO DE ENLACES
	

	
	//FORMULARIO DE CONTACTO
	$("#formulario_contacto").validate({
	debug: true,
		
      rules: { 
			
			email: { required: true, email: true},
			url: { url: true},
			comentario: { required: true},
			nombre: { required: true}
      },
	  messages:	{
			email:	{required: "Introduzca e-mail", email: "E-mail no válido"},
			nombre: "Introduzca su nombre",
			url:	"URL no válida",
			comentario:	{required: "Explícanos algo!"}
	},
		submitHandler: function() {
			$('#formulario_contacto').hide();
			$('#precarga').fadeIn(200, function () {
			$.ajax({
				type: 'POST',
				url: '/paginas/contacto.php',
				data: $('#formulario_contacto').serialize() + '&action=send',
				cache:false,
				dataType: 'html',
				async:false,
				// Mostramos un mensaje con la respuesta de PHP
				success: function(data) {
					$('#contacto').fadeTo('slow', 0.3, function() {
						$('#contacto').html(data);
						$('#contacto').fadeTo('fast', 1);
					});

					 
					}
				});
			});
		}
		
   }); 
	///VALIDACION DE CAMPOS DEL FORMULARIO DE ENLACES




	$('#especiales').hover(
		function(e)
		{
			//ANIMACION
			$('#especiales').animate({
			top:'45'}, 
				{
				duration: 600, 
				specialEasing: {
				  top: 'easeOutBounce'
				}
			});


		},
		function(e)
		{
			//VUELTA ATRAS
			//ANIMACION
			$('#especiales').animate({
			top:'80'}, 
				{
				duration: 600, 
				specialEasing: {
				  top: 'easeOutBounce'
				}
			});
		}
	);



	
		

	//EL LO MAS VISTO EN FLIPPING CONTENT
	$('#flip-container').quickFlip();  
  
    $('#flip-navigation li a').each(function(){  
        $(this).click(function(){  
            $('#flip-navigation li').each(function(){  
                $(this).removeClass('selected');  
            });  
            $(this).parent().addClass('selected');  
            //extract index of tab from id of the navigation item  
            var flipid=$(this).attr('id').substr(4);  
            //Flip to that content tab  
            $('#flip-container').quickFlipper({ }, flipid, 1);  
  
            return false;  
        });  
    });  

	//EL MENU SUPERIOR DESPLEGABLE
	$('ul li:has(ul)').hover(
		function(e)
		{
			$(this).find('ul').slideDown('fast');
		},
		function(e)
		{
			$(this).find('ul').slideUp('fast');
		}
	);

	
	//LAS ANIMACIONES DE INICIO
	if (!$.cookie('balon_h')) {
		$.cookie('balon_h', { path: '/', expires: 1 })

		$('#futbol').animate({
			top:'100'}, 
				{
				duration: 1800, 
				specialEasing: {
				  top: 'easeOutBounce'
				}
		});

		$('#basket').animate({
			top:'90'}, 
				{
				duration: 3000, 
				specialEasing: {
				  top: 'easeOutBounce'
				}
		});

		$('#tenis').animate({
			top:'90'}, 
				{
				duration: 1000, 
				specialEasing: {
				  top: 'easeOutBounce'
				}
		});

		
		$('#titulo').animate({
			left:'0'}, 
				{
				duration: 800, 
				specialEasing: {
				  top: 'easeOutBounce'
				}
		});

		$('#subtitulo').animate({
			left:'0'}, 
				{
				duration: 1900, 
				specialEasing: {
				  top: 'easeOutBounce'
				}
		});




	}	else	{
		$('#futbol').animate({top:'90'},0);
		$('#basket').animate({top:'90'},0);
		$('#tenis').animate({top:'100'},0);
		$('#titulo').animate({left:'0'},0);
		$('#subtitulo').animate({left:'0'},0);
	}


	$('.opciones_polls').click(function(){
		
		var myvar = this.rel;
		var arr = myvar.split('-');
		var poll=arr[0];
		var option=arr[1];
		var laco='encuesta'+arr[0];
		if (!$.cookie(laco)) {
			
			$.cookie(laco, { path: '/', expires: 10 })
			
			//alert('poll:' + poll + ' option:' + option);
			$('#poll_' + poll).fadeOut("fast").load('/modulos/enviar_votos_polls.php?poll=' + poll + '&option=' + option).fadeIn("slow");
		}	else	{
			$('#resultado_poll' + poll).fadeOut("fast").load('/modulos/ya_votaste_encuesta.php').fadeIn("slow");
		}

		return false;
	});


	$('.opciones_polls_grande').click(function(){
		var myvar = this.rel;
		var arr = myvar.split('-');
		var poll=arr[0];
		var option=arr[1];
		var laco='encuesta'+arr[0];
		//alert('poll:' + poll + ' opcion:' + option);
		
		if (!$.cookie(laco)) {
			$.cookie(laco, { path: '/', expires: 10 })
			//alert('poll:' + poll + ' option:' + option);
			$('#poll_grande').fadeOut("fast").load('/modulos/sillon_polls_comentarios_votar.php?poll=' + poll + '&option=' + option).fadeIn("slow");
		}	else	{
			$('#resultado_poll').fadeOut("fast").load('/modulos/ya_votaste_encuesta.php').fadeIn("slow");
		}

		return false;
	});





	$('#el_nombre').click(function(){
		$('#el_nombre').removeClass('error');
	});

	$('#el_texto').click(function(){
		$('#el_texto').removeClass('error');
	});
	

	


	$(".img_votos").hover(
		  function () {
			$(this).addClass("encima");
		  },
		  function () {
			$(this).removeClass("encima");
		  }
	);
	
	$('.img_votos').click(function(){
		var myvar = this.alt;
		var arr = myvar.split('-');
		var laco='votar'+arr[0];
		if (!$.cookie(laco)) {
			$.cookie(laco, { path: '/', expires: 10 })
			
			la_votacion=this.alt;
			$('#modulo_votaciones').fadeOut("fast").load('/modulos/enviar_votos.php?valor='+la_votacion).fadeIn("fast");
		} else	{
			$('#modulo_votaciones').fadeOut("fast").load('/modulos/ya_votaste.php').fadeIn("fast");
		}
	});


	$('#hacer_comentario').click(function(){
		$('#formulario_comentarios').toggle('fast');
		$('#div_compartir').slideUp('fast');
		$('#modulo_votaciones').slideUp('fast');
	});

	$('#votar').click(function(){
		$('#modulo_votaciones').toggle('fast');
		$('#div_compartir').slideUp('fast');
		$('#formulario_comentarios').slideUp('fast');
		
	});
	
	$('#compartir').click(function(){
		$('#div_compartir').toggle('fast');
		$('#formulario_comentarios').slideUp('fast');
		$('#modulo_votaciones').slideUp('fast');

	});

	$('#boton_enviar_comentarios').click(function(){

	
		if ($('#el_nombre').attr('value')=='Tu nombre....' || $('#el_nombre').val().length < 1)	{
			$('#el_nombre').addClass('error');
			exit;
		}

		if ($('#el_texto').val()=='Pon aqui tus comentarios....' || $('#el_texto').val().length < 1){
			$('#el_texto').addClass('error');
			exit;
		}
		
		
		$.ajax({
				type: 'POST',
				url: '/modulos/comentarios_utf.php',
				data: $('#enviar_comentarios').serialize() + '&accion2=guardar',
				cache:false,
				dataType: 'html',
				async:false,
				// Mostramos un mensaje con la respuesta de PHP
				success: function(data) {
					$('#modulo_comentarios').fadeTo('slow', 1, function() {
						$('#modulo_comentarios').html(data);
						$('#formulario_comentarios').hide('fast');
						
					});

					 
				}
		});
	});



	$('#boton_enviar_comentarios_polls').click(function(){
		
		
	
		if ($('#el_nombre').attr('value')=='Tu nombre....' || $('#el_nombre').val().length < 1)	{
			$('#el_nombre').addClass('error');
			exit;
		}

		if ($('#el_texto').val()=='Pon aqui tus comentarios....' || $('#el_texto').val().length < 1){
			$('#el_texto').addClass('error');
			exit;
		}
		
		
		$.ajax({
				type: 'POST',
				url: '/modulos/comentarios_utf_polls.php',
				data: $('#enviar_comentarios').serialize() + '&accion2=guardar',
				cache:false,
				dataType: 'html',
				async:false,
				// Mostramos un mensaje con la respuesta de PHP
				success: function(data) {
					$('#modulo_comentarios').fadeTo('slow', 1, function() {
						$('#modulo_comentarios').html(data);
						$('#formulario_comentarios').hide('fast');
						
					});

					 
				}
		});
	});
 
	

	

	
	
	















 });


