// Creates a new class for storing and manipulating pictures in a slideshow div.  Takes four parameters: 
// slideId [string]: ID of the picture to function as our slideshow's window.
// slideArray [array]: Array of pictures to displayed.
// autoScroll [boolean]: Boolean that determines whether the slideshow will automatically progress through the pictures.
// userControls [boolean]: Boolean that determines if the slideshow will react to user input.
var SlideShow = function(slideId, slideArray, autoScroll, userControls) {

  var slideId = slideId;

  var slideArray = slideArray;

  var autoScroll = autoScroll;

  var userControls = userControls;

  var randomArray = new Array(slideArray.length);

  var currSlide = null;

  // Randomize slideArray and save the result in randomArray
  for (var i=0; slideArray[i]; i++) {

    do {

      currSlide = Math.floor(Math.random() * slideArray.length);

    } while(randomArray[currSlide]);

    randomArray[currSlide] = slideArray[i];

  }

  currSlide = Math.floor(Math.random() * slideArray.length);

  document.getElementById(slideId).src = getCurrSlide();

  setTimeout(rotate, 5*1000);
  
  function getCurrSlide() {
  
    return "images/scriptPics/" + slideId + "/" + randomArray[currSlide];
    
  }

  this.nextSlide = function() {

    autoScroll = false;

    if (currSlide == (slideArray.length - 1)) {

      currSlide = 0;

    } else {

      currSlide++;

    }

    document.getElementById(slideId).src = getCurrSlide();

    return false;

  }

  this.prevSlide = function() {

    autoScroll = false;

    if (currSlide == 0) {

      currSlide = (slideArray.length - 1);

    } else {

      currSlide--;

    }

    document.getElementById(slideId).src = getCurrSlide();

    return false;

  }

  function rotate() {

    if (!autoScroll) {

      return false;

    }

    if (currSlide == (slideArray.length - 1)) {

      currSlide = 0;

    } else {

      currSlide++;

    }

    document.getElementById(slideId).src = getCurrSlide();

    setTimeout(rotate, 5*1000);

  }

}

//////////////////////////////////////////////////////////////
// Multi-Frame Slideshow Script Version 2 copyright 2008 Evan Kroske, all rights reserved.
// Thanks to Tom Negrino and Dori Smith for writing the superb Javascript guide, 
// JavaScript & Ajax Visual Quickstart Guide. Also thanks to Shelley Powers for her more 
// in-depth book, Learning Javascript.
// If you use this script without my permission, I will hunt you down,
// hack your site, and eat your lunch. If you ask nicely, your lunch will be relatively 
// safe. You can email me at E.Kroske@EvansPhotoGraphic.com
//////////////////////////////////////////////////////////////
