// global variables
var digitImages=new Array
/*
if (document.images)
{
	var amImage=new Image
	var pmImage=new Image
}
*/

var imgPath="/248/"
function loadImages()
{
	// make sure browsers is capable to run this 
	// script by checking that "document.images" object exists
	if (document.images)
	{	
		digitImages=new Array
		for (i=0; i<10; i++)
		{
			digitImages[i]=new Image();
			digitImages[i].src=""+imgPath+i+".gif";
		}
		// image of the am, pm sign
//		amImage.src=imgPath+"am.gif"
//		pmImage.src=imgPath+"pm.gif"
	}
}
function tickClock()
{
	// this tells the browser to call the 
	// "tickClock()" function every 1 second
	setTimeout("tickClock()", 1000);

	// make sure all the digit images are loaded
        if (document.images)
        {
		for (i=0; i<10; i++)
		{
			if (!digitImages[i].complete)
				return;
		}
	}
	thisTime = new Date()
	hours = thisTime.getHours()
	minutes = thisTime.getMinutes()
	seconds = thisTime.getSeconds()
/*
	if (hours>=12)
	{
		hours-=12
		if (document.images)
			document.ampmImage.src=pmImage.src
	}
	else
	{
		if (document.images)
			document.ampmImage.src=amImage.src
	}
*/

	if (hours>=12)
	{
		hours-=12
	}
	if (hours==0)
	{
		hours=12
	}
	
	// convert the digit to string
	// make sure there're at least 2 digits
	hourString="0"+hours+""
	minuteString="0"+minutes+""
	secondString="0"+seconds+""
	// format the hour
	hour1=parseInt(hourString.charAt(hourString.length-1))
	hour2=parseInt(hourString.charAt(hourString.length-2))
	// format the minute
	minute1=parseInt(minuteString.charAt(minuteString.length-1))
	minute2=parseInt(minuteString.charAt(minuteString.length-2))
	// format the seconds
	second1=parseInt(secondString.charAt(secondString.length-1))
	second2=parseInt(secondString.charAt(secondString.length-2))
	// for browsers that support image object, update the clock by replacing
	// the images
	if (document.images)
	{
		// update the images	
		if (hour2==0) {document.hour1Image.src=imgPath+"blank.gif"}
		else document.hour1Image.src=digitImages[hour2].src
		document.hour2Image.src=digitImages[hour1].src
		document.minute1Image.src=digitImages[minute2].src
		document.minute2Image.src=digitImages[minute1].src
		document.second1Image.src=digitImages[second2].src
		document.second2Image.src=digitImages[second1].src
	}
	// for browsers that do not support image object, put the time on the text-field
	else
	{
		document.clockForm.clock.value=""+hour2+hour1+":"+minute2+minute1+":"+second2+second1
	}
}
loadImages();
//end of LCD clock script -->
