
window.addEvent('domready', function() {
  
  if ($('imageRotator'))
  {
    //SET THE PAUSE BETWEEN IMAGES HERE
    pauseTime = 5000
  
    //get a list of images to rotate
    var images = $('imageRotator').getElements('div');
  
      // hide all the images
      images.setStyles({
    		display:'block',
    		opacity: 0
    	});

      //show the first one 
    	images[0].setStyles({opacity: 1});

      //start rotating after the pause time
    	setTimeout("crossFade(0,"+pauseTime+")", pauseTime); 
  }
});


function crossFade(current_index, pauseTime)
{
  images = $('imageRotator').getElements('div');

  if(current_index+1 == images.length) 
   {
     next_index = 0
   }
   else 
   {
     next_index = current_index + 1
   }

   //hide image
   images[current_index].effect('opacity', {duration: 4000, transition: Fx.Transitions.Quart.easeIn }).start(0);
    
   //show next
   images[next_index].effect('opacity', {duration: 4000, transition: Fx.Transitions.Quart.easeInOut}).start(1)

   //start again
   setTimeout("crossFade("+next_index+","+pauseTime+")", pauseTime);  
}