//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/*
File: 		timer.js
Author 		Steve Goeckler (sgoeckler@gmail.com)
Abstract:	js countdown timer object 
Date:		12/29/2010
*/
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function tmr(expiration, fn)
{

	var exp = new Array();
	exp = expiration.split('/')
	this.expDay= exp[1]; this.expMonth= exp[0]-1; this.expYear= exp[2];
	
	this.days= this.hours= this.mins= this.secs= 0;
	this.fn = fn;
	this.interval = 1000;

	setTimeout(fn, 250);

	this.update = function() {
	
		var dateFuture = new Date(this.expYear, this.expMonth, this.expDay, 0,0,0);
		//document.getElementById('debug').innerHTML="m:"+this.expMonth+" d:"+this.expDay+" y:"+this.expYear;
		var dateNow = new Date();			//grab current date

		var delta = dateFuture.getTime() - dateNow.getTime();	//calc milliseconds between dates
		delete dateNow;
		delta = Math.floor(delta/1000);		//set resolution to seconds

		// time expired
		if(delta < 0) {
			//document.getElementById('debug').innerHTML="Time's Up!";
			this.days = this.hours = this.mins = this.secs = 0;
		}
		else {
			this.days = Math.floor(delta/86400);	//days
			delta=delta%86400;
			this.hours=Math.floor(delta/3600);		//hours
			delta=delta%3600;
			this.mins=Math.floor(delta/60);			//minutes
			delta=delta%60;
			this.secs=Math.floor(delta);			//seconds
			setTimeout(this.fn, this.interval);
		}
	}
}

