//*** Getest in: 
//** Internet Explorer: 6.0 SP1
//** Mozilla: 0.9, 1.6
//** Opera: 6.05, 7.23
//** Konqueror: 3.3



//*** Gebruik voorbeeldcode: ***
/*
var objImageRotate = new ImageRotate();

objImageRotate.objRotationImage = getById("imgRotatingBanner");
objImageRotate.arrRotationImageSrc = new Array("01.jpg", "02.jpg", "03.jpg", "04.jpg", "05.jpg");
objImageRotate.arrRotationImageAlt = new Array("01", "02", "03", "04", "05");
objImageRotate.intRotationTimeout = 2000;

objImageRotate.startRotation(2000);
*/



function ImageRotate() {
  // *** Public Properties ***
  this.objRotationImage; //Image object waarvan de source image zal roteren
  this.arrRotationImageSrc; //Array met images die gebruikt worden in rotation, met initiële image als eerste element
  this.arrRotationImageAlt; //Array met images die gebruikt worden in rotation, met initiële image als eerste element
  this.intRotationTimeout = 5000; //Interval tussen rotatie


  // *** Private Properties ***
  var objRotationImage;
  var arrRotationImageSrc;
  var arrRotationImageAlt;
  var intRotationTimeout;
  var objPreloadImage;


  // *** Public Functions ***
  this.startRotation = startRotation;
  this.showNextRotationImage = showNextRotationImage;

  function startRotation(intTime) {
    //Public Properties naar Private Properties kopiëren, om deze te kunnen aanspreken in Private Functions
    objRotationImage = this.objRotationImage;
    arrRotationImageSrc = this.arrRotationImageSrc;
    arrRotationImageAlt = this.arrRotationImageAlt;
    intRotationTimeout = this.intRotationTimeout;

    var intNextImageIndex = nextImageIndex(0);
    var objSelf = this;
    setTimeout(function() { objSelf.showNextRotationImage(intNextImageIndex); }, intTime);

    preloadImage(this.arrRotationImageSrc[intNextImageIndex]);
  }

  function showNextRotationImage(intImageIndex) {
    //source en alt van image wijzigen naar volgende image
    objRotationImage.src = arrRotationImageSrc[intImageIndex];
    objRotationImage.alt = arrRotationImageAlt[intImageIndex];

    var intNextImageIndex = nextImageIndex(intImageIndex);
    var objSelf = this;
    setTimeout(function() { objSelf.showNextRotationImage(intNextImageIndex); }, intRotationTimeout);

    preloadImage(arrRotationImageSrc[intNextImageIndex]);
  }


  // *** Private Functions ***

  function nextImageIndex(intCurrentIndex) {
    if (intCurrentIndex < (arrRotationImageSrc.length - 1)) {
      return ++intCurrentIndex;
    }
    else {
      return 0;
    }
  }

  function preloadImage(strImageSrc) {
    objPreloadImage = new Image();
    objPreloadImage.src = strImageSrc;
  }
}