$(document).ready(function() {
	var nb_items = $('#mycarousel li').length;
	$('#mycarousel').jcarousel({
		scroll: 1,
		animation: 1500,
		visible: 7,
		auto: 3,
		wrap: 'circular',
		initCallback: function (carousel) {
			// Disable autoscrolling if the user clicks the prev or next button.
			carousel.buttonNext.bind('click', function() {
				carousel.startAuto(0);
				carousel.options.animation = 'fast';
			});
			carousel.buttonPrev.bind('click', function() {
				carousel.startAuto(0);
				carousel.options.animation = 'fast';
			});
			// Pause autoscrolling if the user moves with the cursor over the clip.
			carousel.clip.hover(function() {
				carousel.stopAuto();
			}, function() {
				carousel.startAuto();
			});
		},
		itemVisibleInCallback: {
			onBeforeAnimation: function (carousel, li, index, action) {
				var i = ((index-1) % nb_items);
				if(i < 0)
				{
					i += nb_items;
				}
				i++; // pour aller de 1 à nb_items
				carousel.add(index, $('#mycarousel li[jcarouselindex="'+i+'"]').html());
				carousel.startAuto();
			}
		},
		itemVisibleOutCallback: function(carousel, li, index, action) {
			if(index < 0 || index > nb_items)
			{
				carousel.remove(index);
			}
		}
	});
	$('#mycarousel').css('visibility', 'visible');
});