function Counter(timestamp, id, type,name,text) { 
    this._timestamp = timestamp; 
    this._id = id;
    var date = new Date();
    this._name = name;
    this._type = type;
    this._text = text;
} 
 
Counter.prototype = { 
	updateCounter: function()
	{
		var id_block = 'counter_'+this._type+'_'+this._id;
		var id_day = 'counter_'+this._type+'_'+this._id+'_day';
		var id_hour = 'counter_'+this._type+'_'+this._id+'_hour';
		var id_min = 'counter_'+this._type+'_'+this._id+'_min';
		var id_sec = 'counter_'+this._type+'_'+this._id+'_sec';
		
		this._timestamp = this._timestamp-1; 
		
		var d = 0;
		var h = 0;
		var m = 0;
		var s = 0;

		var time = this._timestamp;
		
		while(time > 0)
		{
			if(time > 60*60*24)
			{
				time = time - 60*60*24;
				d++;
			}
			else if(time > 60*60)
			{
				time = time - 60*60;
				h++;
			}
			else if(time > 60)
			{
				time = time - 60;
				m++;
			}
			else
			{
				time = time - 1;
				s++;
			}
		}
		
		if(h < 10) h = '0'+h;
		if(m < 10) m = '0'+m;
		if(s < 10) s = '0'+s;
		
		if(s == '00' && m == '00' && h == '00' && d == '0')
		{
			$(id_block).update('<b><center>'+this._text+'</center></b>');
		}
		else
		{
			$(id_day).update(d);
			$(id_hour).update(h);
			$(id_min).update(m);
			$(id_sec).update(s);
			
			window.setTimeout(this._name+'.updateCounter();',1000);
		}
	},
	start: function() 
	{ 
		this.updateCounter();
	}
} 

 
