var bottomScrollSpeed = 80;		// A random speed to make things reasonable.
var bottomScrollPause = 18 * 1000;	// At each stopping point wait for 15 seconds.

var bottomScrollInc = 1;		// Increment for speeding up ro slowing down;
var maxBottomScrollInc = 16;		// Don't scroll faster than this.
var bottomScrollPos = 0;		// The images start at the left edge.
var nBottomImgs = 10;			// Number of tiles to use for scrlling.
var bottomImgWidth = 384;		// Width of each image, as it scrolls.
var bottomImgsWidth = nBottomImgs * bottomImgWidth;	// Width of all images to be loaded
							// when the page is loaded.
var rampUp = true;			// At the beginning, speed up scrolling until max rate is achieved.

function bottomShow() {
  var el;	// Page Element
  var posPx;	// 

  /*
   * Scroll the bottom images.
   */
  bottomScrollPos += bottomScrollInc;
  /*
   * For the next increment, decide if we are speeding up, slowing down, or continuing.`
   */
  if (rampUp) {
    if (bottomScrollInc > -maxBottomScrollInc && bottomScrollInc < maxBottomScrollInc) {
      /*
       * If we aren't maxed out yet, speed up.
       */
      bottomScrollInc *= 2;
      /*
       * If we are maxed out, stop speeding up.
       */
      if (bottomScrollInc == maxBottomScrollInc || bottomScrollInc == -maxBottomScrollInc)
	rampUp = false;
    }
  }
  else if (bottomScrollPos % bottomImgWidth <= 2 * maxBottomScrollInc + 1 ||
  	   bottomImgWidth - (bottomScrollPos % bottomImgWidth) < 2 * maxBottomScrollInc - 1)
    /*
     * Slow down by half.
     */
    bottomScrollInc /= 2;
  /*
   * Don't stop scrolling altogether.
   * At least move 1 pixel.
   */
  if (bottomScrollInc >= 0) {
    if (bottomScrollInc < 1)
      bottomScrollInc = 1;
  }
  else {
    if (bottomScrollInc > -1)
      bottomScrollInc = -1;
  }

  /*
   * Don't scroll off the edge.
   */
  if (bottomScrollPos < 0)
    bottomScrollPos = 0;
  /*
   * Set the new scrolling position.
   */
  posPx = '-' + bottomScrollPos + 'px';
  el = document.getElementById("bottomImg");
  el.style.left = posPx;
  /*
   * If at an end, reverse direction,
   * and start speeding up again.
   */
  if (bottomScrollPos <= 0 ||
    bottomScrollPos > bottomImgsWidth - 2 * bottomImgWidth - 1) {
    bottomScrollInc *= -1;
  }
  if (bottomScrollPos % bottomImgWidth <= 1 ||
      bottomScrollPos % bottomImgWidth >= bottomImgWidth - 2)
    rampUp = true;
  /*
   * Set up for the next move.
   * If at a stopping point, pause,
   * otherwise, start a motion at the minimum speed.
   */
  setTimeout(bottomShow, (((bottomScrollPos % bottomImgWidth) == 0) ||
			  ((bottomScrollPos % bottomImgWidth) == (bottomImgWidth - 1)))
  			 ? bottomScrollPause
			 : bottomScrollSpeed);
}

/*
 * Let's get thigns started.
 */
function bottomShowPreLoad() {
  setTimeout(bottomShow, bottomScrollPause);
}
bottomShowPreLoad();

