// v.1.1 - May 7th 2006
// - fixed nasty year handling in iexplorer
//
// v.1.2 - May 7th 2006
// - Added support for daynames and date endings
// - Separated time and date display
// - 24hour format on time display
//
// v.1.3 - May 7th 2006
// - fixed dayname array
var dateending="";
var month = new Array(11);
elements = document.getElementsByTagName("html");
var langName;
for(i=0;i<elements.length;i++){
	if(elements[i].getAttribute('lang')=='en'){
		langName="en";
		month[0] = "January";
		month[1] = "February";
		month[2] = "March";
		month[3] = "April";
		month[4] = "May";
		month[5] = "June";
		month[6] = "July";
		month[7] = "August";
		month[8] = "September";
		month[9] = "October";
		month[10] = "November";
		month[11] = "December";
	}else{				
		langName="ar";
		month[0] = "يناير";
		month[1] = "فبراير";
		month[2] = "مارس";
		month[3] = "إبريل";
		month[4] = "مايو";
		month[5] = "يونيو";
		month[6] = "يوليو";
		month[7] = "أغسطس";
		month[8] = "سبتمبر";
		month[9] = "أكتوبر";
		month[10] = "نوفمبر";
		month[11] = "ديسمبر";
	}
}

function TimeKeeper(container) {
	if (!document.getElementById || !document.getElementById(container)) return
	this.container=document.getElementById(container)
	this.localtime= new Date()
	this.updateContainer()
}

TimeKeeper.prototype.updateContainer=function(){
	var thisobj=this;
	var today = new Date();							// Date object to store the current date
	var todaysDay = today.getDay() + 1;	
	// Stores the current day number 1-7
	var todaysDate = today.getDate();					// Stores the current numeric date within the month
	getEnding(todaysDate);
	var todaysMonth = month[today.getUTCMonth()];				// Stores the current month 1-12
	var todaysYear = today.getFullYear();	
	if(langName=='en')
	{
		document.getElementById('date').innerHTML=todaysDate+'<span style=\"vertical-align:super; font-size:60%;\">'+dateending+'</span> '+todaysMonth+' '+todaysYear;
	}
	else
	{
		document.getElementById('date').innerHTML=todaysDate+' '+todaysMonth+' '+todaysYear;
	}
	setTimeout(function(){thisobj.updateContainer()}, 10000)
}

function getEnding(day) {
    if (day == 1 || day == 21 || day == 31)
	{
		dateending = 'st';
	}
	else if (day == 2 || day == 22)
	{
		dateending ='nd';
	}
	else if (day == 3 || day == 23)
	{
		dateending = 'rd';
	}
	else
	{
		dateending = 'th';
	}
}