$(document).ready(function() {
	
	/**
	 * We use the initCallback callback
	 * to assign functionality to the controls
	 */
	function mahe_carousel_initCallback(carousel) {
	    jQuery('.control-slider a').bind('click', function() {
	    	//event.preventDefault();
	    	//console.debug(parseInt($(this).attr('href').replace('#', '')) + 1);
	    	cle = parseInt($(this).attr('href').replace('#', ''))
	        carousel.scroll(jQuery.jcarousel.intval(cle + 1));
	    	//alert('test');
	    	//alert(this.offsetLeft);
	    	//console.debug(this.offsetLeft);
	    	/*if(this.offsetLeft < 16){
	    		// BUG IE 7
	    		//alert(this.clientLeft);
	    		$("#blue-arrow").animate({
        			left: this.offsetLeft + 187
        		});
        	} else {
        		if(this.offsetLeft < 21){
        			// BUG IE 7
        			$("#blue-arrow").animate({
            			left: this.offsetLeft + 87
            		});
        		} else {*/
        			$("#blue-arrow").animate({
        				left: this.offsetLeft + 7	
        			});
        		//}	
        	//}	
	        
	        //Changer la legende
	        if($("#ville-"+cle).val()){
	        	$('#titre_legend').html($("#titre-"+cle).val() + ' (' + $("#ville-"+cle).val() + ')');
	        }else{
	        	$('#titre_legend').html($("#titre-"+cle).val());
	        }
	        
	        $('#decouvrir a').attr('href', $("#link-"+cle).val());
	        //return false;
	    });

	};
	

    $('#slideshow').jcarousel({
      scroll: 1,
      visible: 1,
      initCallback: mahe_carousel_initCallback,
      buttonNextHTML: null,
      buttonPrevHTML: null
    });
});
