var oRotateImages = new RotatingImagesConstructor("oRotateImages", 29, "rotImg_", "2000");
oRotateImages.rotateStart();

function RotatingImagesConstructor(objectName, maxID, imagesPrefix, rotateTimeout) { // defaults -> !MANDATORY!, "1", "rotImg_", "2000"
   this.name      = objectName;
   this.images    = new Array();
   this.iMax      = (maxID) ? maxID : 1; // max id
   this.to        = (rotateTimeout) ? rotateTimeout : 2000;
   this.imgPref   = (imagesPrefix) ? imagesPrefix : "rotImg_"; // html var declaration
   this.imagesPos = 1 + Math.round( ( this.iMax - 1 ) * Math.random() ); // that should pick a random number between one and max id

   var html       = ""; // html var declaration
   var aSrc       = new Array(
      '<img src="img/rp.php?rot=',
      this.imagesPos,
      '" style="display: ',
      'none',
      '" name="' + this.imgPref,
      this.imagesPos,
      '">'
   );

   html    += aSrc.join("");
   aSrc[3]  = "none";

   this.images[this.imagesPos]   = this.imgPref + this.imagesPos;

   for ( var j = this.imagesPos ; ( j = j % this.iMax + 1 ) != this.imagesPos ; ) {
      aSrc[1]  = j;
      aSrc[5]  = j;
      html    += "\n" + aSrc.join("");
      this.images[j] = this.imgPref + j;
   }

   document.write(html);

   this.rotateStart  = fRotatePic_2_ver;
}

function fRotatePic_2_ver() {
   j = this.imagesPos % this.iMax;
   j++;
   if ( document.images[this.images[j]].complete ) {
      document.images[this.images[this.imagesPos]].style.display  = "none";
      document.images[this.images[j]].style.display  = "inline";
      this.imagesPos = j;
   }
   setTimeout(this.name + ".rotateStart()", this.to);
}

/*
function fRotatePic() {
   document.images["rotating_pics"].src   = ( match = document.images["rotating_pics"].src.match(/[0-9]+$/) )
      ? 'img/rp.php?rot=' + ( 1 + match[0] % 29 )
      : 'img/rp.php?rot=' + ( 1 + Math.round(29*Math.random()) );
   window.global_rotPic = setTimeout("fRotatePic()", 2000);
}
fRotatePic();
*/