
$j(document).ready(function(){	

	pos_debut = 1;
	if ($j('#carousel ul li').length > 2) {
		if ($j('#carousel ul li').length > 4) {
			pos_debut = 3;
		} else {
			pos_debut = 2;
		}
	}
		
					
	$j('#carousel ul').jcarousel({
		scroll : 1,
		start: pos_debut,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		initCallback: mycarousel_initCallback,
		itemVisibleInCallback: {
			onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
            onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
        }
	});
	
	$j('#carousel ul a').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		bodyHandler: function() { 
			return '<h3>' + $j(this).siblings('.c_nom').html() + '</h3>'
			+ '<div class="a_partir">' + $j(this).siblings('.c_libelle').html() + '</div>'
			+ '<div class="prix">' + $j(this).siblings('.c_prix').html() + '</div>'; 
		},
		extraClass: "carousel",
		fixPNG: true,
		opacity: 0.8,
		left: 12,
		top: 22
	});

});

function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {

	// cache le bloc du bas
	$j('#carousel .informations').slideUp(300);
	
	// desactive l'ancien produit
	$j('.jcarousel-item-big').removeClass("jcarousel-item-big");
	
	
	// active le nouveau produit
	$j('.jcarousel-item-' + idx).addClass("jcarousel-item-big");
	$j('.jcarousel-item-' + idx + ' a').animate({ marginTop : "0px", marginLeft:"-35px"}, 600);
	$j('.jcarousel-item-' + idx + ' a img').animate({ width:"250px", height:"250px"}, 600);
	
	$j('.jcarousel-item-' + (idx-1) + ' a').animate({ marginTop : "45px", marginLeft:"-25px"}, 600);
	$j('.jcarousel-item-' + (idx-1) + ' a img').animate({ width:"160px", height:"160px"}, 600);
	
	$j('.jcarousel-item-' + (idx+1) + ' a').animate({ marginTop : "45px", marginLeft:"45px"}, 600);
	$j('.jcarousel-item-' + (idx+1) + ' a img').animate({ width:"160px", height:"160px"}, 600);
	
	$j('.jcarousel-item-' + (idx-2) + ' a').animate({ marginTop : "60px", marginLeft:"10px"}, 600);
	$j('.jcarousel-item-' + (idx-2) + ' a img').animate({ width:"130px", height:"130px"}, 600);
	
	$j('.jcarousel-item-' + (idx+2) + ' a').animate({ marginTop : "60px", marginLeft:"40px"}, 600);
	$j('.jcarousel-item-' + (idx+2) + ' a img').animate({ width:"130px", height:"130px"}, 600);
		
	$j('.jcarousel-item-' + (idx-3) + ' a').animate({ marginTop : "60px", marginLeft:"10px"}, 600);
	$j('.jcarousel-item-' + (idx-3) + ' a img').animate({ width:"130px", height:"130px"}, 600);
	
	$j('.jcarousel-item-' + (idx+3) + ' a').animate({ marginTop : "60px", marginLeft:"40px"}, 600);
	$j('.jcarousel-item-' + (idx+3) + ' a img').animate({ width:"130px", height:"130px"}, 600);

	
	
};

function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	
	$j('#indicateur').html('Article ' + idx + '|' + carousel.options.size);
	
	// actualise les infos du bas
	$j('#carousel .informations .nom').html($j('.jcarousel-item-big .c_nom').html());	
	$j('#carousel .informations .nom').attr("href", $j('.jcarousel-item-big a').attr("href"));	
	$j('#carousel .informations .prix').html($j('.jcarousel-item-big .c_prix').html());
	$j('#carousel .informations .reduc').html($j('.jcarousel-item-big .c_reduc').html());	
	$j('#carousel .informations del').html($j('.jcarousel-item-big .c_oldprix').html());
	
	// affiche le bloc du bas
	$j('#carousel .informations').slideDown(300);
	
	if(idx == carousel.size()){
		$j('#mycarousel-next').hide();
		$j('#mycarousel-next5').hide();	
	} else {
		$j('#mycarousel-next').show();
		$j('#mycarousel-next5').show();	
	}
	
	if(idx == 1){
		$j('#mycarousel-prev').hide();
		$j('#mycarousel-prev5').hide();	
	} else {
		$j('#mycarousel-prev').show();
		$j('#mycarousel-prev5').show();	
	}	
};


function mycarousel_initCallback(carousel) {
	
    $j('#mycarousel-prev').click(function() {
		carousel.options.scroll = 1;
        carousel.prev();
    });
	
	$j('#mycarousel-prev5').click(function() {
		carousel.options.scroll = 5;
        carousel.prev();
    });
	
	$j('#mycarousel-next').click(function() {
		carousel.options.scroll = 1;
        carousel.next();
    });

	$j('#mycarousel-next5').click(function() {
		carousel.options.scroll = 5;
        carousel.next();
    });

	

	
	
};


