// Webcam status/image data refresh system - © 2007 TMP 

// This JavaScript manages the Webcam refreshing and status indicators

   redate=new  Date()                              ;// Time the last refresh occured
   webcam=new Image()                              ;// Cached Webcam image for smooth refresh
var waddr="http://ednabayalaska.net/Webcam.jpg"    ;// Image address 1
var eaddr="http://ednabayalaska.net/spycam.jpg"    ;// Image address 1
var cstat="Connecting to server... "               ;// Connection status string
var wstat=" Webcam Status: "                       ;// Webcam status string
var istat="  Image Status: "                       ;// Image status string
var ustat="  Image Update: "                       ;// Image update count string
var rstat="      Last Refresh: "                   ;// Current Refresh status string
var nstat="      Next Refresh: "                   ;// Next Refresh status string
var rtime=60                                       ;// Refresh time in seconds
var timer=3                                        ;// Timer count value
var ltime=1                                        ;// Load time room in seconds
var count=0                                        ;// Update count value
var   dec=1                                        ;// Decriment value
var start=3                                        ;// Connection started successfully switch
var ctime                                          ;// Current time
var  hour                                          ;// Current Hour
var   min                                          ;// Current Minute
var   sec                                          ;// Current Second
window.defaultStatus=(wstat+cstat)                 ;// Assign default status string 

function startClock()
{
  timer=timer-dec;

  if(start==0)
  { 
    document.getElementById("show1").innerHTML='<p> > '+istat+'Refreshed'+'<\/p>';
    document.getElementById("show2").innerHTML='<p> > '+ustat+count+'<\/p>';
    document.getElementById("show3").innerHTML='<p> > '+rstat+hour +':'+min+':'+sec+'<\/p>';
    document.getElementById("show4").innerHTML='<p> > '+nstat+timer+'<\/p>';

    if(window.defaultStatus!=' Page: Webcam.')
      window.defaultStatus=' Page: Webcam.';
    if(timer>ltime) 
      window.status=(istat+"Refreshed    "+ustat+count+rstat+hour+":"+min+":"+sec+nstat+timer); 
  }

  if(start==1)
  {
    document.getElementById("show4").innerHTML='<p align="'+'center'+'">Connection successful<\/p>';
    window.defaultStatus=(wstat+cstat+"Successful");
    start=0;
  }

  if(start==2)
  {
    document.getElementById("show4").innerHTML='<p align="'+'center'+'">Connecting to server<\/p>';
    document.Webcam_W.alt="Edna Bay West Webcam - Courtesy of EdnaBayAlaska.net";
    document.Webcam_E.alt="Edna Bay East Webcam - Courtesy of Pegak.MyStarBand.net";
    start=1;
  }

  if(timer==ltime)
  {
    if(start==0)
    {
      document.getElementById("show1").innerHTML='<p> > '+istat+'Refreshing...'+'<\/p>';
      window.status=(istat+"Refreshing..."+ustat+count+rstat+hour+":"+min+":"+sec+nstat+timer);
    }
                   redate=new Date         ();
                     hour=redate.getHours  (); if(hour<10) { hour="0"+hour; }
                      min=redate.getMinutes(); if(min <=9) {  min="0"+min ; }
                      sec=redate.getSeconds(); if(sec <=9) {  sec="0"+sec ; }
                    ctime=new Date();
    var          getTimer=ctime.getTime();
    var          camImg_W=waddr+"?"+getTimer;
    var          camImg_E=eaddr+"?"+getTimer;
    document.Webcam_W.src=camImg_W;
    document.Webcam_E.src=camImg_E;
    if(start==3)
    {
      document.getElementById("show2").innerHTML='<p align="'+'center'+'">Initialising...<\/p>';
      start=2;
    }
  }

  if(timer==0)
  { 
    if(start==0) 
    { 
      document.getElementById("show1").innerHTML='<p> > '+istat+'Refreshing...'+'<\/p>';
      window.status=(istat+"Refreshing..."+ustat+count+rstat+hour+":"+min+":"+sec+nstat+timer); 
    } 
    timer=rtime;
    count=count+dec;
  }
  // setTimeout("Function_call", n (Wait time in MS before function re-call));
  timerID=setTimeout("startClock()", 1000);
}

// END OF FILE
  