/**

   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

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



/**
   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 numImg - The number of images.
   @param curImg - The current image being displayed.
   @param transition - prev or next
   @return
*/
function rotateImage(numImg, curImg, transition, time, id) {
   var nextImg;
   
   if (transition == "next") {
      if (numImg == curImg)
         nextImg = 1;
      else
         nextImg = curImg + 1;
   }
   else if (transition == "prev") {
      if (curImg == 1)
         nextImg = numImg;
      else
         nextImg = curImg - 1;
   }
   
   $("#" + id + curImg).fadeOut(time); 
   $("#" + id + nextImg).fadeIn(time);
   
   return nextImg;
}