
function myTimer()
{
	this.timers = new Array(0);
	
	this.add = function (fnc, interval, initial)
	{
		if (fnc != null && interval > 0)
		{
			var timer = new Object;
			var id = -1;
			timer.interval = interval;
			timer.fnc = fnc;
			timer.stop = false;
			var n=0;
			while (this.timers[n] != null)
				n++;
			id = n;	
			
			this.timers[id] = timer;
			setTimeout("timerHelper(" + id + ");", ((initial && initial > 0)? initial : interval));
			return id;
		}
		return -1;
		
	}
	
	this.remove = function(id)
	{
		if (this.timers[id])
		{
			this.timers[id].stop = true;
		}
	}
	
	this._exec = function(id)
	{
		if (this.timers[id] && this.timers[id].fnc != null && this.timers[id].interval > 0)
		{
			if (this.timers[id].stop == true)
			{
				this.timers[id] = null;
			}
			else
			{
				if (this.timers[id].fnc() == true)
				{
					setTimeout("timerHelper(" + id + ");", this.timers[id].interval);
				}
				else
				{
					this.timers[id] = null;
				}
			}
		}
		else
		{
			this.timers[id] = null;
		}	
	}
}

var Timer = new myTimer(); 

function timerHelper(id)
{
	Timer._exec(id);
}

