// A cloud moves form side to side at the top of the screen.
// LANGUAGE="JavaScript1.3"
//
// This seems most compatible when included at the end of the body of the HTML.
// just before the closing </BODY>.
// This insures that the window.document.body object exists, which we need to access.


if (1) //if (document.images)
{
  var isNetscape = (navigator.appName.indexOf("Netscape") !=-1);
  var timerCloudID = null;
  var CloudDirection = 1;
  var MoveInterval = 1000; /* Run again after 1.000 seconds. */
  var CloudXpos = 50;
  var CloudYpos = 0;
  var bCloudInitComplete = 0;

  // get size of window
  var WinHeight, WinWidth;
  if (isNetscape)
  {
    WinHeight = window.innerHeight /* + document.scrollTop  */ ;
    WinWidth = window.innerWidth   /* + document.scrollLeft */ ;
  }
  else
  {	
    WinHeight = window.document.body.clientHeight + document.body.scrollTop;
    WinWidth = window.document.body.clientWidth + document.body.scrollLeft;
  }

  function CloudLoaded()
  {
    bCloudInitComplete = 1;
    if (isNetscape)
    {
      document.LayerClouds.visibility = 'show';
    }
    else
    {
      LayerClouds.style.visibility = 'visible';
    }
  }

  function MoveClouds()
  {
    if (!bCloudInitComplete)
    { // not quite ready yet
      ;
    } // not quite ready yet
    else
    { // up and running
      // Calculate new cloud position.
      CloudXpos += CloudDirection;

      // If it hits one of the sides, go back the other way.
      if (CloudXpos <= 0)
        CloudDirection = 1;
      if (CloudXpos + 318 >= WinWidth)
        CloudDirection = -1;

      // Move the cloud.
      if (isNetscape)
      {
        document.LayerClouds.top = CloudYpos;
        document.LayerClouds.left = CloudXpos;
      }
      else
      {
        LayerClouds.style.top = CloudYpos;
        LayerClouds.style.left = CloudXpos;
      }

      // Occasionally change direction.
      if (Math.random() * 200 < 1)
        CloudDirection *= -1;

      // Every few steps, change the speed.
      if (CloudXpos % 10 == 0)
        MoveInterval = (10 + Math.random() * 1000);
    } // up and running

    timerCloudID=setTimeout("MoveClouds()",MoveInterval);
  } // MoveClouds()

  function StartMovingClouds()
  {
    // Add the DIV tags to make the cloud layer.
    CloudInvocation = "";
    if (isNetscape)
    {
      // Netscape 4.7 refuses to dynamically reposition the first DIV tag, so we provide a hidden sacrifical DIV tag.
      CloudInvocation = CloudInvocation + '<div id="junk_jmc" style="position: absolute; visibility: hidden; height: 1; width: 1;"></div>';
      // Ideally, the following <IMG> would include LOWSRC="../common/invisible.gif", so you don't see a marker for the image while it loads.
      // Unfortunately, Netscape messes up the size of the image when it replaces the LOWSRC. So we hide the animation layer until the
      // image is loaded.
      CloudInvocation = CloudInvocation + '<div id="LayerClouds" style="position: absolute; visibility: hidden; top: 0; left: 50; height: 158; width: 318; ">';
      CloudInvocation = CloudInvocation + '<IMG SRC="../common/jmc_Clouds.gif" WIDTH=318 LENGTH=158 ALIGN=left onLoad="return CloudLoaded();">';
      CloudInvocation = CloudInvocation + '</div>';
    }
    else
    {	
      CloudInvocation = CloudInvocation + '<div id="LayerClouds" style="position: absolute; visibility: hidden; top: 0; left: 50; height: 158; width: 318; ">';
      CloudInvocation = CloudInvocation + '<IMG SRC="../common/jmc_Clouds.gif" WIDTH=318 LENGTH=158 ALIGN=left onLoad="return CloudLoaded();">';
      CloudInvocation = CloudInvocation + '</div>';
    }
    document.write(CloudInvocation);

    // Start it up...
    MoveClouds();
  } // StartMovingClouds()
} // if (document.images)
