// Function: loadImages
// Purpose:  Reads in images (named 1.jpg through i.jpg) into an array.

function loadImages()
{
  images    = new Array();
  numImages = 11;
  for (frame = 1; frame < numImages+1; frame++)
  {
    images[frame]     = new Image();
    images[frame].src = "slides/" + frame + ".jpg";
  }
}

// Function: loadText
// Purpose:  Stores textual descriptions for images into an array.

function loadText()
{    
  text      = new Array();
  text[1] = "Mike launching over a tabletop at Stratton.";
  text[2] = "Mike in the beginning of a jump.";
  text[3] = "Mike in the middle of a jump.";
  text[4] = 'Me launching over a tabletop at Stratton.';
  text[5] = 'Me in the middle of a jump.';
  text[6] = 'Me coming out of the woods.';
  text[7] = "Me preparing to jump off the deck of our Vermont ski house.";
  text[8] = "Me landing and getting stuck in the snow at our house.";
  text[9] = "Sadie and her boyfriend-for-a-weekend Simon, she enjoys our trips to Vermont too.";
  text[10] = "Sadie trying to run through snow taller than her.";
  text[11] = 'We all just wanted to sleep after all that playing in the snow.';
}

// Function: displayImage
// Purpose:  First sets the textual description and the image counter,
//           then sets the source of the <IMG> tag with the name of
//           slideshow.

function displayImage()
{
  document.forms[0].ta.value = text[i];         // text description
  document.forms[0].imageCount.value = i;        // image number
  document.slideshow.src = images[i].src        // display image 
}

// Function: next
// Purpose:  Handles a request to view the next image.  If the next image
//           doesn't exist, it wraps around to the beginning of the array.

function next()
{
  i++;                                          // increment
  if (i == numImages+1)
    i = 1;                                      // restart at first image
  displayImage();                               // display the image
}

// Function: previous
// Purpose:  Same as next() but it wraps backward.

function previous()
{
  i--;                                          // decrement
  if (i == 0)
    i = images.length-1;                        // restart at last image
  displayImage();                               // display the image
}

// Function: jump
// Purpose:  Based on number entered by user, jump to that image.

function jump()
{
  i = document.forms[0].imageCount.value;        // set image index
  if (i > numImages)                            // if out of range
    window.alert("There are only " + numImages + " images available.");
  else
    displayImage();                             // display the image
}
