/* this script written by Scott Fisher for simple sequential rotation.
If we need transitions then Flash or Scriptaculous are probably required and things
probably get a lot more complicated */

/* examples of how to set up a parallel text/image rotator 

  // first define the list of html IDs to rotate and that already exist in the page
  // any sub-arrays will rotate at the same moment as their siblings in the sub-arrays.
  // the script will not set the initial visibility correctly for you.  In you
  // html, set the initial item so it has style="display:block" and all the
  // alternates with style="display:none".  The script will cycle the visibility
  // for you using a timer.
  var rotData = [ ['rot_img_1', 'rot_text_1'],
                  ['rot_img_2', 'rot_text_2'],
                  ['rot_img_3', 'rot_text_3'],
                  ['rot_img_4', 'rot_text_4'] ];
  rotData.current = 0; // set item you're starting with, zero by default
  rotData.timeout = 8000; // set the timer interval in milliseconds

  rotateImages(rotData); // send the data to the image rotator to do it's job

  // for simple rotation of only one thing at a time, this example is simpler
  var rotData = ['rot_img_1', 'rot_img_2', 'rot_img_3', 'rot_img_4'];
  rotData.current = 0; // item you're starting with
  rotData.timeout = 8000; // change time in milliseconds
  rotateImages(rotData);
*/

/* rotate in sequence, parallel items, see examples above */
function rotateImages(rotator){
	/* this crazy anonymous function is required because IE doesn't support passing a function properly and only passes a string otherwise,
	Seems to fix problem with more than 1 instance being put on the same page and not using global variable for only 1 instance */
  setInterval(function(){changeImage(rotator)}, rotator.timeout);
}

function changeImage(rotator){
  var last_item = rotator[rotator.current % rotator.length];
  rotator.current++;
	var curr_item = rotator[rotator.current % rotator.length];
  if(last_item instanceof Array){
    for(i=0;i<last_item.length;i++){
      document.getElementById(last_item[i]).style.display = 'none';
    }
  }else{
    document.getElementById(last_item).style.display = 'none';
  }
  if(curr_item instanceof Array){
    for(i=0;i<curr_item.length;i++){
      document.getElementById(curr_item[i]).style.display = 'block';
    }
  }else{
    document.getElementById(curr_item).style.display = 'block';
  }
  
}
