

function Scheduler(myName) {
	var me = this;
	var debug = 0;
	this.ts = new Array();
	this.rs = new Array();

	this.queue = function(command, timeout) {
		if(timeout == 0) {
			eval(command);
			return;
		}
		var myTO = me.ts[command];
		var isRunning = me.rs[command];
		if (typeof(myTO) == 'number') {
			window.clearTimeout(myTO);
		}
		if(isRunning) {
			// if we're running then check back in a bit
			var myCom = myName + '.queue("' + command + '", ' + timeout + ')';
			if(debug) logger.dump(myName + ' queuing ' + myCom);
			me.ts[command] = window.setTimeout(myCom, timeout);
		} else {
			// lock the cleaning queue til this run is done
			me.rs[command] = true;
			var myCom = command + ';' + myName + '.rs["' + command + '"] = false;';
			if(debug) logger.dump(myName + ' running ' + myCom);
			window.setTimeout(myCom, timeout);
		}
	}
}
