// JavaScript Document

var globalcountdown;

function Countdown(targetID, endDate)
{
 this.targetID  = targetID;
 this.endDate  = endDate;

 this.clock =
 {
  seconds  :  0,
  minutes  :  0,
    hours  :  0,
     days  :  0
 };

 this.increment = function()
 {
  var count = Math.floor((this.endDate.getTime() - new Date().getTime()) / 1000);

  if(count <= 0)
  { return; }
  this.clock.seconds = count % 60;
   count = Math.floor(count / 60);
   
  this.clock.minutes = count % 60;
   count = Math.floor(count / 60);

  this.clock.hours = count % 24;
   count = Math.floor(count / 24);

  this.clock.days = count;

  this.writeClock();

  globalcountdown = this;

  setTimeout("globalcountdown.increment();", 500);
 };

 this.writeClock = function()
 {
  document.getElementById("dd_1").innerHTML = pad(this.clock.days);
  document.getElementById("hh_1").innerHTML = pad(this.clock.hours);
  document.getElementById("mm_1").innerHTML = pad(this.clock.minutes);
  document.getElementById("ss_1").innerHTML = pad(this.clock.seconds);
 };

}

function pad(i)
{
 return i < 10  ? "0" + i : i;
}