var Scroller = function (pOuterDiv, pContents, pIncrement, pGap, pPause0, pPause1, pPause2) {

  if (pContents.length == 0) return;

  this.outerDiv  = pOuterDiv;
  this.contents  = pContents;
  this.increment = pIncrement > 0 ? pIncrement : 1;
  this.gap       = pGap > 0 ? pGap : 20;
  this.pause0    = pPause0 > 0 ? pPause0 : 25;
  this.pause1    = pPause1 > 0 ? pPause1 : 2000;
  this.pause2    = pPause2 > 0 ? pPause2 : 30000;

  this.outerDiv.style.overflow = "hidden";
  this.outerDiv.style.position = "relative";
  this.upperDiv = this.outerDiv.appendChild(document.createElement("div"));
  this.upperDiv.style.left = "0px";
  this.upperDiv.style.position = "absolute";
  this.upperDiv.style.top = "0px";
  this.upperDiv.style.width = pOuterDiv.style.width;
  this.lowerDiv = this.outerDiv.appendChild(document.createElement("div"));
  this.lowerDiv.style.left = "0px";
  this.lowerDiv.style.position = "absolute";
  this.lowerDiv.style.top = this.outerDiv.offsetHeight + "px";
  this.lowerDiv.style.width = pOuterDiv.style.width;

  this.currentIndex = 0;
  this.lowerDiv.innerHTML = this.contents[this.currentIndex];

  this.scroll();

};

Scroller.prototype.scroll = function () {

  var upperTop = parseInt(this.upperDiv.style.top);
  var lowerTop = parseInt(this.lowerDiv.style.top);
  var remHeight = lowerTop + this.lowerDiv.offsetHeight - this.outerDiv.offsetHeight;
  var tempThis = this;

  if (lowerTop > 0 || remHeight > 0) {
    var increment;
    if (lowerTop > this.increment || remHeight > this.increment) increment = this.increment;
    else if (lowerTop > 0) increment = lowerTop;
    else increment = remHeight;
    this.lowerDiv.style.top = lowerTop - increment + "px";
    this.upperDiv.style.top = upperTop - increment + "px";
    setTimeout(function () { tempThis.scroll(); }, this.pause0);
  }
  else {
    var tempDiv = this.lowerDiv;
    this.lowerDiv = this.upperDiv;
    this.upperDiv = tempDiv;
    this.lowerDiv.style.top = this.outerDiv.offsetHeight + this.gap + "px";
    this.currentIndex++;
    var timeout;
    if (this.currentIndex < this.contents.length) {
      timeout = this.pause1;
    }
    else {
      this.currentIndex = 0;
      timeout = this.pause2;
    }
    this.lowerDiv.innerHTML = this.contents[this.currentIndex];
    setTimeout(function () { tempThis.scroll(); }, timeout);
  }

}

