eon.clock = {
	element: null,
	handle: false,
	seconds: false,
	months: ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Des'], // @todo: language...
	start: function(id) {
		this.element = $(id);
		if (!this.element)
			debug('Cannot start clock. No element with id: ' + id);
		else
			this._start(1);
	},
	_start: function(delay) {
		if (!delay)
			delay = 1000;
		this.handle = setTimeout("eon.clock._update()", delay);
	},
	stop: function() {
		if (!this.handle)
			return;
		clearTimeout(this.handle);
		this.handle = false;
	},
	_update: function() {
		this.stop();
		var dt = new Date();
		var str = dt.getDate() + ". " + this.months[dt.getMonth()] + " " + dt.getFullYear() + " ";
		str += this._format_num(dt.getHours()) + ":" + this._format_num(dt.getMinutes());
		if (this.seconds)
			str += ":" + this._format_num(dt.getSeconds());
		this.element.innerHTML = str;
		this._start();
	},
	_format_num: function(num) {
		if (num < 10)
			return '0'+num;
		else
			return num;
	}
}

