clock = {};

lang.clock = {
	en:{week: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
		month: ["January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
	},
	es:{week: ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"],
		month: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Deciembre"]
	}
}

ClockComponent = Class.create();
ClockComponent.prototype = {
	
	initialize: function(id, options) {
		this.id = id;
		this.self = $(this.id);
		this.date = $(this.id+'_date');
		this.time = $(this.id+'_time');
		
		this.options = options || {};
		
		Element.addClassName(this.self, this.options.color);
		
		this.timer = 0;
		this.formatTime();
		
	},
	
	formatTime: function () {
		clearInterval(this.timer);
		var now = new Date();
		
		var day = now.getDate();
		if (day < 10) day = '0' + day;
		
		var year_offset = (browser.isIE) ? 0 : 1900;
		
		var date_str = day + ' ' + lang.clock[cur_lang].month[now.getMonth()] + ' ' + (now.getYear() + year_offset);
		this.date.innerHTML = date_str;
		
		
		hour = now.getHours();
		min = now.getMinutes();
		sec = now.getSeconds();
		
		var str = "";
				
		if (this.options.military) {
			if (min <= 9) {
			  min = "0" + min; }
			if (sec <= 9) {
			  sec = "0" + sec; }
			if (hour < 10) {
			  hour = "0" + hour; }
			document.clock.sivam.value = hour + ':' + min + ':' + sec;
		} else {
			if (min <= 9) {
			  min = "0" + min;
			}
			if (sec <= 9) {
			  sec = "0" + sec;
			}
			if (hour > 12) {
			  hour = hour - 12;
			  add = " PM";
			} else {
			  hour = hour;
			  add = " AM.";
			}
			if (hour == 12) {
			  add = " PM";
			}
			if (hour == 00) {
			  hour = "12";
			}
		
			str = ((hour<=9) ? "0" + hour : hour) + ":" + min + ":" + sec + add;
				
		}
		
		this.time.innerHTML = str;
		this.timer = setInterval(this.formatTime.bind(this), 1000);
	}
	
};