﻿var jpo = {

    timer: null,
    nbAnim: 1,

    init: function () {

        jpo.go();

        window.setTimeout(function () {

            window.clearInterval(jpo.timer);
            jpo.timer = window.setInterval('jpo.go()', 4500);

        }, 500);

    },

    go: function () {
        $('.reunion').css({ 'top': '43px', 'left': '27px', 'opacity': '0' });
        $('.prepa').css({ 'top': '65px', 'left': '65px', 'opacity': '0' });
        $('.date').css({ 'opacity': '0', 'width': '400px', 'font-size': '50px' });
        $('.mois').css({ 'opacity': '0', 'width': '400px', 'font-size': '50px' });
        $('.url').hide();
        $('.url' + this.nbAnim).show();

        /* Nouvelle version */

        var anim = this.nbAnim;

        window.setTimeout(function () {
            $('.reunion' + anim).stop().animate({
                'opacity': '1',
                'left': '60px'
            }, 300);

            window.setTimeout(function () {
                $('.prepa' + anim).stop().animate({
                    'opacity': '1',
                    'left': '55px'
                }, 300);

                window.setTimeout(function () {
                    $('.prepa' + anim).fadeIn().delay(200).fadeOut(50).delay(2).fadeIn(50).fadeOut(50).delay(2).fadeIn(50);

                    window.setTimeout(function () {
                        $('.date' + anim).stop().animate({
                            'font-size': '20px',
                            'width': '296px',
                            'opacity': '1'
                        }, 200);

                        window.setTimeout(function () {
                            $('.mois' + anim).stop().animate({
                                'font-size': '20px',
                                'width': '296px',
                                'opacity': '1'
                            }, 200);

                            window.setTimeout(function () {
                                $('.date' + anim).fadeIn().delay(200).fadeOut(200).delay(2).fadeIn(200).fadeOut(50).delay(2).fadeIn(200).fadeOut(50).delay(2).fadeIn(200);

                                window.setTimeout(function () {
                                    $('.mois' + anim).fadeIn().delay(200).fadeOut(200).delay(2).fadeIn(200).fadeOut(50).delay(2).fadeIn(200).fadeOut(50).delay(2).fadeIn(200);

                                    window.setTimeout(function () {
                                        $('.mois' + anim + ', .date' + anim + ', .prepa' + anim + ', .reunion' + anim).stop().animate({ 'opacity': '0' });
                                    }, 1400);

                                }, 100);

                            }, 300);

                        }, 200);

                    }, 900);

                }, 100);

            }, 300);

        }, 1200, anim);

        /* Fin nouvelle version */

        var nb = $('.block-jpo').find('div:last-child').attr('class');
        nb = nb.split('mois');
        nb = nb[2];
        if (this.nbAnim == nb) {
            this.nbAnim = 1;
        } else {
            this.nbAnim++;
        }

    }

}

$(document).ready(function () {
    jpo.init();
    if ($.browser.webkit) { // On corrige le bug qui affole l'anim sur Chrome
        $(window).blur(function () {
            window.clearInterval(jpo.timer);
        });
        $(window).focus(function () {
            jpo.init();
        });
    }
});
