function Clock(container_selector, time) {
	
	if (time) 
		this.time = time;
	else {
		var now = new Date;
		var h = D.getHours();
		var m = D.getMinutes(); 
		if (m < 10) m = '0' + m;
		var s = D.getSeconds(); 
		if (s < 10) s = '0' + s;
		var time_string = h + ':' + m + ':' + s;
		this.time = time_string;
	}
	
	/*
	Работать исходя из временной метки не получается, 
	т.к. javascript при переводе её в дату применяет
	преобразование временных зон клиента (отвадить нельзя).
	Из-за этого работать через объект Date вообще нельзя.
	Поэтому будем принимать строку вида HH:MM:SS и разбирать её
	*/
	
	this.addtime = function() {
		var p = /(\d{1,2}):(\d{2}):(\d{2})/;
		var match = p.exec(this.time);
		var h = parseInt(match[1], 10);
		var m = parseInt(match[2], 10);
		var s = parseInt(match[3], 10);
		
		var new_s, new_m, new_h;
		
		new_s = (s + 1) % 60;
		
		if (new_s == 0) {
			if ((new_m = (m + 1) % 60) == 0) 
				new_h = (h + 1) % 24;
			else
				new_h = h;
		}
		else {
			new_m = m;
			new_h = h;
		}
		
		// новое значение времени:
		this.time = 
			new_h + ':' + 
			( (new_m.toString().length < 2) ? '0' + new_m : new_m ) + ':' +
			( (new_s.toString().length < 2) ? '0' + new_s : new_s ) ;
	}
	
	this.write = function() {
		$(container_selector).text(this.time);
	};
	
	this.tick = function() {
		this.write();
		this.addtime();
	}
	
	this.tick();
	
	var this_symlink = this;
	setInterval( function() { this_symlink.tick(); },  1000 );
}

