
// DESCRIPTION:	Javascript clock runner
// DEPENDS:		prototype.js
INTERNETWARE.certainty.clock = function () {

	var clock

	return {
		init : function() {
			var clocks = $$('.clock');

			if(clocks.length > 0) {
				clock = clocks[0];
			}
			
			window.setInterval(INTERNETWARE.certainty.clock.update, 1000);
		},
		
		update : function() {
			var now = new Date();
			
			var days = now.getDate(); // NOT getDay, as that returns the day of the week
			var month = now.getMonth() + 1; // the month starts from zero so add one to get the displayable month
			var year = now.getFullYear();

			days = INTERNETWARE.certainty.clock.pad(days);
			month = INTERNETWARE.certainty.clock.pad(month);

			var hours = now.getHours();
			var mins = now.getMinutes();
			var seconds = now.getSeconds();

			hours = INTERNETWARE.certainty.clock.pad(hours);
			mins = INTERNETWARE.certainty.clock.pad(mins);
			seconds = INTERNETWARE.certainty.clock.pad(seconds);

			clock.innerHTML = days + "/" + month + "/" + year + " " + hours+":" + mins + ":" + seconds;
		},
		
		pad : function(number) {

			if (number < 10) {
				number = "0" + number;
			}
			
			return number;
		}
	}
}();

Event.observe(window, 'load', INTERNETWARE.certainty.clock.init);
