/**
 * @author Oriol Cabau
 */

$.noConflict();

jQuery(document).ready(function($) {
	
	
	
	var bgImg = $('#fullBg');
	var login = $('#login');
	var footer = $('#footer');
		
	function resizeImg(){
		
		var imgwidth = 1920;
		var imgheight = 1280;
		
		var winwidth = ($(window).width())+17;//li sumo 17px a l'amplada per l'scroll
		var winheight = ($(window).height())+17;//li sumo 17px a l'alçada per l'scroll
		
		var widthratio = winwidth / imgwidth;
		var heightratio = winheight / imgheight;
		
		var widthdiff = heightratio * imgwidth;
		var heightdiff = widthratio * imgheight;
		
		if(heightdiff>winheight){
			bgImg.css({
				width: winwidth+'px',
				height: heightdiff+'px'
			});
		}else{
			bgImg.css({
				width: widthdiff+'px',
				height: winheight+'px'
			});		
		}
		
		coordLeft = (winwidth / 2) - 275;
		if(coordLeft < 280){ coordLeft = 280; }
			
		coordTop = ((winheight - 40) / 2) - 200;
		if(coordTop < 50){ coordTop = 50; }
			
		login.stop().animate({left: coordLeft, top: coordTop}, 400);
			
			
		coordTopFooter = winheight - 37;
		if(coordTopFooter < 660){ coordTopFooter = 660; }
			
		footer.css({ top:coordTopFooter });
			
	}
	
	var left = 0;
	var count = $('#intWrap img').length;
	var maxLeft = -((count-1)*515);
	
	function mouBanner(){
		left = left - 515;
		if(left < maxLeft){ left = 0; }
		$('#intWrap').stop().animate({left:left}, 400);
		setTimeout(mouBanner, 4000);
	}
	
	setTimeout(mouBanner, 4000);
	
	resizeImg();
	
	$(window).resize(function() {
		resizeImg();
	});
	
	$('.registrate').click(function(){
		$('.volver').fadeIn(400);
		$('.content1').slideUp(400, function(){
			$('.content2').slideDown(400);
		});
	});
	$('.contrasenya').click(function(){
		$('.volver').fadeIn(400);
		$('.content1').slideUp(400, function(){
			$('.content3').slideDown(400);
		});
	});
	$('.volver').click(function(){
		$(this).fadeOut(400);
		$('.content2, .content3').slideUp(400, function(){
			$('.content1').slideDown(400);
		});
	});
	
	$('#name').hover(function(){
		if($(this).attr("value") == "Nombre"){
			$(this).attr("value", "");
		}
	}, function(){
		if($(this).attr("value") == ""){
			$(this).attr("value", "Nombre");
		}
	});
	$('#surnames').hover(function(){
		if($(this).attr("value") == "Apellidos"){
			$(this).attr("value", "");
		}
	}, function(){
		if($(this).attr("value") == ""){
			$(this).attr("value", "Apellidos");
		}
	});
	$('#email').hover(function(){
		if($(this).attr("value") == "Email"){
			$(this).attr("value", "");
		}
	}, function(){
		if($(this).attr("value") == ""){
			$(this).attr("value", "Email");
		}
	});
	$('#password').hover(function(){
		if($(this).attr("value") == "password"){
			$(this).attr("value", "");
		}
	}, function(){
		if($(this).attr("value") == ""){
			$(this).attr("value", "password");
		}
	});
	$('#day').hover(function(){
		if($(this).attr("value") == "D\xeda"){
			$(this).attr("value", "");
		}
	}, function(){
		if($(this).attr("value") == ""){
			$(this).attr("value", "D\xeda");
		}
	});
	$('#year').hover(function(){
		if($(this).attr("value") == "A\xf1o"){
			$(this).attr("value", "");
		}
	}, function(){
		if($(this).attr("value") == ""){
			$(this).attr("value", "A\xf1o");
		}
	});

});
