$(document).ready(function(){
	$("#section").css({display:"none"});
	$("#section-wrap").css({opacity:0});
	$("#subsection").css({display:"none"});
	$(".subsection-wrap").css({display:"none"});
	$(".cerrado").css({display:"none"});
	if (jQuery.support.opacity)
		$("#list").css({opacity:0});
		
	if (TamVentana()[0]<1164)
	{
		$('#header,#footer').css({width:'1164px'});
		$('#botones_venta,#capicor').css({right:1164-TamVentana()[0]+20});
	}
	else
	{
		$('#header,#footer').css({width:'100%'});
		$('#botones_venta,#capicor').css({right:'20px'});
	}
	
	if (TamVentana()[1]<625)
		$('#section').css({height:'495px'});
	else
		$('#section').css({height:TamVentana()[1]-130});

	if ($('#logo').offset().top>=460)
		$('#logo').css({top:'auto',bottom:'45px'});	
	if ($('#logo').offset().top<460)
		$('#logo').css({top:'460px',bottom:'auto'});
		
	
	$('#content-wrap #section.mostrar').css({display:'block'});
	
	/*if (jQuery.browser.msie && jQuery.browser.version == 6)
		$('#section .mostrar').css({opacity:1,width:'274px'});
	else*/
		$('#section .mostrar').css({opacity:1,width:'204px'});
	
	if (!$('#section').is('.mostrar'))
		$('#section').show('drop', {direction:'up'}, 1000,function() {
			$('#section-wrap').animate({opacity:1},200);
			$('#location a').css({display:'block'});
			$('.jScrollPaneContainer').css({display:'block'});
		});
			
	$('#section-wrap').jScrollPane({showArrows:true, scrollbarWidth:11, scrollbarMargin:15, arrowSize:16});
	
	$(window).bind('resize', function() {
		if (TamVentana()[0]<1164)
		{
			$('#header,#footer').css({width:'1164px'});
			$('#botones_venta,#capicor').css({right:1164-TamVentana()[0]+20});
		}
		else
		{
			$('#header,#footer').css({width:'100%'});
			$('#botones_venta,#capicor').css({right:'20px'});
		}
		
		if (TamVentana()[1]<625)
			$('#section').css({height:'495px'});
		else
			$('#section').css({height:TamVentana()[1]-130});
		
		if ($('#logo').offset().top>=460)
			$('#logo').css({top:'auto',bottom:'45px'});	
		if ($('#logo').offset().top<460)
			$('#logo').css({top:'460px',bottom:'auto'});
	});
	
	
	$('#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);');
			$(this).click(function() {
				$('#section-wrap').animate({opacity:0},200,function() {
					$('#location a').css({display:'none'});
					$('.jScrollPaneContainer').css({display:'none'});
					$('#section').hide('drop', {direction:'up'},1000);
					$('#image img').fadeOut(500);
					$('.subsection-wrap').fadeOut(200);
					$('#subsection').hide('drop', {direction:'up'},1000);
					$('#list').fadeOut(500);
				});
				setTimeout('window.location.href = \''+ $(this).attr('rel') +'\';',1000);
			});
		}
		
		$(this).hover(function(){
			if (!$(this).parent().is('.activo'))
				$(this).stop().animate({backgroundColor:$("#wrapper").attr('class').split('-')[1]},500);
	    },function(){
			if (!$(this).parent().is('.activo'))
			{
				$(this).stop().animate({backgroundColor:$("#wrapper").attr('class').split('-')[1]},100);
				$(this).animate({backgroundColor:$("#wrapper").attr('class').split('-')[2]},800);
			}
	    });
	});
	
	
	$('a.idioma').click(function() {
		$('#form_lang').append('<input type="hidden" value="'+$(this).attr('name')+'" name="l" />');
			
		$('#form_lang').submit();
	});
});


$(window).load(function() {
	$('#logo a img').css({marginTop:-($('#logo a img').height()/2)});
	
	$("#cuenta").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		onComplete			: function() {
			$('#log').focus();
		}
	});
	
	$("#editar,#registrarse,#newsletter").fancybox({
		'width'				: 570,
		'height'			: 380,
		'autoScale'			: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	
	$("#recordar").fancybox({
		'width'				: 310,
		'height'			: 80,
		'autoScale'			: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	
	var datos=document.URL.split('?');

	if (datos[1]=="login=ko")
		alert("Datos incorrectos!");
		
	
	$('img').each(function() {
		$(this).bind('contextmenu', function() {
			return false
		});

		$(this).bind('copy', function() {
			return false
		});

		$(this).bind('dragstart', function() {
			return false
		});
	});
});


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;
}
