$(document).ready(function(){
	/*if (TamVentana()[0]>=1024)
		$('#body').css({'overflow-x':'hidden'});*/
	
	$('#menu li a, #logo a').each(function(i) {
		if ($(this).attr('rel').length == 0) {
			$(this).attr('rel', $(this).attr('href'));
			$(this).attr('href', 'javascript: void(0);');
			var destino=$(this).attr('rel');
			
			$(this).click(function() {
				$('#wrapper,#footer').animate({opacity:0},300,function() {
					window.location.href=destino;
				});
			});
		}
	});
	
	$('a.idioma').click(function() {
		$('#form_lang').append('<input type="hidden" value="'+$(this).attr('name')+'" name="l" />');
			
		$('#form_lang').submit();
	});
	
	$('#input_footer').click(function() {
		if ($(this).val()=='Introduce tu e-mail')
			$(this).val('');
	});
	
	$('#input_footer').blur(function() {
		if ($(this).val()=='')
			$(this).val('Introduce tu e-mail');
	});
});

$(window).load(function(){
	$('#wrapper,#footer').animate({opacity:1},1000);
	
	$("#cuenta").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		onComplete			: function() {
			$('#log').focus();
		}
	});
	
	$("#editar,#registrarse").fancybox({
		'width'				: 800,
		'height'			: 620,
		'autoScale'			: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	
	$("#recordar").fancybox({
		'width'				: 470,
		'height'			: 130,
		'autoScale'			: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	
	$("#contactar,#privacidad,#clausula_privacidad,#legal,#preguntas,#preguntas,#costes,#plazo,#cambios,#pago").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade'
	});
	
	var datos=document.URL.split('?');

	if (datos[1]=="login=ko")
		alert("Datos incorrectos!")
});



function requerido(elemento)
{
	if (elemento.value.length<=0)
		return false
 	else
		return true;
}

function validaremail(email)
{
	var subemail='';
	var subemail2='';
	for (i=0;i<email.value.length;i++)
	{
		if (email.value.charAt(i)=="@" && i>1)
			subemail=email.value.substring(i+1,email.value.length)
	}
	if (subemail!='')
	{
		for (j=0;j<subemail.length;j++)
		{
			if (subemail.charAt(j)=="." && j>1)
				subemail2=subemail.substring(j+1,subemail.length);
		}
		if (subemail2.length>=2 && subemail2.length<=8)
			return true;
	}
}

function validar_newsletter(newsletter)
{
		if (requerido(newsletter.email_newsletter) && validaremail(newsletter.email_newsletter))
			document.newsletter.submit();
		else
		{
			newsletter.email_newsletter.focus();
			$('#respuesta').text('Debes introducir un e-mail válido.');
			return false;
		}
}





/*$(window).resize(function(){
	if (TamVentana()[0]>=1024)
		$('#body').css({'overflow-x':'hidden'});
	else
		$('#body').css({'overflow-x':'auto'});
});

function TamVentana() 
{ 
	var tam=[0, 0]; 
	if (typeof window.innerWidth != 'undefined')
		tam=[window.innerWidth,window.innerHeight];
	else 
		if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined'
				&& 	document.documentElement.clientWidth != 0)
			tam=[document.documentElement.clientWidth, document.documentElement.clientHeight];
		else
			tam=[document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight];
	return tam;
}*/
