<!-- simple.loop.v03.js -->
<!-- Below is Simple Loop code.-->
<!-- v03 2001-10-12 Clive Edington, allow all browsers. -->
<!-- v02 2001-05-21 Clive Edington, adapted from IDR.loop.v02.js -->
<!-- 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:
//
// 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.

// Allow any browser.
isOK = true;

if (nImages>0) { 

// 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  = ?;
//animation_width  = ?;
 
//**************************************************************************
 
//=== 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;
 
}  // (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.   ==
//==============================================================
 
//===> Load and initialize everything once page is downloaded (called from 'onLoad' in <BODY>)

function launch()
{
  if (nImages==0)  return;

  // If there is only 1 image, show it, but dont start the loop.
  if (nImages==1) {
    current_image = 0;
    theImages[current_image] = new Image();
    theImages[current_image].src = image_href + theImageNames[current_image];
    imageNum[current_image] = true;   // pretend it is ready.
    display_current_image();
    return;
  }
    
  
  //
  // step 5: construct filenames for all images 
  //
  for (var i = first_image; i <= last_image; i++)
  {
    current_image = i;
    theImages[current_image] = new Image();
    theImages[current_image].src = image_href + theImageNames[current_image];
    imageNum[current_image] = false;  // image is not ready yet.
  }
  current_image = first_image;
  imageNum[current_image] = true;   // pretend it is ready.
 
  // this needs to be done to set the right mode when the page is manually reloaded
  change_mode (1);
  fwd();
}
 
//==> Display the 'current_image'.

function display_current_image()
{
   //display image onto screen
   document.animation.src = theImages[current_image].src;
   //display image number
   document.control_form.frame_nr.value = current_image+1;
}
 
//===> Stop the animation

function stop()
{
//== cancel animation (timeID holds the expression which calls the fwd or bkwd function) ==
  if (status == 0) {
    clearTimeout (timeID);
  }
  status = 0;
  return;
}

//===> Display animation in fwd direction in either loop or sweep mode

function animate_fwd()
{
   if (nImages<=1) return;
   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] == false) {
    if (theImages[current_image].complete) {
        imageNum[current_image] = true;
        break;
    }
    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;
      }
    }
  }
 
  display_current_image();

  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()
{
  if (nImages<=1) return;
  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] == false) {
    if (theImages[current_image].complete) {
        imageNum[current_image] = true;
        break;
    }
    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_current_image();

  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;
  if (nImages<=1) return;
  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] == false) {
    if (theImages[number].complete) {
        imageNum[number] = true;
        break;
    }
    number++;
   if (number > last_image) number = first_image;
  }
 
  current_image = number;
  display_current_image();
}
 
//===> Decrement to next image

function decrementImage()
{
  var number;
  if (nImages<=1) return;
  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] == false) {
    if (theImages[number].complete) {
        imageNum[number] = true;
        break;
    }
    number--;
   if (number < first_image) number = last_image;
  }
 
  current_image = number;
  display_current_image();
}
 
//===> "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;
}
 
//===> 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()
{
}

//-->

