/* 
 * This code has been designed by E-leos/ABProd
 * It has been designed either for an internal application or for one customer of E-leos/ABProd
 * It remains the property of either E-leos/ABprod or of one customer of E-leos/ABProd
 * Please contact arnaud@abprod.com for more informations
 * 
 * Ce code a été réalisé par E-leos/ABProd
 * Il a été conçu soit pour une application interne, soit pour le compte d'un client
 * Il reste la propriété soit de E-leos/ABProd soit de son client
 * Veuillez contacter arnaud@abprod.com pour plus d'informations
 */

var EMFRssWidget = {
    emfrss_duration: 0,
    emfrss_current: 0,
    emfrss_direction: 1,
    emfrss_total: 0,
    emfrss_timer: 0,
    emfrss_prefix: '',
    emfrss_container: null,
    emfrss_width: 0,

    emfrssPrecedent: function( elmP, elmC, displayed )
    {
        EMFRssWidget.emfrss_current = displayed;
        EMFRssWidget.emfrss_direction = -1;
        new Effect.Parallel([
            new Effect.Move(elmP, {
                sync: true,
                x: EMFRssWidget.emfrss_width,
                y: 0,
                mode: 'relative'
            }),
            new Effect.Move(elmC, {
                sync: true,
                x: EMFRssWidget.emfrss_width,
                y: 0,
                mode: 'relative'
            })
            ], {
                duration: 0.8,
                delay: 0
            });
    },

    emfrssSuivant: function( elmC, elmN, displayed )
    {
        EMFRssWidget.emfrss_current = displayed;
        EMFRssWidget.emfrss_direction = 1;
        new Effect.Parallel([
            new Effect.Move(elmN, {
                sync: true,
                x: -EMFRssWidget.emfrss_width,
                y: 0,
                mode: 'relative'
            }),
            new Effect.Move(elmC, {
                sync: true,
                x: -EMFRssWidget.emfrss_width,
                y: 0,
                mode: 'relative'
            })
            ], {
                duration: 0.8,
                delay: 0
            });
    },

    emfrssLoad: function(url)
    {
        new Ajax.Updater(EMFRssWidget.emfrss_container, url, {
            evalScripts: true
        } );
    },

    /**
 * Called in timer rotation
 */
    emfrssRotation: function()
    {
        if( EMFRssWidget.emfrss_current == 0 ) {
            EMFRssWidget.emfrss_direction = 1;
        }
        if( EMFRssWidget.emfrss_current == (EMFRssWidget.emfrss_total-1) ){
            EMFRssWidget.emfrss_direction = -1;
        }
        if( EMFRssWidget.emfrss_direction > 0 ){
            n = EMFRssWidget.emfrss_current + 1;
            EMFRssWidget.emfrssSuivant( $(EMFRssWidget.emfrss_prefix+EMFRssWidget.emfrss_current), $(EMFRssWidget.emfrss_prefix+n), EMFRssWidget.emfrss_current+1 );
        }
        if( EMFRssWidget.emfrss_direction < 0 ){
            p = EMFRssWidget.emfrss_current - 1;
            EMFRssWidget.emfrssPrecedent( $(EMFRssWidget.emfrss_prefix+p), $(EMFRssWidget.emfrss_prefix+EMFRssWidget.emfrss_current), EMFRssWidget.emfrss_current-1 );
        }
    },

    /**
 * Clear the interval
 */
    emfrssMouseOver: function() {
        if( EMFRssWidget.emfrss_timer == 0 ){
            return;
        }
        clearInterval(EMFRssWidget.emfrss_timer);
        EMFRssWidget.emfrss_timer = 0;
    },

    /**
 * Clear the interval
 */
    emfrssMouseOut: function() {
        if( EMFRssWidget.emfrss_timer != 0 ){
            return;
        }
        EMFRssWidget.emfrss_timer = setInterval('EMFRssWidget.emfrssRotation()', EMFRssWidget.emfrss_duration);
    },

    /**
     * Start the news rotation
     */
    emfrssStartRotation: function( container, prefix, duration, total, width )
    {
        EMFRssWidget.emfrss_container = container;
        EMFRssWidget.emfrss_prefix = prefix;
        EMFRssWidget.emfrss_duration = duration;
        EMFRssWidget.emfrss_total = total;
        EMFRssWidget.emfrss_width = width;
        EMFRssWidget.emfrss_timer = setInterval('EMFRssWidget.emfrssRotation()', duration);
        Event.observe( container, 'mouseover', EMFRssWidget.emfrssMouseOver );
        Event.observe( container, 'mouseout', EMFRssWidget.emfrssMouseOut );
    }
}
