function ScrollBox(id,leftClassName,rightClassName) {
  this.id = id;
  this.leftClassName = leftClassName;
  this.rightClassName = rightClassName;
  this.speedConstant = 1;
};
ScrollBox.prototype = new ObjectEvents();
ScrollBox.prototype.init = function() {
  this.build();
  this.play();
  this.addEvent(get_by_id(this.id),'mouseover','mouseOver');
  this.addEvent(get_by_id(this.id),'mouseout','mouseOut');
  this.addEvent(document,'click','click');
};

ScrollBox.prototype.build = function() {
  var box = get_by_id(this.id);
  box.className = 'scroll-box';
  this.scrollWidth = box.scrollWidth;
  var content = make_el('DIV',{style:{width:this.scrollWidth+'px'}});
  while(box.hasChildNodes())
    content.appendChild(box.firstChild);
  box.appendChild(content);
  var copy = content.cloneNode(true);
  copy.className = 'scroll-box-content';
  copy.style.display = 'none';
  copy.style.left = this.scrollWidth+'px';
  copy.style.top = 0;
  box.appendChild(copy);
  var me = this;
  copy.style.display = '';
};

ScrollBox.prototype.play = function() {
  this.stop();
  var me = this;
  this.interID = setInterval(function(){
      var el = get_by_id(me.id);
      if(el.scrollLeft>=me.scrollWidth
	 && me.speedConstant > 0)
	el.scrollLeft=0;
      else if(el.scrollLeft<=0
	 && me.speedConstant < 0)
	el.scrollLeft=me.scrollWidth;
      else el.scrollLeft += me.speedConstant;
    }, 1);
};
ScrollBox.prototype.stop = function() {
  clearInterval(this.interID);
};
ScrollBox.prototype.linkTest = function(el) {
  return el.tagName == 'A';
};

ScrollBox.prototype.mouseOver = function(e) {
  if(getAncestor(get_srcEl(e),this.linkTest,2))
    this.stop();
};

ScrollBox.prototype.mouseOut = function(e) {
  if(getAncestor(get_srcEl(e),this.linkTest,2))
    this.play();
};

ScrollBox.prototype.click = function(e) {
  var el = get_srcEl(e);
  if(className.test(el, this.leftClassName)
     || className.test(el.parentNode, this.leftClassName))
    this.speedConstant = 1;
  else if(className.test(el, this.rightClassName)
     || className.test(el.parentNode, this.rightClassName))
    this.speedConstant = -1;
};
