/**
 * carousel des thématiques
 */

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
    chargeHover();
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
    chargeHover();
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<div class="libelle_thema"><p class="libelle_thema_titre">' + item.thema + '</p><p class="libelle_thema_nombre">' + item.quantite + '</p></div><a href="' + item.link + '">' + item.url + '</a>';
};

jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
    if ((t/=d) < (1/2.75)) {
        return c*(7.5625*t*t) + b;
    } else if (t < (2/2.75)) {
        return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
    } else if (t < (2.5/2.75)) {
        return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
    } else {
        return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
    }
};

function chargeHover()
{
     $("ul#mycarousel li").hover(
            function(){
                  //$(this).children("a").children("img").attr({ src: "../images/thematique_tradition.jpg"});
                  //$(this).children("div").css("display","block");
                  $(this).children("div").show('normal');
                  return false;
            },
            function(){
                  //$(this).children("a").children("img").attr({ src: "../images/thematique_musique.jpg"});
                  //$(this).children("div").css("display","none");
                  $(this).children("div").hide('normal');
                  return false;
            }
      );
}

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        wrap: 'circular',
        //easing: 'BounceEaseOut',
        animation: 1000,
        scroll: 3,
        auto: 0,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
});

/**
 * R�alise un submit du form permettant l'affichage des �v�nements par type 
 *  lorsque l'on clique sur une image du carrousel
 */
function searchByTypeEvenement( id_evt )
{
	document.form_type.id_type_evenement.value = id_evt ;
	document.form_type.submit();
}
