<!-- radar.loop.js -->
<!-- Below is the Radar Loop code plus cursor Pointer & Origin code.-->
<!-- 001207 Clive Edington, No html here, just js.  Allow No images.-->
<!-- 000728 Clive Edington, generalised the code for www.bom.gov.au-->
<!-- Thanks to Alf West and the Radar Section for the original code.-->

<!--
// Usage:
// (1) Call 'launch()' once (e.g. from BODY onload="..") to start this code.
// (2) Assumes that these Image dependent variables have already been defined:
//
// Km = nn;	// Standard 64km, 128km, 256km or 512km radar picture.
// nImages = n;
// theImageNames = new Array();
// theImageNames[0] = "filename1.gif";
// theImageNames[1] = "filename2.gif";
// ...etc...
// -----------------------------------------------------------------

// If there are some images, loop them.
// else when no images are available, exit now.
//	Assume that the enclosing html will provide a message.
  if (nImages>1) { 

// 
// Microsoft vs. Netscape.  See below for safer definitions.
  var isMS;	// = (navigator.appName.indexOf("Microsoft") != -1);
  var isNN;	// = (navigator.appName.indexOf("Netscape") != -1);
  // document.all     means Microsoft Explorer.
  // document.layers  means Netscape Navigator.
  if (document.all)	isMS = true;  else  isMS = false;
  if (document.layers)	isNN = true;  else  isNN = false;
  var doc;	// Holds a pointer to MS or NN document (see launch).
  
// Now the general Looping code.
//
//============================================================
//                >> jsImagePlayer 1.0 <<
//            for Netscape3.0+, September 1996
//============================================================
//                  by (c)BASTaRT 1996
//             Praha, Czech Republic, Europe
//
// feel free to copy and use as long as the credits are given
//          by having this header in the code
//
//          contact: xholecko@sgi.felk.cvut.cz
//          http://sgi.felk.cvut.cz/~xholecko
//
//============================================================
// Thanx to Karel & Martin for beta testing and suggestions!
//============================================================
//
//     modified by D. Watson and A. Earnhart (CIRA/CSU), 7/30/97
//     and Greg Thompson (NCAR/RAP) Dec. 11 1997

// step 1: define the images
//		See "theImageNames" set above.
 
//
// step 2: define variables used to control images
//

image_href = "";
first_image = 0;
last_image = nImages-1;

//
// step 3: define dimensions of image (would be nice if this were interactively done)
//         Presently these ARE NOT used below. See step 9
//

animation_height  = 524;
animation_width  = 564;
 
//**************************************************************************
 
//=== THE CODE STARTS HERE - no need to change anything below ===
 
//=== global variables ====

theImages = new Array();      //holds the images
imageNum = new Array();       //keeps track of which images to omit from loop
normal_delay = 300;
delay = normal_delay;         //delay between frames in 1/100 seconds
delay_step = 50;
delay_max = 4000;
delay_min = 50;
dwell_multipler = 3;
dwell_step = 1;
end_dwell_multipler   = dwell_multipler;
start_dwell_multipler = dwell_multipler - 1;
current_image = first_image;     //number of the current image
timeID = null;
status = 0;                      // 0-stopped, 1-playing
play_mode = 0;                   // 0-normal, 1-loop, 2-sweep
size_valid = 0;
 
//===> Make sure the first image number is not bigger than the last image number
if (first_image > last_image)
{
   var help = last_image;
   last_image = first_image;
   first_image = help;
}
 
//===> Preload the first image (while page is downloading)
   theImages[0] = new Image();
//
// step 4: construct filename of first image
//
   theImages[0].src = image_href + theImageNames[0];
   imageNum[0] = true;

}  // (end of if there are images to loop)
//==============================================================
//== All previous statements are performed as the page loads. ==
//== The following functions are also defined at this time.   ==
//==============================================================
 
//===> Stop the animation
function stop()
{
//== cancel animation (timeID holds the expression which calls the fwd or bkwd function) ==
  if (status == 1) {
    clearTimeout (timeID);}
  status = 0;
  return;
}
 
 
//===> Display animation in fwd direction in either loop or sweep mode
function animate_fwd()
{
   current_image++;                      //increment image number
 
  //== check if current image has exceeded loop bound ==
  if (current_image > last_image) {
    if (play_mode == 1) {              //fwd loop mode - skip to first image
      current_image = first_image;
    }
    if (play_mode == 2) {              //sweep mode - change directions (go bkwd)
      current_image = last_image;
      animate_rev();
      return;
    }
  }
 
  //== check to ensure that current image has not been deselected from the loop ==
  //== if it has, then find the next image that hasn't been ==
  while (imageNum[current_image-first_image] == false) {
    current_image++;
    if (current_image > last_image) {
      if (play_mode == 1)
        current_image = first_image;
      if (play_mode == 2) {
        current_image = last_image;
        animate_rev();
        return;
      }
    }
  }
 
  doc.animation.src = theImages[current_image-first_image].src;   //display image onto screen
  document.control_form.frame_nr.value = current_image+1;                //display image number

  delay_time = delay;
  if (current_image == first_image)  delay_time = start_dwell_multipler*delay;
  if (current_image == last_image)   delay_time =   end_dwell_multipler*delay;
 
  //== call "animate_fwd()" again after a set time (delay_time) has elapsed ==
  timeID = setTimeout("animate_fwd()", delay_time);
}
 
 
//===> Display animation in reverse direction
function animate_rev()
{
  current_image--;                      //decrement image number
 
  //== check if image number is before lower loop bound ==
  if (current_image < first_image) {
    if (play_mode == 1) {               //rev loop mode - skip to last image
       current_image = last_image;
    }
    if (play_mode == 2) {
      current_image = first_image;     //sweep mode - change directions (go fwd)
      animate_fwd();
      return;
    }
  }
 
  //== check to ensure that current image has not been deselected from the loop ==
  //== if it has, then find the next image that hasn't been ==
  while (imageNum[current_image-first_image] == false) {
    current_image--;
    if (current_image < first_image) {
      if (play_mode == 1)
        current_image = last_image;
      if (play_mode == 2) {
        current_image = first_image;
        animate_fwd();
        return;
      }
    }
  }
  
  //display image onto screen
  doc.animation.src = theImages[current_image-first_image].src;   
  
  //display image number  
  document.control_form.frame_nr.value = current_image+1;

  delay_time = delay;

  if (current_image == first_image)  delay_time = start_dwell_multipler*delay;
  if (current_image == last_image)   delay_time =   end_dwell_multipler*delay;
 
  //== call "animate_rev()" again after a set amount of time (delay_time) has elapsed ==
  timeID = setTimeout("animate_rev()", delay_time);
}
 
 
//===> Changes playing speed by adding to or substracting from the delay between frames
function change_speed(dv)
{
  delay+=dv;
  //== check to ensure max and min delay constraints have not been crossed ==
  if(delay > delay_max) delay = delay_max;
  if(delay < delay_min) delay = delay_min;
}
 
//===> functions that changed the dwell rates.
function change_end_dwell(dv) {
  end_dwell_multipler+=dv;
  if ( end_dwell_multipler < 1 ) end_dwell_multipler = 0;
}
 
function change_start_dwell(dv) {
  start_dwell_multipler+=dv;
  if ( start_dwell_multipler < 1 ) start_dwell_multipler = 0;
}
 
//===> Increment to next image
function incrementImage()
{
  var number;
  stop();
  current_image++;
  number = current_image;

  //== if image is last in loop, increment to first image ==
  if (number > last_image) number = first_image;

  //== check to ensure that image has not been deselected from loop ==
  while (imageNum[number-first_image] == false) {
    number++;
   if (number > last_image) number = first_image;
  }
 
  current_image = number;
  //display image
  doc.animation.src = theImages[current_image-first_image].src;
  //display image number
  document.control_form.frame_nr.value = current_image+1;
}
 
//===> Decrement to next image
function decrementImage()
{
  var number;
  stop();
  current_image--;
  number = current_image;
 
  //== if image is first in loop, decrement to last image ==
  if (number < first_image) number = last_image;
 
  //== check to ensure that image has not been deselected from loop ==
  while (imageNum[number-first_image] == false) {
    number--;
   if (number < first_image) number = last_image;
  }
 
  current_image = number;
  //display image
  doc.animation.src = theImages[current_image-first_image].src;
  //display image number
  document.control_form.frame_nr.value = current_image+1;
}
 
//===> "Play forward"
function fwd()
{
  stop();
  status = 1;
  play_mode = 1;
  animate_fwd();
}
 
//===> "Play reverse"

function rrev()
{
  stop();
  status = 1;
  play_mode = 1;
  animate_rev();
}

//===> "play sweep"
function sweep() {
  stop();
  status = 1;
  play_mode = 2;
  animate_fwd();
}
 
//===> Change play mode (normal, loop, swing)
function change_mode(mode)
{
   play_mode = mode;
}
 
//===> Load and initialize everything once page is downloaded (called from 'onLoad' in <BODY>)

function launch()
{
  if (nImages==0) { return; }

  startxy ()	// Start pointer-origin code.
  
  if (isMS) doc = document;
  if (isNN) doc = document.animationlayer.document;
  
  for (var i = first_image + 1; i <= last_image; i++)
  {
    theImages[i-first_image] = new Image();

//
// step 5: construct filenames of rest of images 
//

    theImages[i-first_image].src = image_href + theImageNames[i-first_image];
    imageNum[i-first_image] = true;
    doc.animation.src = theImages[i-first_image].src;
    document.control_form.frame_nr.value = i+1;
  }
 
  // this needs to be done to set the right mode when the page is manually reloaded
  change_mode (1);
  fwd();
}
 
//===> Check selection status of image in animation loop
function checkImage(status,i)
{
  if (status == true)
    imageNum[i] = false;
  else imageNum[i] = true;
}
 
//==> Empty function - used to deal with image buttons rather than HTML buttons
function func()
{
}
 
<!-- Below is the Radar moving cursor Pointer & Origin code.-->
<!-- 000728 Clive Edington, generalised the code.-->
<!-- Thanks to Alf West and the Radar Section for the original code.-->

  // Usage:
  // (1) Call 'startxy()' once (e.g. from BODY onload="..") to start this code.
  // (2) Assumes that these Image dependent variables have already been defined:
  //
  // GifFileName = "??.gif";
  // Km = nn;	// Standard 64km, 128km, 256km or 512km radar picture.
  // -----------------------------------------------------------------
  //
  // This code assumes a TABLE with a radar image and X, Y outputs, etc,
  // and then does the logic of updating X & Y whenever the mouse moves.

if (nImages>0) {
  // Compute some internal globals.
  var maxKm = Km-1;
  //  128km is .5 KmPerPixel,  512km is 2 KmPerPixel
  var KmPerPixel = Km/256;
 
  // Internal Global variables.
  var xx=0;
  var yy=0;
  var zz=0;
  var aa=0;
  var xKm=0;
  var yKm=0;
  var xKmOrigin=0;
  var yKmOrigin=0;
}

// startxy is called once after the BODY has been loaded.
//	It initalises x-y stuff and sets up mouse-event-callbacks.
//
function startxy ()
{
  // Setup mouse-move & mouse-click(down) callbacks.
  if (isMS) {
    document.body.onmousemove=move;
    document.body.onmousedown=down;
    //document.animation.src = GifFileName;
  }
  if (isNN) {
    document.captureEvents(Event.MOUSEMOVE);
    document.onMouseMove=move;
    document.captureEvents(Event.MOUSEDOWN);
    document.onMouseDown=down;
    //window.onresize = resize;  // Not needed because the loop will reload it.
    //document.animationlayer.document.animation.src = GifFileName;
  }
  resetOrigin ();
}

// Netscape-only (maybe Xterms only), reload the image after a resize.
function resize () {
      document.animationlayer.document.animation.src = GifFileName;
}

function move(e)	// When the mouse moves, update the pointer boxes.
{
    if (isMS) {
	e = window.event;
        // X-Y relative to the container (i.e. the image).
        xKm=9999
        yKm=9999
        if (e.srcElement && e.srcElement.name) {
          if (e.srcElement.name == "animation") {
            xKm= (window.event.offsetX-262+2)*KmPerPixel
            yKm=-(window.event.offsetY-262+2)*KmPerPixel
          }
        } 
    }
    if (isNN) {
        xKm=9999
        yKm=9999
        if (e.target.name) {
          if (e.target.name == "animation") {
            xKm= (e.pageX-document.animationlayer.pageX-262)*KmPerPixel
            yKm=-(e.pageY-document.animationlayer.pageY-262)*KmPerPixel
          }
        } 
    }

    if (Math.abs(xKm)>maxKm || Math.abs(yKm)>maxKm) {
      document.myForm.x.value="" 
      document.myForm.y.value=""
      document.myForm.z.value=""
      document.myForm.a.value=""        
    }
    else {
      xx=xKm-xKmOrigin
      yy=yKm-yKmOrigin
      zz=Math.round(Math.sqrt(xx*xx+yy*yy)-.01)
      aa=450-Math.round(Math.atan2(yy,xx)*57.29)
      if (aa>359) { aa=aa-360 }
      if (zz<1)   { aa="0"    }
      xx=Math.round(xx) 
      yy=Math.round(yy)
      if (xx>=0) document.myForm.x.value = xx + ' Km East'
      else       document.myForm.x.value =-xx + ' Km West'
      if (yy>=0) document.myForm.y.value = yy + ' Km North'
      else       document.myForm.y.value =-yy + ' Km South'
      document.myForm.z.value = zz + ' Km Away'
      document.myForm.a.value = aa + ' Degrees'        
    }
}

function down()		// A left-click (mouse-down) to move the Origin. 
{
    // xKm & yKm are the distances from the centre of the radar image.
    // They were already computed in (mouse) move() above.
    // (or are zero at startup.)
    
    // Maybe set the new origin.
    if (Math.abs(xKm)<maxKm && Math.abs(yKm)<maxKm) {
        xKmOrigin=xKm
        yKmOrigin=yKm
    }
    if (xKmOrigin>=0) document.offsets.xo.value =  Math.round(xKmOrigin) + ' Km East' 
    else              document.offsets.xo.value = -Math.round(xKmOrigin) + ' Km West' 
    if (yKmOrigin>=0) document.offsets.yo.value =  Math.round(yKmOrigin) + ' Km North' 
    else              document.offsets.yo.value = -Math.round(yKmOrigin) + ' Km South' 
}

function resetOrigin () 
{
   xKm = 0;
   yKm = 0;
   down ();
}
 
// Empty function - used to deal with image buttons rather than HTML buttons
function xynullfunc()
{
}

//-->
