﻿/// <reference name="MicrosoftAjax.js" />

Type.registerNamespace("McCannErickson.Controls");

McCannErickson.Controls.Timer = function(interval)
{
	McCannErickson.Controls.Timer.initializeBase(this);
	this.interval = interval;
}

McCannErickson.Controls.Timer.prototype =
{
	add_tick: function(handler)
	{
		this.get_events().addHandler("tick", handler);
	},
	remove_tick: function(handler)
	{
		this.get_events().removeHandler("tick", handler);
	},
	dispose: function()
	{
		this.stop();
	},
	start: function()
	{
		this.tickDelegate = Function.createDelegate(this, this.tick); 
		this.timeoutReference = window.setTimeout(this.tickDelegate, this.interval);
	},
	stop: function()
	{
		window.clearTimeout(this.timeoutReference);
		delete this.tickDelegate;
	},
	tick: function()
	{
		var handler = this.get_events().getHandler("tick");
		if (handler)
		{
			handler(this, Sys.EventArgs.Empty);
		}
		this.timeoutReference = window.setTimeout(this.tickDelegate, this.interval);
	}
}

McCannErickson.Controls.Timer.registerClass("McCannErickson.Controls.Timer", Sys.Component);
