$package("js.util");
/**
 * Construct a Timer.
 * @param {Integer} interval
 */
js.util.Timer = 
function (interval){
	if(interval!=null)
		this.delay = this.interval = interval;
	var js = "if("+this.getName()+".ontimer)"+this.getName()+".ontimer("+this.getName()+");";
	this.run  = new Function(js); 
}
js.util.Timer.prototype = new js.lang.Thread();
js.util.Timer.prototype.interval = 1000;
js.util.Timer.prototype.active   = false;
js.util.Timer.prototype.ontimer  = function(){};

js.util.Timer.prototype.setInterval = function (interval){
	if(interval!=null)
		this.delay = this.interval = interval;
}

js.util.Timer.prototype.setActive = function (active){
	this.active = active;
	if(active) {
		if(this.started) return;
		this.delay = this.interval;
		this.start();
	}
	else{
		this.stop();
	}
}
