
var countDownTimer = Class.create({
  initialize: function(toDate, id){
    this.toDate = new Date(toDate);
    this.id = id;
  },

  update: function(){
    $(this.id).update(this.getTimeLeftString());
  },


  cycle: function(){
    new PeriodicalExecuter(this.update.bind(this), 1);
  },


  getDaysLeft: function(){
    m = this.toDate - (new Date());
    with(Math){
      return floor(m/(n=1000*60*60*24));
      }
  },

  getHoursLeft: function(){
    m = this.toDate - (new Date());
    with(Math){
      n=1000*60*60*24;
      return floor((m%n)/(n=n/24));
      }
  },

  getMinutesLeft: function(){
    m = this.toDate - (new Date());
    with(Math){
      n=1000*60*60*24;
      n=n/24;
      return floor((m%n)/(n=n/60));
      }
  },

  getSecondsLeft: function(){
    m = this.toDate - (new Date());
    with(Math){
      n=1000*60*60*24;
      n=n/24;
      n=n/60;
      return floor((m%n)/(n=n/60)) ;
      }
  },


  getTimeLeftString: function(){
      daysleft = this.getDaysLeft();
     hoursleft = this.getHoursLeft();
     minsleft = this.getMinutesLeft();
     secsleft =  this.getSecondsLeft();

msg = 'Sorry but this voucher has now expired, Got another code? Click <a href="/customer/account/changecode/">HERE</a> to enter it';

if (daysleft < 0) { document.getElementById('bigboxx').innerHTML=''; return msg;  }
else if (hoursleft < 0) {  document.getElementById('bigboxx').innerHTML=''; return msg;    }
else if (minsleft < 0) { document.getElementById('bigboxx').innerHTML=''; return msg;  }
else if (secsleft < 0) {  document.getElementById('bigboxx').innerHTML='';  return msg;   }
else {

    return daysleft + ' days, '+
         hoursleft + ' hours, '+
        minsleft + ' minutes '+
     secsleft + ' seconds';
  }}
});
