function imagesOnDisplay(id) {
	this.id = id;
	this.imageIdOnDisplay = [];
	this.maxDisplayNo = 2;
	this.lastDisplayNo = this.maxDisplayNo;
	this.thumbnailsElement = null;
	this.thumbnailLowOpacity = 50;
	this.clrImageDuration = 3000;
	this.clrImageFadeOutDuration = 300;
	this.clrImageCountDown = new Array(this.maxDisplayNo);
	this.autoShowIdleDuration = 20000;
	this.autoShowCountDown = -1;
	this.autoShowFirstImageNo = 0;
	this.autoShowNextImageNo = 0;
}

imagesOnDisplay.prototype.onLoad = function() {
	IM.addSmartImage('StockAlamyLink', 'StockAlamyLink_S360.gif', '', true);
	IM.addSmartImage('StockAlamyHLink', 'StockAlamyHLink_S360.gif', '', true);
        this.addSmartImageOnDisplay('D007559_4M_S60M.gif', 'D007559_4M_S360.jpg', 'Buildings and Structures - Wind turbine - Denmark'); 
	this.addSmartImageOnDisplay('D010031_3M_S60M.gif', 'D010031_3M_S360.jpg', 'Travel locations - New York City - Manhattan Bridge', '656166', 'New York City'); 
	this.addSmartImageOnDisplay('D012151_3_S60M.gif', 'D012151_3_S360.jpg',   'Action & Events - Cannon fire'); 
	this.addSmartImageOnDisplay('4742_2M_S60M.gif', '4742_2M_S360.jpg',       'Insects - Wasp - Close-up');
	this.addSmartImageOnDisplay('D009232_4M_S60M.gif', 'D009232_4M_S360.jpg', 'Travel locations - Washington DC - Iwo Jima Memorial', '656170', 'Washington DC'); 
	this.addSmartImageOnDisplay('D002488_S60M.gif', 'D002488_S360.jpg',       'Still life - Croquis concept - Ready to go', '670661', 'Still life'); 
	this.addSmartImageOnDisplay('C003129_S60M.gif', 'C003129_S360.jpg',       'Travel locations - India - Tea plantation', '836755', 'India'); 
	this.addSmartImageOnDisplay('5592_2M_S60M.gif', '5592_2M_S360.jpg',       'Buildings and Structures - Classic Wind mill'); 
	this.addSmartImageOnDisplay('D005255_3M_S60M.gif', 'D005255_3M_S360.jpg', 'Still life - Conceptual - Investment in buildings', '670661', 'Still life');
	this.addSmartImageOnDisplay('D000790_S60M.gif', 'D000790_S360.jpg',       'People - Vacation & Hobbies - Coarse fishing'); 
	this.addSmartImageOnDisplay('D007694_3M_S60M.gif', 'D007694_3M_S360.jpg', 'IT & Technology - Conceptual - Growth & Succes', '670661', 'Still life'); 
	this.addSmartImageOnDisplay('D010989_S60M.gif', 'D010989_S360.jpg',       'Travel locations - New York City - Statue of Liberty', '656166', 'New York City'); 
	this.addSmartImageOnDisplay('4644_S60M.gif', '4644_S360.jpg',             'Action & Events - Danish paratrooper'); 
	this.addSmartImageOnDisplay('D011314_2M_S60M.gif', 'D011314_2M_S360.jpg', 'Still life - Conceptual - Eye masks', '670661', 'Still life'); 
	this.addSmartImageOnDisplay('5149_2M_S60M.gif', '5149_2M_S360.jpg',       'Buildings and Structures - Lighthouse - Denmark'); 
	this.addSmartImageOnDisplay('D014789_2_S60M.gif', 'D014789_2_S360.jpg',   'Travel locations - India - Rice', '836755', 'India'); 
	this.addSmartImageOnDisplay('5819_2M_S60M.gif', '5819_2M_S360.jpg',       'Nature - Feather on sand - Black and White'); 
	this.addSmartImageOnDisplay('D001015_2M_S60M.gif', 'D001015_2M_S360.jpg', 'Nature and Humans - Children of the Stars'); 
	this.addSmartImageOnDisplay('5917_2M_S60M.gif', '5917_2M_S360.jpg',       'Traffic - Conceptual - Snail og railroad track'); 
	this.addSmartImageOnDisplay('5315_3_S60M.gif', '5315_3_S360.jpg',         'People - Young girl with waterbucket - Ghana'); 
	this.addSmartImageOnDisplay('D011275_S60M.gif', 'D011275_S360.jpg',       'Still life - Conceptual - Party Blowout', '670661', 'Still life'); 
	this.addSmartImageOnDisplay('D012944_S60M.gif', 'D012944_S360.jpg',       'Travel locations - India - Bicycles', '836755', 'India'); 
}

imagesOnDisplay.prototype.addSmartImageOnDisplay = function(tnfilename, filename, description, lightboxno, lightboxname) {
	var imageNo = this.imageIdOnDisplay.length;
	var imageId = 'imageOnDisplay' + imageNo;
	this.imageIdOnDisplay[imageNo] = imageId;
	if (lightboxno != null) { description += '<br>Alamy Lightbox: <a href="http://www.alamy.com/lbx.asp?' + lightboxno + '" alt="" target="_blank">' + lightboxname + '</a>' }
	IM.addSmartImage(imageId, tnfilename, '', true);	
	IM.addSmartImage(imageId + 'D', filename, description, isOP());	
	this.addThumbnail(imageId, tnfilename);
}

imagesOnDisplay.prototype.addThumbnail = function(id, filename) {
	if (this.thumbnailsElement == null) this.thumbnailsElement = document.getElementById('thumbnails');
        this.thumbnailsElement.innerHTML += '<img class=\"thumbnail\" id=\"' + id + '\" src=\"' + IM.getImagePath() + filename + '\" onmouseover=\"javascript:IOD.onMouseOverThumbnail(this)\" onmouseout=\"javascript:IOD.onMouseOutThumbnail(this)\" alt=\"\" /> ';
	var thumbnail = document.getElementById(id);
	setElementOpacity(thumbnail, this.thumbnailLowOpacity);
}

imagesOnDisplay.prototype.setImageOnDisplayNo = function(displayNo, imageId) {
	if (IM.isInitiated()) {
	  this.clrImageCountDown[displayNo] = 0;
	  var smartImage = IM.getSmartImageById(imageId);
	  var displayImage = this.getImageOnDisplayNo(displayNo);
	  var displayText = this.getTextOnDisplayNo(displayNo);
	  displayImage.src = smartImage.src();
	  displayText.innerHTML = smartImage.alt();
	  setElementOpacity(displayImage, 100);
	  setElementOpacity(displayText, 100);
	}
}    

imagesOnDisplay.prototype.getImageOnDisplayNo = function(displayNo) { return document.getElementById('displayimage' + displayNo); }

imagesOnDisplay.prototype.getTextOnDisplayNo = function(displayNo) { return document.getElementById('displaytext' + displayNo); }

imagesOnDisplay.prototype.setImageOnNextDisplay = function(imageId) {
	if (IM.isInitiated()) {
	  this.lastDisplayNo = (this.lastDisplayNo == this.maxDisplayNo) ? 1 : this.lastDisplayNo + 1;
	  this.setImageOnDisplayNo(this.lastDisplayNo, imageId);
	}
}    

imagesOnDisplay.prototype.onMouseOverThumbnail = function(thumbnail) {
	if (IM.isInitiated()) {
	  this.clrAutoShow(false);
	  var displayImageId = thumbnail.id + 'D';
	  thumbnail.src = IM.getSmartImageById(displayImageId).src();
	  setElementOpacity(thumbnail, 100);
	  this.setImageOnNextDisplay(displayImageId);
	}
}    

imagesOnDisplay.prototype.onMouseOutThumbnail = function(thumbnail) {
	if (IM.isInitiated()) {
	  this.clrAutoShow(true);
	  thumbnail.src = IM.getSmartImageById(thumbnail.id).src();
	  setElementOpacity(thumbnail, this.thumbnailLowOpacity);
	  this.clrImageCountDown[this.lastDisplayNo] = this.clrImageDuration;
	}
}

imagesOnDisplay.prototype.clrAutoShow = function(enabled) {
	this.autoShowCountDown = (enabled) ? this.autoShowIdleDuration : - 1;
	this.autoShowFirstImageNo = (enabled) ? this.autoShowNextImageNo : this.autoShowFirstImageNo;
}

imagesOnDisplay.prototype.initTimer = function() {
	for (var i in this.clrImageCountDown) { this.clrImageCountDown[i] = 0; }
	this.clrAutoShow(true);
}

imagesOnDisplay.prototype.timerEvent = function(timeInterval, visible) {
	if (visible) {
	  for (var i in this.clrImageCountDown) {
	    if (this.clrImageCountDown[i] > 0) {
              this.clrImageCountDown[i] -= timeInterval;
	      if (this.clrImageCountDown[i] > 0) {
	        if (this.clrImageCountDown[i] <= this.clrImageFadeOutDuration) {
	          var Opacity = Math.round((this.clrImageCountDown[i] / this.clrImageFadeOutDuration) * 100);
	          setElementOpacity(this.getImageOnDisplayNo(i), Opacity);
	          setElementOpacity(this.getTextOnDisplayNo(i), Opacity);
	        }
	      } else {
	        this.setImageOnDisplayNo(i, 'StockAlamyLink');      
	      }
	    }
	  }

	  if (this.autoShowCountDown > 0) {
	    this.autoShowCountDown -= timeInterval;
	    if (this.autoShowCountDown <= 0) {
	      this.setImageOnNextDisplay(this.imageIdOnDisplay[this.autoShowNextImageNo] + 'D');
              this.autoShowNextImageNo = (this.autoShowNextImageNo == (this.imageIdOnDisplay.length - 1)) ? 0 : this.autoShowNextImageNo + 1;
	      this.autoShowCountDown = (this.autoShowNextImageNo == this.autoShowFirstImageNo) ? this.autoShowIdleDuration : (this.clrImageDuration / 2);
	      this.clrImageCountDown[this.lastDisplayNo] = this.clrImageDuration;
	    }
	  }
	}

}
