/*
	Author:		Robert Hashemian (http://www.hashemian.com/)
	Modified by:	Munsifali Rashid (http://www.munit.co.uk/)
	Also Modified By itch.com
*/


function countdown(obj)
{
	this.obj		= obj;
	this.Div		= "clock";
	this.TargetDate		= "10/28/2007 3:00 PM";
	this.CountActive	= true;
	
	this.DisplayStr;

	this.Calcage			= cd_Calcage;
	this.CountBack			= cd_CountBack;
	this.Setup				= cd_Setup;
	this.TargetSeconds	= 0;
	
	
}

function cd_Calcage(secs, num1, num2, pad)
{
  s = ((Math.floor(secs/num1))%num2).toString();
  if (s.length < 2 && pad) s = "0" + s;
  return (s);
}

function cd_CountBack()
{
	var dnow	= new Date()
	
	var secs		= Math.floor((dnow.getTime() - this.TargetDate) / 1000) + parseInt(this.TargetSeconds);

  var days = this.Calcage(secs,86400,100000,false);
  var hours = this.Calcage(secs,3600,24,true);
	var minutes = this.Calcage(secs,60,60,true);
	var seconds = this.Calcage(secs,1,60,true);

	this.countActive = (days > 0 || hours > 0 || minutes > 0 || seconds > 0);
	if (!this.countActive) {
		this.DisplayStr = secs;	
	} else {
		this.DisplayStr="";
		if (days > 0) {
			if (days >1)
				this.DisplayStr += days + "d ";
			else
				this.DisplayStr += days + "d ";				
		}
		this.DisplayStr += hours + "h ";
		this.DisplayStr += minutes + "m ";
		this.DisplayStr += seconds + "s";
	}
			
	document.getElementById(this.Div).innerHTML = this.DisplayStr;
	var cmdText=this.obj +".CountBack()";
	setTimeout(cmdText, 990);
}

function cd_Setup()
{	
	this.TargetDate =  new Date();
	
	this.CountBack();
}
