var currentBook = 2;
jQuery(document).ready ( function() {
	
jQuery('.list-home').jcarousel({
	scroll: 3,
	animation: 200,
	wrap: 'circular',
	initCallback: mycarousel_initCallback,
	itemVisibleInCallback: {
				onBeforeAnimation: mycarousel_beforeAnimation,
				onAfterAnimation: mycarousel_afterAnimation
	},
	itemVisibleOutCallback:mycarousel_itemVisibleOutCallback
});

jQuery(".list-home-recommended").jcarousel({
    scroll: 1,
	auto:0,
	start:1,
	animation: 'slow',
    wrap: 'circular',
    initCallback: carousel_1_initCallback,
    itemVisibleInCallback: {
				onBeforeAnimation: carousel_1_beforeAnimation,
				onAfterAnimation: carousel_1_afterAnimation
	},
	itemVisibleOutCallback:carousel_1_itemVisibleOutCallback
});

});

function carousel_1_initCallback(carousel) {
	jQuery('.jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});
};

function carousel_1_beforeAnimation(carousel,element,i,status){
    
	
	var idx = carousel.index(i, carousel.options.size);
	carousel.add(i,carousel.get(idx).html())
	
	if(status!="init"){
		if(status=="next"){
			currentBook = i-1;
			oldBook = i-2;
		}
		else{
			currentBook = i+1;
			oldBook = i+2;
		}
	
	carousel.get(oldBook).find('img').animate({width:'90px',left:'45px',paddingTop:'58'},300);
	carousel.get(oldBook).find('.preu').hide();
	carousel.get(oldBook).find('.info_on').removeClass("info_on").addClass("info");
	
	carousel.get(oldBook+1).unbind('click');
	carousel.get(oldBook-1).unbind('click');
	}
	carousel.get(currentBook).find('img').animate({width:'128px',left:'26px',paddingTop:'0'},400, function(){
		carousel.get(currentBook).find('.preu').show();
		carousel.get(currentBook).find('.info').removeClass("info").addClass("info_on");
	});
	
	//buttons for prev and next books
	carousel.get(currentBook+1).bind('click', function() { carousel.next(); return false;});
	carousel.get(currentBook-1).bind('click', function() { carousel.prev(); return false;});
}


function carousel_1_afterAnimation(carousel,element,index,status){
    var idx = carousel.index(index, carousel.options.size);
		carousel.selected=idx
};

function carousel_1_itemVisibleOutCallback(carousel, item, i, state, evt){
   	if (i>carousel.options.size || i<0){
    	carousel.remove(i);
    }
  	carousel.startAuto();
};

function mycarousel_initCallback(carousel) {
		jQuery('.jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});
};

function mycarousel_beforeAnimation(carousel,element,i,status){
	var idx = carousel.index(i, carousel.options.size);
	carousel.add(i,carousel.get(idx).html())
}

function mycarousel_afterAnimation(carousel,element,index,status){
    var idx = carousel.index(index, carousel.options.size);
		carousel.selected=idx
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){
   	if (i>carousel.options.size || i<0){
    	carousel.remove(i);
    }
  	carousel.startAuto();
};