// script by alfred.korn of digital.paper.inc - www.digitalpaper.com

// holds the name of the subdirectory that contains all your clock images
//  "" means that the images are in the same directory as the script
//  "clockimages/" means that the images are in the clockimages directory
var image_dir = "clockimages/";
var spacer_dir = "graphics/miscgraphics/"

switch (image_sel) 
{
        case 0 : image_dir = "clockimages/"; spacer_dir = "graphics/miscgraphics/"; break;
        case 1 : image_dir = "../clockimages/"; spacer_dir = "../graphics/miscgraphics/"; break;
        case 2 : image_dir = "../../clockimages/"; spacer_dir = "../../graphics/miscgraphics/"; break;
        case 3 : image_dir = "../../../clockimages/"; spacer_dir = "../../../graphics/miscgraphics/"; break;
}

// update every how many seconds?
var speed = 1;

// ********** NO NEED TO MODIFY ANYTHING BELOW THIS POINT ************

// preload number images
img0 = new Image(); img0.src = image_dir + "0.gif";
img1 = new Image(); img1.src = image_dir + "1.gif";
img2 = new Image(); img2.src = image_dir + "2.gif";
img3 = new Image(); img3.src = image_dir + "3.gif";
img4 = new Image(); img4.src = image_dir + "4.gif";
img5 = new Image(); img5.src = image_dir + "5.gif";
img6 = new Image(); img6.src = image_dir + "6.gif";
img7 = new Image(); img7.src = image_dir + "7.gif";
img8 = new Image(); img8.src = image_dir + "8.gif";
img9 = new Image(); img9.src = image_dir + "9.gif";

// fixes a Netscape 2 and 3 bug
function getFullYear(fullyear) {
 curyear = fullyear.getYear(); 
 
 if (curyear < 1000) curyear += 1900;
 
 return curyear;
}
function calcDate() {
var temp = "";
curdate = new Date();
var dowarray = new Array("st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th",
                         "th", "th", "th", "th", "th", "th", "th", "th", "th", "th",
                         "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th",
                         "st")

curday = curdate.getDay();
document.dayofweek.src = image_dir + "d" + curday + ".gif";

curmon = curdate.getMonth();
document.month.src = image_dir + "m" + curmon + ".gif";

curdow = curdate.getDate();
temp = curdow;
curdow = (curdow >= 10 ? "" : "0") + curdow;
document.date1.src = image_dir + curdow.substring(0,1) + ".gif";
document.date2.src = image_dir + curdow.substring(1,2) + ".gif";
document.date3.src = image_dir + dowarray[temp - 1] + ".gif";

curyear = "" + getFullYear(curdate);
document.year1.src = image_dir + curyear.substring(0,1) + ".gif";
document.year2.src = image_dir + curyear.substring(1,2) + ".gif";
document.year3.src = image_dir + curyear.substring(2,3) + ".gif";
document.year4.src = image_dir + curyear.substring(3,4) + ".gif";

calcAmPm();
}

function calcAmPm(){
 ampm = new Date();
 var hours = ampm.getHours();
 var minutes = ampm.getMinutes();
 
 document.morn.src = image_dir + "am.gif";
 if ((hours >= 12 && (minutes >= 1) || (hours >= 13))) { document.morn.src = image_dir + "pm.gif"; }

 calcTime();
}

speed *= 1000; // time kept in milliseconds not seconds

function calcTime() {
curtime = new Date();
 
curhour = curtime.getHours();
if (curhour > 12) curhour = curhour - 12;
curhour = (curhour < 10 ? "0" : "") + curhour;
document.hour1.src = image_dir + curhour.substring(0,1) + ".gif";
document.hour2.src = image_dir + curhour.substring(1,2) + ".gif";

curmin = curtime.getMinutes(); 
curmin = (curmin < 10 ? "0" : "") + curmin;
document.min1.src = image_dir + curmin.substring(0,1) + ".gif";
document.min2.src = image_dir + curmin.substring(1,2) + ".gif";

cursec = curtime.getSeconds();
cursec = (cursec < 10 ? "0" : "") + cursec;
document.sec1.src = image_dir + cursec.substring(0,1) + ".gif";
document.sec2.src = image_dir + cursec.substring(1,2) + ".gif";

if ((curhour < 1) && (curmin < 1) && (cursec < 1)) calcDate();

if ((curhour == 12) && (curmin < 1) && (cursec < 1)) calcAmPm();

setTimeout("calcTime()",speed);
}