if (typeof window.NGSControlsNamespace == "undefined")
{
	window.NGSControlsNamespace = {};
}

NGSControlsNamespace.Ticker = function (listener)
{
	this.Listener = listener;
	this.IntervalPointer = null;
}

NGSControlsNamespace.Ticker.prototype =
{
	Configure : function (config)
	{
		this.Duration = config.Duration;
		this.Interval = 16;
	},
	
	Start : function ()
	{
		clearInterval(this.IntervalPointer);
		this.TimeElapsed = 0;
		var instance = this;
		var closure = function ()
		{
			instance.Tick();
		}
		
		this.Tick();
		this.IntervalPointer = setInterval(closure, this.Interval);
	},
	
	Tick : function ()
	{
		this.TimeElapsed += this.Interval;
		this.Listener.OnTick(this.TimeElapsed);
		
		if (this.TimeElapsed >= this.Duration)
		{
			this.Stop();
		}
	},
	
	Stop : function ()
	{
		if (this.IntervalPointer)
		{
			this.Listener.OnTickEnd();
			clearInterval(this.IntervalPointer);
			this.IntervalPointer = null;
		}
	}
	
}

