﻿
chronos = new Object();
chronos.elementId="chronosSPAN";
chronos.dayNames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
chronos.monthNames=["January","February","March","April","May","June","July","August","September","October","November","December"];
this.hour=0;
this.minute=0;
this.second=0;
this.amPm="xx";
this.day=0;
chronos.dayName="day name";
chronos.month=0;
chronos.monthName="month name";
chronos.year=1900;
chronos.update = function() {
  	var d=new Date();
  	this.dayName=this.dayNames[d.getDay()];
  	this.monthName=this.monthNames[d.getMonth()];
  	
  	this.minute=d.getMinutes().toString();
  	while (this.minute.length < 2) {
  		this.minute = "0" + this.minute;
  	}
  	this.hour=d.getHours();
  	//if (this.hour < 12) {this.amPm="am";} else {this.amPm="pm";}
  	this.amPm = (this.hour < 12 ? "a" : "p") + "m"
  	if (this.hour == 0) this.hour=12;
  	if (this.hour > 12) this.hour-=12;
	this.hour = this.hour.toString();
  	
  	this.second=d.getSeconds().toString();  
  	while (this.second.length < 2) {
  		this.second = "0" + this.second;
  	}  	
  	
  	this.day=d.getDate();
  	this.month=d.getMonth()+1;
  	this.year=d.getFullYear();
  	
}
chronos.display = function(elemId) {
	if (elemId) this.elementId = elemId
	var x=document.getElementById(this.elementId);
  	x.innerHTML = this.dayName+" "+this.monthName+" "+this.day+", "+this.year+" at "+this.hour+":"+this.minute+this.amPm;
}
chronos.run = function() {
	this.update();
	this.display();
	window.setTimeout("chronos.run();",5000);	
}

chronos.run();


