function Timer(continuestatement) {
    this.continuestatement = continuestatement;
    this.running = false;
    
    this.delay = 50;
  //this is an array containing id's and not objects, since the splice method would otherwise spoil this entire thing.
    this.objectids = new Array();
    this.ojects    = new Array();
    
    this.start = function() {
        if (!this.running) {
            this.running = true;
            //alert("start now!");
            setTimeout (this.continuestatement, 0);
        }
    }
    this.add = function(id) {
        this.objectids[this.objectids.length] = id;
        this.buildObjects();
    }
    
    this.stop = function() {
        
    }

    this.remove = function(id) {
        var o = document.getElementById(id);
        //o.innerText = o.innerText + '_0'; 
        for (var i = 0; i < this.objectids.length; i++) {
            if (this.objectids[i] == id) {
            this.objectids.splice (i,1);
            break;
            }
        }
        this.buildObjects();
    }

    this.run = function() {
        for (i = 0; i < this.objects.length; i++) {
            this.objects[i].p.move();
        }
        //quit if all objects are ready.
        if (this.objects.length != 0) {
            setTimeout (this.continuestatement, this.delay);
        }
        else {
            this.running = false; 
        }
    }//*/
    
    this.buildObjects = function() {
        var objects = new Array();
        for (var i = 0; i < this.objectids.length; i++) {
            objects[i] = document.getElementById (this.objectids[i]);
        }
        this.objects = objects;
    }
}//*/

