/* FIX car IE8 ne gere toujours pas array.indexOf */
if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj) {
        for (var i = 0; i < this.length; ++i) {
            if (this[i] == obj) {
                return i;
            }
        }
        return -1;
    }
}

$(document).ready(function(){

    $('#news_wrapper').cycle({
        timeout: 6000,
        fx:      'fade',
        next:    '#next',
        prev:    '#prev'
        /* after:   onAfter */
    });

    $('#toutes-actus-cycle').cycle({
        timeout: 1000,
        fx:      'fade',
        pause:   1
    });

    $('#pause').bind('click', function() {
        if ($('#pause').hasClass('play')) {
            $('#news_wrapper').cycle('resume');
        } else {
            $('#news_wrapper').cycle('pause');
        }
        $('#pause').toggleClass('play');
        return false;
    });

    function onAfter() { 
        $('#output').html("News id is :"+this.id);
        id_actu=(this.id).replace("news","");
        $('#lire_link').attr("href","index.php?id=11&tx_ttnews[backPid]=2&tx_ttnews[tt_news]="+id_actu);
        /* MODIF PA : ajoute le num actu */
        nb_actus = $('.news_box').length;
        all_actus = new Array();
        $('.news_box').each(function() {
            all_actus.push($(this).attr('id'));
        });
        var num_actu;
        num_actu = parseInt(1 + parseInt(all_actus.indexOf("news" + id_actu)));
        addendum_actu = num_actu + '/' + nb_actus;
        $('#num_actu').html(addendum_actu);
        /* console.log($('#num_actu').html(addendum_actu)); */
    }
});
