var eventcommonCountdown = {
	countdownRate : 100,

	init : function(endTimestamp, strings) {
		var now = new Date;

		this.tz = now.getTimezoneOffset() * 60 * 1000;

		this.endDate = endTimestamp * 1000;

		this.strings = strings;

		$().ready(this.start);
	},

	start : function(endTimestamp) {
		eventcommonCountdown._start(endTimestamp);
	},

	_start : function(endTimestamp) {

		this.el = $('#countDown');

		this.loop();
	},

	loop : function() {
		var cdDate = new Date;

		var remain = this.endDate - cdDate.getTime();

		if (remain < 0) {
			this.el.hide();
			return;
		}
		this.el.show();

		var remTest = parseInt(remain / 1000);

		if (!this.oldRemain || this.oldRemain != remTest) {
			this.oldRemain = remTest;

			cdDate.setTime(remain+this.tz);

			var d = -1;

			do {
				d += cdDate.getDate();
				cdDate.setDate(0);
			} while (cdDate.getTime() > 0);


			var h = cdDate.getHours();
			var m = cdDate.getMinutes();
			var s = cdDate.getSeconds();

			if (m < 10) m = '0' + m;
			if (s < 10) s = '0' + s;

			var str ='<div class="counter_pp"><div class="item_pp">' + d + '<br /><span>'+this.strings.days+'</span></div><div class="item_pp">' + h + '<br /><span>'+this.strings.hours+'</span></div><div class="item_pp">:</div><div class="item_pp">' + m + '<br /><span>'+this.strings.minutes+'</span></div><div class="item_pp">:</div><div class="item_pp">' + s +'<br /><span>'+this.strings.seconds+'</span></div><div class="cl"></div></div>';
	
			this.el.html(str);
		}

		setTimeout('eventcommonCountdown.loop();', this.countdownRate);
	}
};


