// set up an array for the days of the week
var weekday = new Array(7)
weekday[0]="Sun"
weekday[1]="Mon"
weekday[2]="Tue"
weekday[3]="Wed"
weekday[4]="Thu"
weekday[5]="Fri"
weekday[6]="Sat"

// set up an array for the months of the year
var month = new Array(12)
month[0]="01"
month[1]="02"
month[2]="03"
month[3]="04"
month[4]="05"
month[5]="06"
month[6]="07"
month[7]="08"
month[8]="09"
month[9]="10"
month[10]="11"
month[11]="12"


function clock() {
	// grab the date object
	var date = new Date();
		
	// convert the 24 hour clock to 12 hours
	var hours = date.getHours();
	
	if (date.getHours() > 12) {
		hours = hours - 12;
	}

	if (hours == 0) {
		hours = 12;
	}

	
	// set up references to the text fields on the clock face
	// since the clock it not triggered by Silverlight, use
	// document.getElementbyID() method to locate the
	// appropriate element.
	var SilverlightControl = document.getElementById("SilverlightControl");

	var amPmText = SilverlightControl.content.findName("amPmTextBlock");
	var hoursText = SilverlightControl.content.findName("hoursTextBlock");
	var minutesText = SilverlightControl.content.findName("minutesTextBlock");
	var secondsText = SilverlightControl.content.findName("secondsTextBlock");
	var monthText = SilverlightControl.content.findName("monthTextBlock");
	var dateText = SilverlightControl.content.findName("dateTextBlock");
	var dayText = SilverlightControl.content.findName("dayTextBlock");

	// write AM/PM indicator
	if (date.getHours() < 12) {
		amPmText.text = "AM";
	}
	else {
		amPmText.text = "PM";
	}
	
	// write the hours. if they're less than 10, add
	// some leading space to account for the lack of 
	// text alignment in Silverlight TextBlock elements
	if (hours <= 9) {
		hoursText.text = "  " + hours;
	}
	else {
		hoursText.text = hours + "";
	}

	// if the minutes are less than 10, append a leading 0 to the value
	if (date.getMinutes() <= 9) {
		minutesText.text = "0" + date.getMinutes();
	}
	else {
		minutesText.text = date.getMinutes() + "";
	}
	
	
	// if the seconds are less than 10, append a 0 to the value
	if (date.getSeconds() <= 9) {
		secondsText.text = "0" + date.getSeconds();
	}
	else {
		secondsText.text = date.getSeconds()+"";
	}

	// display the month
	monthText.text = month[date.getMonth()] + "";

	// display the date, appending a leading
	// 0 to the day if it is less than 10
	if (date.getDate() <= 9) {
		dateText.text = "0" + date.getDate();
	}
	else {
		dateText.text = date.getDate() + "";
	}
	
	// display the day
	dayText.text = weekday[date.getDay()] + "";
	
	
		
	// rinse, repeat	
	setTimeout("clock()",1000);	
}

