$(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').animate({opacity:0},300,function() {
					window.location.href=destino;
				});
			});
			
			$(this).hover(function(){
				if (!$(this).parent().is('.activo'))
					$(this).stop().animate({backgroundColor:$("#header").attr('class').split('-')[1]},500);
		    },function(){
				if (!$(this).parent().is('.activo'))
				{
					$(this).stop().animate({backgroundColor:$("#header").attr('class').split('-')[1]},100);
					$(this).animate({backgroundColor:'#000'},2000);
				}
		    });
		}
	});
	
	$('a.idioma').click(function() {
		$('#form_lang').append('<input type="hidden" value="'+$(this).attr('name')+'" name="l" />');
			
		$('#form_lang').submit();
	});
	
	$('#localizacion').click(function() {
		window.open("http://maps.google.es/maps?q=colormatic&hl=es&ll=38.700909,-0.483463&spn=0.006832,0.016512&sll=40.396764,-3.713379&sspn=13.645715,33.815918&t=h&z=17&iwloc=A");
	});
});

$(window).load(function(){
	$('#wrapper').animate({opacity:1},1000);
});

$(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;
}
