

function ImageRotation()
{
  this.INTERVAL       = 10;
  this.FADE_DURATION  = 1;
  this.MAX_IMAGE      = 7;
  this.IMAGE_ID       = "sidebar_images_";
  this.IMAGE_PATH     = "../Images/top/sidebar_photo_";
  this.IMAGE_TYPE     = ".jpg";
  this.IMAGEARRAY     = new Array(2,4,6,8,9,11,14,16);
  
  this.current_viewed = 2;
  this.next_view      = 4;
  
  var b = this.showNext.bind(this);
  setInterval(b, this.INTERVAL*1000);
}



ImageRotation.prototype.showNext = function()
{
  if ($(this.IMAGE_ID + "1") != null && $(this.IMAGE_ID + "2") != null){
	$(this.IMAGE_ID + "2").src = $(this.IMAGE_ID + "1").src;
	//new Effect.Opacity(this.IMAGE_ID + "2", {duration:0, from:0, to:1.0});
	Element.setOpacity(this.IMAGE_ID + "2", 100);

	var nxt = this.getRandom();
	while( nxt==this.current_viewed || nxt==this.current_viewed )
	{
		nxt = this.getRandom();
	}
	  
	$(this.IMAGE_ID + "1").src = this.IMAGE_PATH + this.IMAGEARRAY[nxt] + this.IMAGE_TYPE;
	  
	//Effect.Fade(this.IMAGE_ID + "2", { duration: this.FADE_DURATION })
	new Effect.Opacity(this.IMAGE_ID + "2", {duration:this.FADE_DURATION, from:1.0, to:0});
  }
}

ImageRotation.prototype.getRandom = function()
{
  return Math.round(Math.random()*(this.MAX_IMAGE-1)+1);
}

var ROTAT = new ImageRotation();