// JavaScript Document

$(document).ready(function(){

$('.head ul li a[id!=selec]').hover(function(){$(this).stop().animate({backgroundPosition: '50% -66px'}, 300);},function(){$(this).stop().animate({backgroundPosition: '50% 0px'}, 300); });

$('.logo').fadeIn(1000);

$('a.link[id!=selec], a.subLink[id!=selec], a.subSubLink[id!=selec]').hover(function(){$(this).stop().animate({backgroundColor: '#000', color: '#FFF'}, 300);},function(){$(this).stop().animate({backgroundColor: '#FFF', color: '#000'}, 300); });


$("a[rel=galeria]").fancybox({
	'overlayOpacity'	: '0.5',
	'overlayColor'		: '#000',
	'transitionIn'		: 'elastic',
	'transitionOut'		: 'elastic'
});

$('.contNovedades.lista a.masInfo').hide();

$('.contNovedades.lista').hover(
	function()
	{
		$(this).stop().animate({backgroundColor: '#EAEAEA'}, 200);
		$('a.masInfo', this).fadeIn(200);
	},
	function()
	{
		$(this).stop().animate({backgroundColor: '#FFF'}, 200);
		$('a.masInfo', this).fadeOut(200);
	});

$('.buscar').fadeTo(0,0.5);
$(".buscar").css('color','#666').focus(function(){this.valuedefault=this.valuedefault||this.value; if (this.value==this.valuedefault){this.value=''; $(this).css('color','#000'); $('.buscar').fadeTo(200,1);}});
$(".buscar").blur(function(){if (this.value.length==0||this.value==this.valuedefault){$(this).css('color','#666'); if (this.valuedefault&&this.value.length==0){this.value=this.valuedefault;$('.buscar').fadeTo(200,0.7);}}});

		$("#enviaform")
		.click
		(
			function ()
			{
				function vacio(q) { for ( i = 0; i < q.length; i++ ) { if ( q.charAt(i) != " " ) { return true } } return false }
				$("#alert").slideUp(200);
				
				var nombre=$("#nombre").val();
				var apellido=$("#apellido").val();
				var direccion=$("#direccion").val();
				var localidad=$("#localidad").val();
				var cp=$("#cp").val();
				var mail=$("#mail").val();
				var comentario=$("#comentario").val();
				var tel=$("#tel").val();
				
				
				if ((vacio(nombre)==false) || (vacio(apellido)==false) || (vacio(direccion)==false) || (vacio(localidad)==false) || (vacio(cp)==false) || (vacio(mail)==false))
				{
					$("#alert").slideDown(200).html('<div class="mal">Complete todos los campos</div>');
				}
				else
				{
				
					$("#resultados").slideUp(300, function()
					{
					
					$.ajax({
							   async:true,
							   type: "POST",
							   dataType: "html",
							   contentType: "application/x-www-form-urlencoded",
							   url:"ajax/envia.php",
							   data:"nombre="+nombre+
									"&apellido="+apellido+
									"&direccion="+direccion+
									"&localidad="+localidad+
									"&tel="+tel+
									"&cp="+cp+
									"&mail="+mail+
									"&comentario="+comentario+
									"&donde=Consultas",
							   beforeSend:function()
							   	{
								   $("#enviaform").val("Enviando...");
								},
							   success:function(datos)
							   	{
								   $("#resultados").html(datos).slideDown(300);
								},
							   timeout:4000,
							   error:function()
								{
								  $("#resultados").html('Problemas en el servidor.').slideDown(300);
								  $("#enviaform").val("Enviar &raquo;");
								}		
							 });
							 return false;		
					});
				}
			}
		);


$(".FAQtitulo").click(function(){ var id=$(this).attr("id");  $(".FAQcontenido#Cont"+id).slideToggle(300); });


});
