function TimerControl()
{
	this.timers = new Array();
	this.timer = null;
	
	this.start = function()
	{
		this.tick();
	}
	
	this.stop = function()
	{
		this.timer.clearInterval();
	}
	
	this.tick = function()
	{
		var _parent = this;
		this.timer = setInterval(function(){
			for(i = 0;i < _parent.timers.length; i++)
				_parent.timers[i].updateValue();
			},1000);
	}
}

var timeControl = new TimerControl();

$(document).ready(function(){timeControl.start();});

function BingoTimer(selector)
{
	this.element = $(selector);
	this.m = 0;
	this.s = 0;
	this.isOn = true;
	
	this.updateValue = function()
	{
		if(this.isOn)
		{
			if(this.s == 0) 
			{
				this.m = this.m - 1;
				this.s = 59;
			}
			else
				this.s = this.s - 1;
				
			this.element.text(this.m + ":" + ((this.s < 10) ? ("0" + this.s) : this.s));
			
			if(this.s == 0)
				if(this.m == 0)
					this.isOn = false;
		}
	}
	
	this.init = function()
	{
		this.m = this.element.text().split(':')[0] * 1;
		this.s = this.element.text().split(':')[1] * 1;
		
		if(this.s == 0)
			if(this.m == 0)
				this.isOn = false;
	}
}
