/* anImage : animateur d'images, version 1.0
* (c) 2007 Damien Ravé (Le Caphar)
* anImage peut être librement copié ou modifié
* http://www.lepotlatch.org
*
*pour mettre une deuxiéme animation sur la meme page !!!
*--- mettre a l'endroit ou voir l'animation 
             <img src=" " id="animage_2" >
			 la premier étant
			 <img src=" " id="animage_1" >
			 
********************* et remplacer le script suivant valable que pour une animation
     <script>
     var images1 = [
         'http://www.wetterzentrale.de/pics/Rgme003.gif',
         'http://www.wetterzentrale.de/pics/Rgme123.gif',
         'http://www.wetterzentrale.de/pics/Rgme243.gif',
         'http://www.wetterzentrale.de/pics/Rgme363.gif',
         'http://www.wetterzentrale.de/pics/Rgme483.gif',
         'http://www.wetterzentrale.de/pics/Rgme603.gif',
         'http://www.wetterzentrale.de/pics/Rgme723.gif'
     ];
     new animage ('animage_1', images1, 1000, true);
     </script>

*********************remplacer par 
<script>
// Déclaration des images de la premiere animation
     var tableau_images_1 = [
   'http://www.wetterzentrale.de/pics/Rgme003.gif',
         'http://www.wetterzentrale.de/pics/Rgme123.gif',
         'http://www.wetterzentrale.de/pics/Rgme243.gif',
         'http://www.wetterzentrale.de/pics/Rgme363.gif',
         'http://www.wetterzentrale.de/pics/Rgme483.gif',
         'http://www.wetterzentrale.de/pics/Rgme603.gif',
         'http://www.wetterzentrale.de/pics/Rgme723.gif'
     ]
// Création de l'objet animage pour la premiere animation
     new animage ('animage_1', tableau_images_1, 1000, false);

// Déclaration des images de la deuxieme animation
     var tableau_images_2 = [
        'http://www.vtm.be/weer/gfx/eurweban12hr.jpg',
        'http://www.vtm.be/weer/gfx/eurweban24hr.jpg',
        'http://www.vtm.be/weer/gfx/eurweban36hr.jpg',
        'http://www.vtm.be/weer/gfx/eurweban60hr.jpg',
        'http://www.vtm.be/weer/gfx/eurweban84hr.jpg',
        'http://www.vtm.be/weer/gfx/eurweban108hr.jpg',
        'http://www.vtm.be/weer/gfx/eurweban132hr.jpg'
     ]
// Création de l'objet animage pour la deuxieme animation
     new animage ('animage_2', tableau_images_2, 1000);
 </script>
*/

// Classe animage
var animage = function(elementId,images,delai,actif) {
    this.elementId = elementId;
    this.indexActuel = 0;
    this.images = images;
    this.delai = delai;
    this.imageChargee = new Array();

    // Précharge les images
    this.prechargement = function() {
        for (i= 0; i <= this.images.length -1 ; i++) {
            this.imageChargee[i] = new Image(100,25);
            this.imageChargee[i].src= this.images[i];
        }
    }

    // Renvoie true si toutes les images sont chargées
    this.imagesChargees = function() {
        for (i= 0; i <= this.images.length -1 ; i++) {
            if (!this.imageChargee[i].complete) {
                return false;
            }
        }
        return true;
    }

    // Configure l'image de base et l'événement onClick
    this.imageDepart = function() {
        var self = this;
        if (document.getElementById(this.elementId)) {
            document.getElementById(this.elementId).src = this.images[this.indexActuel];

            document.getElementById(this.elementId).onclick = function() {
                //animage.images[self.imgNo].lanceur();
                self.lanceur();
            }

        } else {
            setTimeout(function() {
                self.imageDepart()
            },50);
        }
    }
    // Changer l'image
    this.changeImage = function() {
        if (document.getElementById(this.elementId) && this.images.length - 1 > 0 && this.imagesChargees()) {
            this.indexActuel = (this.indexActuel + 1) % (this.images.length);
            if (this.images[this.indexActuel] != undefined) {
                document.getElementById(this.elementId).src = this.images[this.indexActuel];
            }
        }
    }

    // Démarre ou arrête la boucle
    this.lanceur = function() {
        if (this.actif) {
            this.actif = 0;
            clearTimeout(this.timer);
        } else {
            this.actif = 1;
            var self = this;
            this.timer = setInterval(function() {
                self.changeImage()
                },this.delai);
        }
    }

    // Initialisation
    this.prechargement();
    this.imageDepart();
    if (actif === undefined || actif) {
        this.lanceur();
    }
}