/**
 * @author James Scott
 */
var Clock = new Class({
	initialize: function(c, options) {
		this.setOptions(this.getOptions(), options);

		this.months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		this.days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
		this.clock = $$(c); 
		// the periodical starts here, the * 1000 is because milliseconds required
		this.periodical = this.refresh.periodical(this.options.period * 1000, this); 
    this.refresh();

	},
 
	checkTime: function(i) {
		if (i<10) {i="0" + i;}
		return i;
	},

 
	getOptions: function(){
		return {
		period: 20
		};
	},
	refresh: function() {
		//var time = this.makeTime();
		this.clock.set('html', this.makeTime(new Date()));
		var t24 = this.make24h();
		$$('.clock-time-24h').set('html', t24);
	},
	getCopyrightYear : function() {
		if (this.today == null) {
			this.today = new Date();
		}
		var year = this.today.getFullYear();

		return (year > 2007) ? "2007-"+year : "2007";
	},
	
	makeTime: function(t){
		this.today = t;
	
		var M = this.months[this.today.getMonth()];
		var D = this.today.getDate();
		var Y = this.today.getFullYear();
		var d = this.days[this.today.getDay()];
		var H = this.today.getHours();
		var h = H;
		var e = 'am';
		if (h >= 12) {
			e = 'pm';
			h = h - 12;
		} 
		if (h == 0) {
			h = 12;
		}

		var m = this.checkTime(this.today.getMinutes());
		return d + ', ' + M + ' ' + D + ', ' + Y + ' ' + h + ":" + m + e;
	},
	make24h: function(){

		var H = this.checkTime(this.today.getHours());
		var m = this.checkTime(this.today.getMinutes());

		return H + ":" + m;
	}
});

function StartClock(c) {
	return new Clock($$(c), {});
} 

Clock.implement(new Options);
