/* Previous Next Utility
 * Author:  Tricia Woodruff
 * Date: January 8, 2004
 */

/**
  * prevNext
  * Allows you to scroll through an array of items.
  * Requires that the following parameters be present
  * @param currentItem the name of hte current item in the array
  *        usually a filename
  * @param commonURL the common url to append to the file name for 
  *        each item in the array
  * @param numberOfItems the number of items in the array
  * @param itemsArray the array to use
  * @param direction either 'forward' or 'back'
  */
 
function prevNext (currentItem, commonURL, numberOfItems, itemsArray, direction) {
   
   var pos, x, y, urlForward, urlBack;

   
   for (i=0; i<numberOfItems; i++){
      if (itemsArray[i] == currentItem) {
         pos = i
   	}
   }
   
   x = itemsArray[pos+1]
   y = itemsArray[pos-1]
         
   if (currentItem == itemsArray[numberOfItems-1]){
      x=itemsArray[0]
   }
      
   if (currentItem == itemsArray[0]){
      y=itemsArray[numberOfItems-1];
   }
   
   urlForward = commonURL + x;
   urlBack = commonURL + y; 
   
   if (direction == 'forward') {
      return urlForward;
   }
   else if (direction == 'back') {
      return urlBack;
   }
}


