/**
 *  Timeline class. Simple event timeline that allows us to attach functions to
 *  positions along a timeline.
 */
var timeline = new Class({
    queue: $A([]),
    interval: 1000,
    timer: null,
    position: 0,
    launched: 0,
    initialize: function() {},
    run: function() {
        var tl = this;
        var curr = $A(this.queue).filter(function(item, index){
            return item.run_at == tl.position;
        });
        $A(curr).each(function(item){
            tl.launched++;
            item.callback();
        })
        if(this.launched < this.queue.length) {
            this.timer = setTimeout(this.run.create({bind:this}), this.interval);            
        }
        this.position++;
    },
    stop: function() {
        clearTimeout(this.timer);
    },
    add: function(run_at, callback) {
        this.queue.push({'run_at':run_at,'callback':callback});
    }
});
