/**

   Name: image_rotate.js
   Version: 1.1
   Requires: jquery
   Author: Stuart Swope
*/

/**
   Switches images via fade in/out.
   Example. id = maindiv curId = button1, newId = button2
   Switches the selected id from #curid to #newid
   @param id - the id of the elements
   @param curId - An id of current selected element
   @param newId - An id of newly selected element
   @param speed - Transition speed

*/
function switchImage(id, curId, newId, speed) {
   if (curId != newId) {
      var curNum = parseInt(curId.match(/[0-9]/g));
      var newNum = parseInt(newId.match(/[0-9]/g));
      $("#" + id + curNum).fadeOut(speed); 
      $("#" + id + newNum).fadeIn(speed);
   }
}



/**
   This should be rewritten.
   Switches the selected class to a new id
   Example. id = thumb curSel=1, newSel = 2
   Switches the selected class from #thumb1 to #thumb2
   @param id - the id of the elements
   @param curSel - An integer of current selected element
   @param newSel - An integer of newly selected element

*/
function switchSelected(id, curSel, newSel) {
   if(curSel != newSel)
      $("#" + id + curSel).removeClass("selected");
   $("#" + id + newSel).addClass("selected");
}


/**
   Rotates exhibits on home page via fade in/out.  Updates
   @param numEx - The number of exhibits.
   @param currentEx - The current exhibit being displayed.
   @param transition - prev or next
   @param id - The id for switching classes in switchSelected
   @return
*/
function rotateImage(numIm, currentIm, transition, id) {
   var nextIm;
   
   if (transition == "next") {
      if (numIm == currentIm)
         nextIm = 1;
      else
         nextIm = currentIm + 1;
   }
   else if (transition == "prev") {
      if (currentIm == 1)
         nextIm = numIm;
      else
         nextIm = currentIm - 1;
   }
   
   $("#himage" + currentIm).fadeOut(1000); 
   $("#himage" + nextIm).fadeIn(1000);
   switchSelected(id, currentIm, nextIm);
   
   return nextIm;
}