var countDown = Class.create({
  initialize: function(params) {
    this.params = params || {};    
		this.wrapperEl = $(this.params['wrapper']);
		this.endDate = new Date(this.params['endDate']);
		this.initElements();
  },
  initElements: function() {
		this.dayCountEl = this.wrapperEl.select('#dayCount')[0];
		this.hourCountEl = this.wrapperEl.select('#hourCount')[0];
		this.minCountEl = this.wrapperEl.select('#minCount')[0];
		this.secCountEl = this.wrapperEl.select('#secCount')[0];
		this.update();
	},
	getDiffValue: function(secs,num1,num2) {
	  var s = ((Math.floor(secs/num1))%num2).toString();
	  if (true && s.length < 2)
	    s = "0" + s;
	  return s;
	},
	update: function() {
		var dnow = new Date();
		var ddiff = new Date(this.endDate-dnow);
		var gsecs = Math.floor(ddiff.valueOf()/1000);
		if (gsecs < 0) gsecs = 0;
		this.dayCountEl.innerHTML = this.getDiffValue(gsecs,86400,100000);
		this.hourCountEl.innerHTML = this.getDiffValue(gsecs,3600,24);
		this.minCountEl.innerHTML = this.getDiffValue(gsecs,60,60);
		this.secCountEl.innerHTML = this.getDiffValue(gsecs,1,60);
		if (gsecs > 0)
			this.update.bind(this).delay(1);
		//setTimeout(this.update.bind(this),1000);
	}
});

