var rotation = { 
	displaySeconds: 5,
	fadeDuration: 1,
  current: 0,
  last: 0,
  elements: false,
  executer: false,
  startup: function() { 
	  rotation.elements=$$('.mainImage'); //Get a collection of the elements to cycle in and out of view
    rotation.executer=new PeriodicalExecuter(rotation.cycle, rotation.displaySeconds); // Image Change Timer
  }, 

  cycle: function() {
    //Only one photo - do nothing	
	  if(rotation.elements.length<2)
	    return;
	
	  //Find next image
	  next=rotation.current+1;
    if(next>=rotation.elements.length) {
	    next=0;
    }

    rotation.showImage(next);
	},
	showImage: function(num) {
		//if(num==rotation.current)
		//  return;
		
	  //Remember the index of the last element
    rotation.last=rotation.current;
    rotation.current=num;
    //Fade the last object out and fade the new current one in
    currentObj=rotation.elements[rotation.current];
    lastObj=rotation.elements[rotation.last];
    new Effect.Fade(lastObj, { duration: rotation.fadeDuration, fps: 50,
	    afterFinish: function() {
		    new Effect.Appear(currentObj, { duration: rotation.fadeDuration, fps: 50, queue:'end' }) 
	    }
		})
	}
} 

function selectImage(num) {
  rotation.executer.stop();
  rotation.fadeDuration=0.25;
  rotation.showImage(num);
  /* rotation.elements[num].scrollTo(); */
}

Event.observe(window, 'load',
   function() { 
     rotation.startup();
   }
 );