function mycarousel_itemLoadCallback(carousel, state)
{
		var mot_clef = $("#texteRechercheVideo").val();
		
		if(mot_clef == 'Rechercher une video...')
			mot_clef = '';
			
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    $.get(
        '/videos/search',
        {
            mot_clef: mot_clef,
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
						$("#recherchevideocarouselloader").html('');
        },
        'xml'
    );
};
function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    carousel.size(parseInt($('total', xml).text()));

    $('item', xml).each(function(i) {
        carousel.add(first + i, jQuery(this).text());
    });
};

$(document).ready(function() 
{	
	$('#recherchevideocarousel').jcarousel({
			visible: 4,
			scroll: 4,
			itemLoadCallback: mycarousel_itemLoadCallback
	});

	$("#video_search_form").submit(function() {
		if($("#texteRechercheVideo").val() != '' && $("#texteRechercheVideo").val() != 'Rechercher une video...')
		{
				$("#recherchevideocarouselloader").html('<img src="/images/loader.gif" alt="Chargement" />');
				$("#recherchevideocarousel").html('');
				$('#recherchevideocarousel').jcarousel({
						visible: 4,
						scroll: 4,
						itemLoadCallback: mycarousel_itemLoadCallback
				});
		}
		return false;
	});
});

