// DigiClock
// digiclock_b.js
// Programmed by Peter Prins
// peter@alienalchemy.com
// Copyright 1999, Alien Alchemy
// www.alienalchemy.com


// Pre-Load The Digits
if (document.images){
        // clock images
        var num_0 = new Image(12,15);num_0.src="digiclock/bdigits/0.gif";
        var num_1 = new Image(12,15);num_1.src="digiclock/bdigits/1.gif";
        var num_2 = new Image(12,15);num_2.src="digiclock/bdigits/2.gif";
        var num_3 = new Image(12,15);num_3.src="digiclock/bdigits/3.gif";
        var num_4 = new Image(12,15);num_4.src="digiclock/bdigits/4.gif";
        var num_5 = new Image(12,15);num_5.src="digiclock/bdigits/5.gif";
        var num_6 = new Image(12,15);num_6.src="digiclock/bdigits/6.gif";
        var num_7 = new Image(12,15);num_7.src="digiclock/bdigits/7.gif";
        var num_8 = new Image(12,15);num_8.src="digiclock/bdigits/8.gif";
        var num_9 = new Image(12,15);num_9.src="digiclock/bdigits/9.gif";
        var num_am = new Image(24,15);num_am.src="digiclock/bdigits/am.gif";
        var num_pm = new Image(24,15);num_pm.src="digiclock/bdigits/pm.gif";
}

// Run The Clock
function displayClock(){
        if (document.images){
                document.writeln('<a href="http://www.alienalchemy.com/" target="_blank"><img src="digiclock/bdigits/0.gif" height="15" width="12" name="hh_1" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/0.gif" height="15" width="12" name="hh_2" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/colon.gif" height="15" width="6" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/0.gif" height="15" width="12" name="mm_1" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/0.gif" height="15" width="12" name="mm_2" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/colon.gif" height="15" width="6" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/0.gif" height="15" width="12" name="ss_1" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/0.gif" height="15" width="12" name="ss_2" border="0" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!"><img src="digiclock/bdigits/am.gif" height="15" width="24" name="am_pm" alt="Alien Alchemy Digital Clock. Click here to get yours too for FREE!" border="0"></a>');
                runClock();
        }
}

function runClock(){
        window.setTimeout('runClock()',1000);
        var Myclock = new Date();
        var hrs = Myclock.getHours();
        if (hrs == 0){
                x = "12"; updateClock(x,"hh");
        }
        if (hrs < 10 && hrs > 0){
                x = "0" + hrs; x = x + ""; updateClock(x,"hh");
        }
        if (hrs > 9 && hrs < 13){
                x = hrs; x = x + ""; updateClock(x,"hh");
        }
        if (hrs > 12){
                x = hrs - 12; x = x + "";
                if (x < 10){
                        x = "0" + x;
                        updateClock(x,"hh");
                }else{
                        updateClock(x,"hh");
                        }
        }
        var mins = Myclock.getMinutes();
        if (mins < 10){
                x = "0" + mins; updateClock(x,"mm");
        }else{
                x = mins + ""; updateClock(x,"mm");
        }
        var secs = Myclock.getSeconds();
        if (secs < 10){
                x = "0" + secs; updateClock(x,"ss");
        }else{
                x = secs + ""; updateClock(x,"ss");
        }
        if (hrs < 11){
                document.images["am_pm"].src=eval("num_am.src");
        }else{
                document.images["am_pm"].src=eval("num_pm.src");
        }
}

function updateClock(clock_num,clock_type){
        for (var x = 0; x < clock_num.length; x++){
                image_id = clock_type+"_"+(x+1);
                document.images[image_id].src=eval("num_"+clock_num.substring(x,x+1)+ ".src");
        }
}

if (document.images){
        displayClock();
        }
