/*
	Author:		Robert Hashemian (http://www.hashemian.com/)
	Modified by:	Munsifali Rashid (http://www.munit.co.uk/)
   Further Modified by:  Steven Chang (http://www.gurucs.com)
*/


function countdown(obj, timeleft)
{
	this.obj		= obj;
	this.Div		= obj;
	this.BackColor		= "white";
	this.ForeColor		= "black";
	this.SecondsLeft		= timeleft;
   this.DisplayFormat   = "%%D%%d %%H%%h %%M%%m %%S%%s";
	this.CountActive	= true;
	
	this.DisplayStr;

	this.Calcage		= cd_Calcage;
	this.CountBack		= cd_CountBack;
	this.Setup		= cd_Setup;
}

function cd_Calcage(secs, num1, num2)
{
  s = ((Math.floor(secs/num1))%num2).toString();
  return (s);
}
function cd_CountBack(secs)
{
  this.DisplayStr = this.DisplayFormat.replace(/%%D%%/g,	this.Calcage(secs,86400,100000));
  this.DisplayStr = this.DisplayStr.replace(/%%H%%/g,		this.Calcage(secs,3600,24));
  this.DisplayStr = this.DisplayStr.replace(/%%M%%/g,		this.Calcage(secs,60,60));
  this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,		this.Calcage(secs,1,60));

  document.getElementById(this.Div).innerHTML = this.DisplayStr;
  
  // if time reaches 0, stop counting
  if(secs > 0) {
      if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990);
  }
}
function cd_Setup()
{
	this.CountBack(this.SecondsLeft);
}
