var w3c = false;
var scrollingFrame;

if (document.getElementById) {
  w3c = true;
}

function ScrollingFrame(inner, outer) {
  this.pause = false;
  this.inner = inner;
  this.outer = outer;
  this.innerHTMLOrig = this.inner.innerHTML;
  this.nHeightOuter = this.outer.offsetHeight;
  this.nHeightInner = this.inner.offsetHeight;
  //repeat inner enough so that it fills outer
  while (this.inner.offsetHeight < this.nHeightOuter) {
    this.inner.innerHTML = this.inner.innerHTML + "<p>&nbsp;<p>" + this.innerHTMLOrig;
  }
  this.nHeightFilled = this.inner.offsetHeight;
  //double the new inner so that outer will remain filled when scroll is near reset
  this.inner.innerHTML = this.inner.innerHTML + this.inner.innerHTML;
  this.nHeightDouble = this.inner.offsetHeight;
  this.inner.style.position = "relative";
  this.outer.style.position = "relative";
  this.outer.overflow = "hidden";
  this.inner.style.top = this.nHeightOuter/2 + "px";
  this.frameSize = 1;
  this.interval = 125;
}

ScrollingFrame.prototype.nextFrame = function(obj) {
  var top = parseInt(this.inner.style.top);
  if (-top > this.nHeightDouble - this.nHeightFilled) {
	top = 0;
  }
  this.inner.style.top = (top - this.frameSize) + "px";
  setTimeout(obj + ".nextFrame('" + obj + "')", this.interval);
}

function moveIt(strFrame, strInner, strOuter) {
  if (!w3c) return;
  var frameScroll = document.getElementById(strFrame);
  var outer = document.getElementById(strOuter);
  var inner = document.getElementById(strInner);
  var outer = document.getElementById(strOuter);
  frameScroll.style.display = "block";
  scrollingFrame = new ScrollingFrame(inner, outer);
  scrollingFrame.nextFrame("scrollingFrame");
}

function selectSpeed(select) {
  scrollingFrame.interval = select.options[select.selectedIndex].value;
}

function changeSpeed(speed) {
  scrollingFrame.interval = speed;
}

function pause(anchor) {
  scrollingFrame.pause = !scrollingFrame.pause;
  if (scrollingFrame.pause) {
	anchor.innerHTML = "Scroll";
	scrollingFrame.frameSize = 0;
  } else {
	anchor.innerHTML = "Pause";
	scrollingFrame.frameSize = 1;
  }
}