/* animator.js - Copyright 2004 Aaron Isotton <aaron@isotton.com>.
 *
 * Version: 		1.03
 * Release date: 	2004-10-24
 * 
 * Use under the conditions of the GNU GPL.
 * 
 * New Versions & Documentation at:
 *   http://www.isotton.com/scripts/animator/
 */

var animators = new Array();

function animator_loop(index) {
    a = animators[index];
    if (!a.image) return;
    a.image.src = a.images[a.current].src;
    a.current = (a.current + 1) % a.images.length;
    setTimeout('animator_loop(' + index + ');', a.interval);
}

function Animator(imageid) {
    if (document.getElementById)
	this.image = document.getElementById(imageid);
    else if (document.all)
	this.image = document.all[imageid];
    this.images = new Array();
    this.interval = 5000;
    this.prefix = '';
    this.current = 0;
    this.index = animators.length;
    animators[this.index] = this;

    this.add = function(url) {
	var l = this.images.length;
	this.images.length++;
	this.images[l] = new Image();
	this.images[l].src = this.prefix + url;
    }

    this.run = function() {
	animator_loop(this.index);
    }
}
