onlinePath = "../";
onlinePathHTML = "";
m_random = Math.round(10000 * Math.random());

function openAnyWindow(url, name, w, h)
{
  window.open('http://cad.chp.ca.gov/', name, 'status,resizable,scrollbars,width=' + w + ',height=' + h + '');
  openAWindow(url, name, w, h);
}

function reloadGIF()
{
  // test to see if there is an object to reference 
  if (document.FOtrafficmap)
  {
    // make sure there is a src field and that it is not empty (I would be surprised if this fails)
    if (document.FOtrafficmap.src != null && document.FOtrafficmap.src != "")
    {
      // get the src and reload it
      var trafficMapLocation = document.FOtrafficmap.src;
      document.FOtrafficmap.src = trafficMapLocation;
    }
    else
    {
      // reload document if the above fails
      window.location.reload();
    }
  }
  else
  {
    // reload document if the above fails
    window.location.reload();
  }
}

function openAWindow(url, name, w, h)
{
  reloadGIF();
  // open new window
  popupWin = window.open(url, name, 'status,resizable,scrollbars,width=' + w + ',height=' + h + '');
  // Bring focus to window -- doesn't work with Netscape ;(
  popupWin.focus();
  return popupWin;
}


function openPlaybackWindow(cameraName, cameraLocation)
{
   win = openAWindow("","FOcamera", 0,0);
   win.resizeTo(460,550);
   win.document.writeln("<html><head>");
   win.document.writeln("<title>Fontana Cam: " + cameraLocation + "</title>");
   win.document.writeln("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=iso-8859-1\" />");
   win.document.writeln("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />");

   win.document.writeln("<script language=\"javascript\">");
   win.document.writeln("<!-- ");
   win.document.writeln("var onlinePath = \"" + onlinePath + "\";");
   win.document.writeln("var m_random = Math.round(10000 * Math.random());");
   win.document.writeln("var m_imageURL;");
   win.document.writeln("window.onerror=null;");
   win.document.writeln("function badImageURL() {");
   win.document.writeln("   document.images[0].src = \"" + onlinePath + "images/cameras/Cam_NA.jpg\";");
   win.document.writeln("   return true;");
   win.document.writeln("}");
   win.document.writeln("function refreshImage() {");
   win.document.writeln("   document.images[0].src = m_imageURL + \"?" + m_random + "\";");
   win.document.writeln("   setTimeout(\"refreshImage()\",180000);");
   win.document.writeln("}");
   win.document.writeln("function startRefreshTimer(imageURL) {");
   win.document.writeln("   m_imageURL = imageURL;");
   win.document.writeln("   setTimeout(\"refreshImage()\",180000);");
   win.document.writeln("}");


   win.document.writeln("function beginSnapshotPlayback(cameraName, cameraLocation) {");
   win.document.writeln("   win = window.open('','FOcamera', 'status,resizable,scrollbars,width=0,height=0');");
   win.document.writeln("   win.resizeTo(460,550);");
   win.document.writeln("   win.document.writeln('<html><head>');");
   win.document.writeln("   win.document.writeln('<title>Fontana Camera: ' + cameraLocation + '</title>');");
   win.document.writeln("   win.document.writeln('<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=iso-8859-1\\\" />');");
   win.document.writeln("   win.document.writeln('<meta http-equiv=\\\"Content-Script-Type\\\" content=\\\"text/javascript\\\" />');");

   win.document.writeln("   win.document.writeln('<script type=\\\"text/javascript\\\" language=\\\"javascript\\\">');");
   win.document.writeln("   win.document.writeln('var m_imageNdx;');");
   win.document.writeln("   win.document.writeln('var m_imageURL;');");
   win.document.writeln("   win.document.writeln('var m_refreshCtr;');");
   win.document.writeln("   win.document.writeln('var m_timerID;');");
   win.document.writeln("   win.document.writeln('window.onerror=null;');");
   win.document.writeln("   win.document.writeln('function badImageURL() {');");
   win.document.writeln("   win.document.writeln('   return true;');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('function nextImage() {');");
   win.document.writeln("   win.document.writeln('  if (++m_imageNdx > 10) {');");
   win.document.writeln("   win.document.writeln('     m_imageNdx=1;');");
   win.document.writeln("   win.document.writeln('     if (++m_refreshCtr > 36) return;');");
   win.document.writeln("   win.document.writeln('  }');");
   win.document.writeln("   win.document.writeln('  if (m_imageNdx == 1)');");
   win.document.writeln("   win.document.writeln('    document.images[10].border=0;');");
   win.document.writeln("   win.document.writeln('  else');");
   win.document.writeln("   win.document.writeln('    document.images[m_imageNdx-1].border=0;');");
   win.document.writeln("   win.document.writeln('  document.images[m_imageNdx].border=1;');");
   win.document.writeln("   win.document.writeln('  document.images[m_imageNdx].src = m_imageURL + \\\"_\\\" + m_imageNdx + \\\".jpg?' + m_random + '\\\";');");
   win.document.writeln("   win.document.writeln('  document.images[0].src = document.images[m_imageNdx].src;');");
   win.document.writeln("   win.document.writeln('  m_timerID = setTimeout(\\\"nextImage()\\\",500);');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('function startPlayback(cameraName) {');");
   win.document.writeln("   win.document.writeln('   m_imageURL = \\\"' + onlinePath + 'images/cameras/\\\" + cameraName;');");
   win.document.writeln("   win.document.writeln('   m_imageNdx=0; m_refreshCtr=0;');");
   win.document.writeln("   win.document.writeln('   document.snapshots.status.value=\\\"playing snapshots...\\\";');");
   win.document.writeln("   win.document.writeln('   nextImage();');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('function stopPlayback(imageNdx) {');");
   win.document.writeln("   win.document.writeln('  clearTimeout(m_timerID);');");
   win.document.writeln("   win.document.writeln('  if (imageNdx == m_imageNdx) {');");
   win.document.writeln("   win.document.writeln('    document.snapshots.status.value=\\\"playing snapshots...\\\";');");
   win.document.writeln("   win.document.writeln('     nextImage();');");
   win.document.writeln("   win.document.writeln('  } else {');");
   win.document.writeln("   win.document.writeln('    document.snapshots.status.value=\\\"pausing playback...(click outlined snapshot to restart playback)\\\";');");
   win.document.writeln("   win.document.writeln('    document.images[m_imageNdx].border=0;');");
   win.document.writeln("   win.document.writeln('    m_imageNdx = imageNdx;')");
   win.document.writeln("   win.document.writeln('    document.images[imageNdx].border=1;');");
   win.document.writeln("   win.document.writeln('    document.images[imageNdx].src = m_imageURL + \\\"_\\\" + imageNdx + \\\".jpg?' + m_random + '\\\";');");
   win.document.writeln("   win.document.writeln('    document.images[0].src = document.images[imageNdx].src;');");
   win.document.writeln("   win.document.writeln('  }');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('</script>');");

   win.document.writeln("   win.document.writeln('</head><body onload=\\\"startPlayback(\\\'' + cameraName + '\\\');\\\">');");
   win.document.writeln("   win.document.writeln('<form name=\\\"snapshots\\\"><table border=\\\"0\\\" cellspacing=\\\"0\\\" cellpadding=\\\"0\\\">');");
   win.document.writeln("   win.document.writeln('<tr><td background=\\\"' + onlinePath + 'images/cameras/Cam_NA400.jpg\\\"><center><img width=\\\"400\\\" height=\\\"300\\\" src=\\\"' + onlinePath + 'images/cameras/\" + cameraName + \"_1.jpg?\" + m_random + \"\\\" onError=\\\"javascript:return badImageURL();\\\" /></center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center><input name=\\\"status\\\" size=\\\"60\\\" value=\\\"loading snapshots...(may take a few minutes on slow connections)\\\" /></center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center><img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_1.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(1);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_2.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(2);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_3.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(3);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_4.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(4);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_5.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(5);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_6.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(6);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_7.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(7);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_8.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(8);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_9.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(9);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + onlinePath + 'images/cameras/' + cameraName + '_10.jpg?' + m_random + '\\\" onClick=\\\"javascript:stopPlayback(10);\\\" /></center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center>This snapshot series is regenerated every 5 minutes.</center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center><font face=\\\"arial, helvetica\\\" size=\\\"2\\\"><br />');");
   win.document.writeln("   win.document.writeln('The camera snapshots are provided courtesy of<br />');");
   win.document.writeln("   win.document.writeln('<a href=\\\"http://www.fontana.org/\\\" target=\\\"_blank\\\">City of Fontana, California, Traffic Operations</a><br /></font>');");
   win.document.writeln("   win.document.writeln('<font face=\\\"arial, helvetica\\\" size=\\\"1\\\">&copy;2002 Iteris, Inc</font></center></td></tr>');");
   win.document.writeln("   win.document.writeln('</table></form></body></html>');");
   win.document.writeln("   win.document.close();");
   win.document.writeln("   win.focus();");
   win.document.writeln("}");

   win.document.writeln("// -->");
   win.document.writeln("</script>");

   win.document.writeln("</head><body onload=\"javascript:startRefreshTimer('" + onlinePath + "images/cameras/" + cameraName + "_1.jpg');\">");
   win.document.writeln("<form><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
   win.document.writeln("<tr><td><center><img width=\"400\" height=\"300\" src=\"" + onlinePath + "images/cameras/" + cameraName + "_1.jpg?" + m_random + "\" onError=\"javascript:return badImageURL();\" /></center></td></tr>");
   win.document.writeln("<tr><td><center>This snapshot image is regenerated every 5 minutes.</center></td></tr>");
   win.document.writeln("<tr><td><br /><center><font face=\"arial, helvetica\">If you have a high-speed internet connection, you can<br />");
   win.document.writeln("try our new<input type=\"submit\" value=\"SnapShot Playback\" onclick=\"javascript:beginSnapshotPlayback('" + cameraName + "','" + cameraLocation + "');\">mode.<br />");
   win.document.writeln("<font color=#ff0000 size=\"1\"><b>[NOT RECOMMENDED FOR DIALUP INTERNET CONNECTIONS]</b></font></font></center></td></tr>");
   win.document.writeln("<tr><td><center><br /><font face=\"arial, helvetica\" size=\"2\">");
   win.document.writeln("The camera snapshots are provided courtesy of<br />");
   win.document.writeln("<a href=\"http://www.fontana.org/\" target=\"_blank\">City of Fontana, California, Traffic Operations</a><br /></font>");
   win.document.writeln("<font face=\"arial, helvetica\" size=\"1\">&copy;2002 Iteris, Inc</font></center></td></tr>");
   win.document.writeln("</table></form></body></html>");
   win.document.close();
}

function openCaltranCameraWindow(cameraName, cameraLocation, imageURL)
{
   win = openAWindow("","FOcamera", 0,0);
   win.resizeTo(380,450);
   win.document.writeln("<html><head>");
   win.document.writeln("<title>Caltrans Camera</title>");
   win.document.writeln("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=iso-8859-1\" />");
   win.document.writeln("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />");

   win.document.writeln("<script type=\"text/javascript\" language=\"javascript\">");
   win.document.writeln("<!-- ");
   win.document.writeln("var m_imageURL;");
   win.document.writeln("window.onerror=null;");
   win.document.writeln("function refreshImage() {");
   win.document.writeln("   document.images[0].src = m_imageURL + \"?\" + Math.random();");
   win.document.writeln("   setTimeout(\"refreshImage()\",120000);");
   win.document.writeln("}");
   win.document.writeln("function startRefreshTimer(imageURL) {");
   win.document.writeln("   m_imageURL = imageURL;");
   win.document.writeln("   setTimeout(\"refreshImage()\",120000);");
   win.document.writeln("}");
   win.document.writeln("// -->");
   win.document.writeln("</script>");

   win.document.writeln("</head><body onload=\"javascript:startRefreshTimer('" + imageURL + "');\">");
   win.document.writeln("<table border=0 cellspacing=0 cellpadding=0>");
   win.document.writeln("<tr><td background=\"" + onlinePath + "images/cameras/Cam_NA320.jpg\"><center><img width=\"320\" height=\"240\" src=\"" + imageURL + "?" + m_random + "\" /></center></td></tr>");
   win.document.writeln("<tr bgcolor=\"BLACK\"><td><center><font size=2 color=\"WHITE\">" + cameraLocation + "</font></center></td></tr>");
   win.document.writeln("<tr><td><center><font face=\"arial, helvetica\" size=\"2\"><br />");
   win.document.writeln("The snapshot image is provided courtesy of<br />");
   win.document.writeln("<a href=\"http://www.dot.ca.gov/dist8/\" target=\"_blank\">Caltrans District 8, San Bernadino</a> and<br />");
   win.document.writeln("<a href=\"http://www.fontana.org/\" target=\"_blank\">City of Fontana, California, Traffic Operations</a><br /></font>");
   win.document.writeln("<font face=\"arial, helvetica\" size=\"1\">&copy;2001 Iteris, Inc</font></center></td></tr>");
   win.document.writeln("</table></body></html>");
   win.document.close();
   win.focus();
}

function openRealPlayerWindow(imageURL)
{
   win = openAWindow("","FOcamera", 0,0);
   win.resizeTo(450,550);
   win.document.writeln("<html><head><title>Caltrans Camera</title></head>");
   
  win.document.writeln("<body bgcolor='#FFFFFF'>");
  win.document.writeln('<object id="MediaPlayer1" width=400 height=350 classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject" align="middle">');
  win.document.writeln('<param name="url" value="'+ imageURL +'">');
  win.document.writeln('<param name="ShowStatusBar" value="true">');
  win.document.writeln('<param name="AutoStart" value="true">');
  win.document.writeln('<embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/" src="'+ imageURL +'" align="middle" width=400 height=350 showstatusbar="true"></embed>');
  win.document.writeln('</object>');
  win.document.writeln("<BR><BR><FONT SIZE='2' FACE='Tahoma' >To view this streaming video, you will need the free Windows Media Player plugin.  You can downoad it <A HREF='http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx?displang=en&qstechnology' target='_new'>here.</A>");
  win.document.writeln("</body></html>");   
   

//   win.document.writeln("<frameset rows=325,100 frameborder=\"NO\" border=\"0\" framespacing=\"0\">");
//   win.document.writeln("  <frame name=\"video\" scrolling=\"NO\" noresize src=\"" + imageURL + "\">");
//   win.document.writeln("  <frame name=\"player warning\" scrolling=\"NO\" noresize src=\"" + onlinePathHTML + "RealPlayerWarning.html\">");
//   win.document.writeln("</frameset>");
//   win.document.writeln("<noframes><body bgcolor=\"#FFFFFF\">");
//   win.document.writeln("I'm sorry, Your browser does not support frames.<br />");
//   win.document.writeln("<a href='" + imageURL + "'>Click here</a> to continue on to the Caltrans streaming video page.<br />");
//   win.document.writeln("To view this streaming video, you will need the free RealPlayer plugin.");
//   win.document.writeln("</body></noframes></html>");

   win.document.close();
   win.focus();
}

function leavingSite(newSiteHREF, newSiteName)
{
   reloadGIF();
   win = window.open('','EXTERNAL_LINK');
   win.document.writeln("<html><head>");
   win.document.writeln("<title>You Are Now Leaving the Traffic Web Site</title>");
   win.document.writeln("	<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
   win.document.writeln("	<meta name='Posted' contents='02/19/2003'>");
   win.document.writeln("</head><body bgcolor='#FFFFFF'>");
   win.document.writeln("<img name='titlebar' usemap='#m_titlebar' src='" + onlinePath + "assets/images/titlebar.gif' width='761' height='75' border='0'> ");
   win.document.writeln("<hr align='center' width='80%'>");
   win.document.writeln("<br clear=all />");
   win.document.writeln("<p align=center><font size=+2 color='navy'><b>You Are About To Leave The<br />Fontana / Ontario Traffic Information<br />Web Site</b></font></p>");
   win.document.writeln("<br clear=all />");
   win.document.writeln("<hr align='center' width='80%'>");
   win.document.writeln("<table width='70%' align='center'>");
   win.document.writeln("<tr><td>");
   win.document.writeln("<p align='center'><br><B>You are about to access <A href='" + newSiteHREF + "'>" + newSiteName + "</a></B><br><br></p>");
   win.document.writeln("</td></tr>");
   win.document.writeln("<tr><td><p align='justify'><font size='+1'><strong>Please note:</strong></font>");
   win.document.writeln("&nbsp;&nbsp; Links to web sites outside of this Traffic Information site are offered for your convenience");
   win.document.writeln(" in accessing related information. Please be aware that when you exit this Traffic web site,");
   win.document.writeln(" you are subject to the privacy policy of the new site. ");
   win.document.writeln("&nbsp;The City of Fontana does not attest to the accuracy of information provided by linked sites,");
   win.document.writeln(" and such information does not necessarily represent the viewpoint of the City of Fontana. </p>");
   win.document.writeln("</td></tr></table>");
   win.document.writeln("<p><div align='center'><font size=+1><b><A href='" + newSiteHREF + "'>Continue</a></b></font></div>");
   win.document.writeln("<p align='center'>OR</p>");
   win.document.writeln("<p align='center'><a href='javascript:window.close()'>Close Window</a></p>");
   win.document.writeln("<td width='76'></td></tr></table></font>");
   win.document.writeln("</body></html>");
   win.document.close();
   win.focus();
}