/* $Id$ */

function Timeline(window) {
    this.window = window;
    this.events = [];
    this.timeouts = [];
    this.timeoutId = null;
    this.window._tl = this;
}

Timeline.prototype.addEvent = function(timeout, event) {
    if (!event) {
        if (DEBUG) {
            console.log("tried add undefined event!");
        }
        return;
    }
    
    this.events.push(event);
    this.timeouts.push(timeout);
}

Timeline.prototype.play = function(window) {

    if (this.timeouts.length == 0) {
        this.window.status = "Timeline is empty";
        return;
    }
    
    var timeout = this.timeouts.shift();
    
    this.timeoutId = this.window.setTimeout("_tl.playEvent()", timeout);
}

Timeline.prototype.playEvent = function() {
    var event = this.events.shift();
    event();
    
    if (this.timeouts.length == 0) {
        this.window.status = "Timeline ended";
        return;
    }
    
    var timeout = this.timeouts.shift();
    
    this.timeoutId = this.window.setTimeout("_tl.playEvent()", timeout);
}

/* 

 * $Log$
 * Revision 1.3  2011-04-14 18:22:47  justme
 * Major bugfixing and refactoring
 *

 * Revision 1.2  2007-04-16 16:41:28  patrickkopp

 * does not add undefined events

 *

 * Revision 1.1  2006/12/10 18:25:50  justme

 * *** empty log message ***

 *

 * Revision 1.1  2006/12/04 17:19:56  justme

 * Initial revision

 *

 */


