var timerID = null
var timerRunning = false

function stopclock (){
	if(timerRunning){
		clearTimeout(timerID);
		timerRunning = false
	}
}

function showtime () {
	var now = new Date();
	year = new String(now.getYear());
	month = new String(now.getMonth() + 1);
	date = new String(now.getDate());
	hours = new String(now.getHours());
	minutes = new String(now.getMinutes());
	seconds = new String(now.getSeconds());

	document.ampm.src = (hours < 12) ? "lib/clock/dgam.gif" : "lib/clock/dgpm.gif";
	hours = (hours > 12) ? (hours - 12) + "" : hours + ""
	hours = (hours == "0") ? "12" : hours
	
	document.day1.src = (date < 10) ? "lib/clock/dg0.gif" : "lib/clock/dg" + date.charAt(0) + ".gif";
	document.day2.src = (date < 10) ? "lib/clock/dg" + date + ".gif" : "lib/clock/dg" + date.charAt(1) + ".gif";
	document.month1.src = (month < 10) ? "lib/clock/dg0.gif" : "lib/clock/dg" + month.charAt(0) + ".gif";
	document.month2.src = (month < 10) ? "lib/clock/dg" + month + ".gif" : "lib/clock/dg" + month.charAt(1) + ".gif";
	document.year1.src = (year < 10) ? "lib/clock/dg0.gif" : "lib/clock/dg" + year.charAt(0) + ".gif";
	document.year2.src = (year < 10) ? "lib/clock/dg" + year + ".gif" : "lib/clock/dg" + year.charAt(1) + ".gif";
	document.hour1.src = (hours < 10) ? "lib/clock/dg0.gif" : "lib/clock/dg" + hours.charAt(0) + ".gif";
	document.hour2.src = (hours < 10) ? "lib/clock/dg" + hours + ".gif" : "lib/clock/dg" + hours.charAt(1) + ".gif";
	document.minute1.src = (minutes < 10) ? "lib/clock/dg0.gif" : "lib/clock/dg" + minutes.charAt(0) + ".gif";
	document.minute2.src = (minutes < 10) ? "lib/clock/dg" + minutes + ".gif" : "lib/clock/dg" + minutes.charAt(1) + ".gif";
	document.second1.src = (seconds < 10) ? "lib/clock/dg0.gif" : "lib/clock/dg" + seconds.charAt(0) + ".gif";
	document.second2.src = (seconds < 10) ? "lib/clock/dg" + seconds + ".gif" : "lib/clock/dg" + seconds.charAt(1) + ".gif";

	timerID = setTimeout("showtime()",1000);
	timerRunning = true
}

function startclock () {
	stopclock();
	showtime()
}
