Topic: "turning webcams on and off" at different times of day

I thought I had a sweet, simple Javascript function to turn a webcam on and off depending on the time of day but I guess it's more complicated than I thought. So I sort of have two questions.

1) Is this the right tactic? If so, how can I fix it? What am I missing?
2) If this is wrong, how should I do it?

Thanks.

Go here: http://tinyurl.com/nrxwtm and then click webcam or add ?page_id=3  to the URL

The code is essentially this:

<script language="Javascript">
<!--

now = new Date

if (now.getHours() < 8) {
    document.write('<img src="http://www.XXXXXXX.com/wp/wp=content/themes/XXXX/img/webcam-offair.gif" alt="" />')
}
else if (now.getHours() < 12) {
   document.write('<APPLET codebase="http://70.17.255.114:1205/program/" code="javaviewer.Viewer.class" archive="SonySncP1View.jar" name="viewer" width="340" height="270" hspace="0" vspace="0" align="top"><param name="ParamViewMode" value="00000003"><param name="ParamColorCtrlBack" value="000000"><param name="ParamColorPictFrame" value="000000">
<param name="ParamColorDateFore" value="00E000"></APPLET></div><div class="Webcam2-button"><a href="http://www.XXXXXXX.com/wp/?page_id=39">&nbsp;</a></div>')
}
else if (now.getHours() < 14) {
    document.write('<img src="http://www.XXXXXXX.com/wp/wp=content/themes/XXXX/img/webcam-nap.gif" alt="" />')
}
else if (now.getHours() < 17) {
    document.write('<APPLET codebase="http://70.17.255.114:1205/program/" code="javaviewer.Viewer.class" archive="SonySncP1View.jar" name="viewer" width="340" height="270" hspace="0" vspace="0" align="top"><param name="ParamViewMode" value="00000003"><param name="ParamColorCtrlBack" value="000000"><param name="ParamColorPictFrame" value="000000">
<param name="ParamColorDateFore" value="00E000"></APPLET></div><div class="Webcam2-button"><a href="http://www.XXXXXXX.com/wp/?page_id=39">&nbsp;</a>')
}

else {
    document.write('<img src="http://www.XXXXXXX.com/wp/wp=content/themes/XXXX/img/webcam-offair.gif" alt="" />')
}
//-->
</script>