HIIndexClockController = {
	
	boxDate:null,
	boxHours:null,
	boxMinutes:null,
	boxSeconds:null,
	lastUpdateTime:0,
	
	
	setup:function() {
		this.boxDate = document.getElementById('boxIndexClockDate');
		this.boxHours = document.getElementById('boxIndexClockHours');
		this.boxSeparator_1 = document.getElementById('boxIndexClockSeparator_1');
		this.boxMinutes = document.getElementById('boxIndexClockMinutes');
		this.boxSeparator_2 = document.getElementById('boxIndexClockSeparator_2');
		this.boxSeconds = document.getElementById('boxIndexClockSeconds');
		this.boxDate = this.boxDate.firstChild;
		this.boxHours = this.boxHours.firstChild;
		this.boxMinutes = this.boxMinutes.firstChild;
		this.boxSeconds = this.boxSeconds.firstChild;
		
		if (this.boxDate && this.boxHours && this.boxSeparator_1 && this.boxMinutes && this.boxSeparator_2 && this.boxSeconds) {
			setInterval(this.doUpdateClock, 200);
		}
	},
	
	
	doUpdateClock:function() {
		HIIndexClockController.updateClock();
	},
	
	
	updateClock:function() {
		var date = new Date();
		var newUpdateTime = Math.ceil(date.getTime() / 1000);
		if (this.lastUpdateTime == newUpdateTime) return;
		this.lastUpdateTime = newUpdateTime;
		var newDate = date.getDate() + ' ' + CRDate.getMonthName(date.getMonth(), 1) + ' ' + date.getFullYear() + ' года, ';
		if (this.boxDate.nodeValue != newDate) {
			this.boxDate.nodeValue = newDate;
		};
		var newHours = this.padDateTimeValue(date.getHours());
		if (this.boxHours.nodeValue != newHours) {
			this.boxHours.nodeValue = newHours;
		};
		var newMinutes = this.padDateTimeValue(date.getMinutes());
		if (this.boxMinutes.nodeValue != newMinutes) {
			this.boxMinutes.nodeValue = newMinutes;
		}
		this.boxSeconds.nodeValue = this.padDateTimeValue(date.getSeconds());
		this.boxSeparator_1.className = this.boxSeparator_2.className = (this.lastUpdateTime % 2 ? 'genInvisible' : '');
	},
	
	
	padDateTimeValue:function(value) {
		value = value.toString();
		if (value.length < 2) {
			value = '0' + value;
		}
		return value;
	}
	
	
	
}


CREvent.setObserving(window, CREvent.eventTypeLoad, function() { HIIndexClockController.setup(); });
