// CKOI.COM 2010
// romain.lefebvre@corusent.com

jQuery(function(){
	$("#webdif li").each(function (i) {
		i = i+1;
		$('.webdif-control').append('<li><a href="javascript:;" id="item-' + i + '">' + i + '</a></li>');
	});
	
	jQuery('#webdif').jcarousel({
        start: 1,
		scroll: 1,
		wrap: 'last',
		auto: 6,
		buttonNextHTML: null,
        buttonPrevHTML: null,
		initCallback: mycarousel_initCallback,
		itemVisibleInCallback: {
			onBeforeAnimation: mycarousel_itemVisibleInCallbackAfterAnimation
        },
		itemVisibleOutCallback: {
            onBeforeAnimation: mycarousel_itemVisibleOutCallbackAfterAnimation
        }
    });
	
});


function mycarousel_initCallback(carousel)
{
    jQuery('.webdif-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        carousel.stopAuto();
		return false;
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });	
};


function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	//display('Item #' + idx + ' is now visible');
	$('.webdif-control').find('#item-' + idx).addClass('active');
};
function mycarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
	//display('Item #' + idx + ' is no longer visible');
	$('.webdif-control').find('#item-' + idx).removeClass('active');
};
