

function mycarousel_itemLoadCallback(carousel, state)
{
    // Since we get all URLs in one file, we simply add all items
    // at once and set the size accordingly.
    if (state != 'init')
        return;

    jQuery.get('http://aef.mikolaj/js/jcarousel/examples/dynamic_ajax.txt', function(data) {
        mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
    });
};

function mycarousel_itemAddCallback(carousel, first, last, data)
{
    // Simply add all items at once and set the size accordingly.
    var items = data.split('|');

    for (i = 0; i < items.length; i++) {
        carousel.add(i+1, mycarousel_getItemHTML(items[i],i));
    }

    carousel.size(items.length);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url,i)
{
    return '<img class="img_n'+i+'" src="' + url + '" width="75" height="75" alt="'+i+'" />';
};


 	/**
 	 * This is the callback function which receives notification
 	 * about the state of the next button.
 	 */
 	function mycarousel_buttonNextCallback(carousel, button, enabled) {
 	    display('Next button is now ' + (enabled ? 'enabled' : 'disabled'));
 	};
 	
 	/**
 	 * This is the callback function which receives notification
 	 * about the state of the prev button.
 	 */
 	function mycarousel_buttonPrevCallback(carousel, button, enabled) {
 	    display('Prev button is now ' + (enabled ? 'enabled' : 'disabled'));
 	};
 	
 	/**
	 * This is the callback function which receives notification
 	 * right after initialisation of the carousel
 	 */
 	function mycarousel_initCallback(carousel, state) {
 	    if (state == 'init')
	        display('Carousel initialised');
 	    else if (state == 'reset')
	        display('Carousel reseted');
 	};
 	
 	/**
 	 * This is the callback function which receives notification
 	 * right after reloading of the carousel
	 */
	function mycarousel_reloadCallback(carousel) {
 	    display('Carousel reloaded');
 	};
 	
 	/**
	 * This is the callback function which receives notification
 	 * when an item becomes the first one in the visible range.
 	 */
	function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	    /*alert('Item #' + idx + ' is now the first item');    
	    $(".diaporama .mid img").attr("src", $("#AAA").attr("src"));*/
	    var idx_middle = idx + 1;
	    jQuery(".diaporama .mid img").attr("src", jQuery(".img_n"+idx_middle).attr("alt"));
	};
	
	/**
	 * This is the callback function which receives notification
 	 * when an item is no longer the first one in the visible range.
	 */
	function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
 	    display('Item #' + idx + ' is no longer the first item');
	};
 	
 	/**
 	 * This is the callback function which receives notification
 	 * when an item becomes the first one in the visible range.
	 */
 	function mycarousel_itemLastInCallback(carousel, item, idx, state) {
 	    display('Item #' + idx + ' is now the last item');
 	};
	
 	/**
 	 * This is the callback function which receives notification
 	 * when an item is no longer the first one in the visible range.
 	 */
	function mycarousel_itemLastOutCallback(carousel, item, idx, state) {
 	    display('Item #' + idx + ' is no longer the last item');
	};
 	
 	/**
 	 * This is the callback function which receives notification
 	 * when an item becomes the first one in the visible range.
 	 * Triggered before animation.
 	 */
	function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
 	    // No animation on first load of the carousel
 	    if (state == 'init')
 	        return;
	
 	    jQuery('img', item).fadeIn('slow');
	};
 	
	/**
 	 * This is the callback function which receives notification
 	 * when an item becomes the first one in the visible range.
 	 * Triggered after animation.
 	 */
 	function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
 	    display('Item #' + idx + ' is now visible');
 	};
 	
 	/**
 	 * This is the callback function which receives notification
 	 * when an item is no longer the first one in the visible range.
 	 * Triggered before animation.
 	 */
 	function mycarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) {
 	    jQuery('img', item).fadeOut('slow');
 	};
 	
 	/**
 	 * This is the callback function which receives notification
 	 * when an item is no longer the first one in the visible range.
 	 * Triggered after animation.
 	 */
 	function mycarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
 	    display('Item #' + idx + ' is no longer visible');
 	};
 	
 	/**
 	 * Helper function for printing out debug messages.
 	 * Not needed for jCarousel.
 	 */
 	var row = 1;
 	function display(s) {
 	    // Log to Firebug (getfirebug.com) if available
 	    //if (window.console != undefined && typeof window.console.log == 'function')
 	      //  console.log(s);
 	
 	    if (row >= 1000)
 	        var r = row;
 	    else if (row >= 100)
 	        var r = '&nbsp;' + row;
 	    else if (row >= 10)
 	        var r = '&nbsp;&nbsp;' + row;
 	    else
 	        var r = '&nbsp;&nbsp;&nbsp;' + row;
 	
 	    jQuery('#display').html(jQuery('#display').html() + r + ': ' + s + '<br />').get(0).scrollTop += 10000;
 	
 	    row++;
 	};




 
 
jQuery(document).ready(function() {


    jQuery('#mycarousel').jcarousel({
    	start:1,
    	scroll:1,
    	speed:100,
    	auto:2,
    	visible:5,  	
 	    itemFirstInCallback:  mycarousel_itemFirstInCallback	   	
    });


jQuery(".diaporama img").click(function() {
   jQuery(".diaporama .mid img").attr("src", jQuery(this).attr("alt"));
});


});
