var minutes = new Array( 
	"o'clock", 
	"oh-one", 
	"oh-two",
	"oh-three",
	"oh-four",
	"oh-five",
	"oh-six",
	"oh-seven",
	"oh-eight",
	"oh-nine",
	"Ten",
	"Eleven",
	"Twelve",
	"Thirteen",
	"Fourteen",
	"Fifteen",
	"Sixteen",
	"Seventeen",
	"Eighteen",
	"Nineteen",
	"Twenty",
	"Twenty One",
	"Twenty Two",
	"Twenty Three",
	"Twenty Four",
	"Twenty Five",
	"Twenty Six",
	"Twenty Seven",
	"Twenty Eight",
	"Twenty Nine",
	"Thirty",
	"Thirty One",
	"Thirty Two",
	"Thirty Three",
	"Thirty Four",
	"Thirty Five",
	"Thirty Six",
	"Thirty Seven",
	"Thirty Eight",
	"Thirty Nine",
	"Forty",
	"Forty One",
	"Forty Two",
	"Forty Three",
	"Forty Four",
	"Forty Five",
	"Forty Six",
	"Forty Seven",
	"Forty Eight",
	"Forty Nine",
	"Fifty",
	"Fifty One",
	"Fifty Two",
	"Fifty Three",
	"Fifty Four",
	"Fifty Five",
	"Fifty Six",
	"Fifty Seven",
	"Fifty Eight",
	"Fifty Nine"
	 );
var hours = new Array(
	"Twelve",
	"One",
	"Two",
	"Three",
	"Four",
	"Five",
	"Six",
	"Seven",
	"Eight",
	"Nine",
	"Ten",
	"Eleven",
	"Twelve",
	"One",
	"Two",
	"Three",
	"Four",
	"Five",
	"Six",
	"Seven",
	"Eight",
	"Nine",
	"Ten",
	"Eleven",
	"Twelve"
);

var times = new Array(
	"xx 00 04 Just after %h",
	"xx 00 02 %h o'clock",
	"xx 00 02 %h",
	"xx 00 03 Around %h o'clock",
	"xx 00 04 Slightly after %h",
	"xx 00 03 Just gone %h",
	"xx 00 03 A bit past %h",
	"xx 01 04 A little past %h",
	"xx 01 04 A bit past %h",
	"xx 01 03 Just past %h",
	"xx 02 04 A hair past %h",
	"xx 03 07 Five after %h",
	"xx 03 07 Five past %h",
	"xx 08 12 Ten after %h",
	"xx 08 12 Ten past %h",
	"xx 13 16 About a quarter past %h",
	"xx 13 19 Quarter after %h",
	"xx 13 19 Around %h fifteen",
	"xx 13 19 Quarter past %h",
	"xx 18 22 Twenty after %h",
	"xx 18 22 Twenty past %h",
	"xx 23 27 Twenty five after %h",
	"xx 23 27 Twenty five past %h",
	"xx 26 29 ItŐs almost half past %h",
	"xx 27 29 Just about %h Thirty",
	"xx 27 29 Almost %h Thirty",
	"xx 27 33 Half %h",
	"xx 27 33 Half past %h",
	"xx 28 29 Nearly %h Thirty",
	"xx 28 29 Nearly Half %h",
	"xx 29 31 %h Thirty",
	"xx 31 35 Just past %h Thirty",
	"xx 31 35 Just gone Half %h",
	"xx 31 35 Just past %h thirty",
	"xx 33 37 Twenty five to %H",
	"xx 36 43 Twenty to %H",
	"xx 43 44 Nearly %h Forty five",
	"xx 43 47 About a quarter to %H ",
	"xx 41 47 Quarter to %H",
	"xx 48 52 Ten to\n%H",
	"xx 53 57 Five to %H",
	"xx 57 59 Nearly %H",
	"xx 57 59 Just before %H",
	"xx 57 59 Around %H o'clock",
	"xx 57 59 Just about %H",
	"xx 57 59 Almost %H",
	"xx 58 59 %H",
	"xx 58 59 A hair before %H",
	"xx 58 59 A couple before %H",
	"xx 57 59 A bit before %H",
	"00 00 00 Midnight",
	"11 55 00 Lunch!",
	"12 00 00 Noon",
	"12 00 05 Lunch!",
	"17 00 10 ItŐs quitting time!",
	"23 57 58 Too close to midnight to be sober!"
	);

var lastTimeMinute;
lastTimeMinute = -1;

window.onresize = setFont;
function setFont()
{
	var text = document.getElementById("TimeDiv");
	//var W = document.body.offsetWidth;
	var W = document.body.offsetWidth;
	text.style.fontSize=Math.floor(W/6) + "px";
}
function Update()
{
	var myDate = new Date();
	if (!(myDate.getMinutes() == lastTimeMinute )) {
		lastTimeMinute = myDate.getMinutes();
 		if(document.all){
    		 document.getElementById('TimeDiv').innerText = FormatTime(myDate);
		} else{
		    document.getElementById('TimeDiv').textContent = FormatTime(myDate);
		}
		setFont();
	}
	// Schedule the next update in one second
	setTimeout("Update()",1000);
}
function FormatTime(myDate)
{	
	var h;
	var m = new String();
	var s = new String();
 	h = myDate.getHours();
 	m = myDate.getMinutes();
 	s = myDate.getSeconds();

	var t1 = new String();
	var t2 = new String();
	var hh = new String();
	var timePossibilities = new Array();
	for (i=0;i<times.length;i++)
	{
		hh = times[i].substr(0,2);
		t1 = times[i].substr(3,2);
		t2 = times[i].substr(6,2);
		// If the hour is don't care, or the hour matches, and the time range matches, then this is a condender
		if( (hh == "xx" || hh == h) && ( m >= t1 && m <= t2 )) {
			timePossibilities.push( times[i].substr( 9 ));
		}
	}
	// Now choose a random value from the possibilities
	if( timePossibilities.length > 0 ) {
		timePossibilities.push( "%h-%m"); // Show the exact time every now and then...
		var random_number=Math.floor(Math.random()*timePossibilities.length);
			var t3 = new String();
			t3 = timePossibilities[ random_number ];
			t3 = t3.replace("%h", hours[h] );    // %h = current hour
			t3 = t3.replace("%H", hours[ h+1 ]); // %H = next hour
			t3 = t3.replace("%m", minutes[ m ]); // %m = minutes
			return t3;
	}

	// If no times found, just display the time!
	m = "" + m;
 	if( m.length == 1 ) {
 		m = "0"+ m;
 	}
 	s = "" + s;
 	if( s.length == 1) {
 		s = "0" + s;
 	} 
 	return h + ':' + m + ':' + s;
}
