jQuery(document).ready(function($){
	
	// Mark JS-blocks
	$('#recomendados, #tagCloud').addClass('js-on');

	// Carousels
	$('#recomendados>ul').jcarousel({
        scroll: 8
    });
	$('#mirada>ul').jcarousel({
        scroll: 3
    });
	$('#destacat>ul').cycle({
			fx:    'fade', 
			speed:  2000,
			pause: true,
			timeout: 8000
    });
	
	// Cycle tagCloud
	$('#tagCloudScreen').cycle({ 
		fx:    'scrollLeft', 
		speed:  1000,
		pause: true,
		timeout: 6000
	});
	
	// Popup recomendados
	$('#recomendados li').hover(
		function(){
			offset = $(this).offset();
			parentOffset = $('#recomendados').offset();
			if (offset.left - parentOffset.left > 700) $(this).addClass('right');
			$(this).addClass('show');
		},
		function(){
			$(this).removeClass('show right');
		}
	);
	
	$("#tagCategory").bind('change', function(){
		$("#tagSubCategory").html("");
		$("#tagSubCategory").attr('disabled', true);
		ajaxSelect('tagSubCategory', 0, 'descriptores', 'idcat=' + $(this).val(), '', function() {
			$("#tagSubCategory").attr('disabled', false);
		});
	});
	
	var tab = 0;
	$('#tab1 a, #tab2 a').live('click', function(e){
		if(tab == 0) {
			$('#tabsEbook').fadeOut(function(){
				$('#tabsDiaPadre').fadeIn();
				$('#tab1').html('<span>' + $('#tab1').attr('titulo') + '</span>');
				$('#tab2').html('<a href="#">' + $('#tab2').attr('titulo') + '</a>');
			});
			tab = 1;
		} else {
			$('#tabsDiaPadre').fadeOut(function(){
				$('#tabsEbook').fadeIn();
				$('#tab1').html('<a href="#">' + $('#tab1').attr('titulo') + '</a>');
				$('#tab2').html('<span>' + $('#tab2').attr('titulo') + '</span>');
			});
			tab = 0;
		}
		e.preventDefault();
		e.stopPropagation();
	});
	
	$("#btCategory").bind('click', function(){
		var id = $("#tagSubCategory").val();
		if(id != "") {
			document.location = urlWeb + '/bibliografias/?dcp=' + id;
		}
	});

});

