var box = document.getElementById("box");

if (box != null)
{
    box.divEx = new divEx(box, document.getElementById("upScroll"), document.getElementById("downScroll"));
}
box = null;


function divEx(div, aUp, aDown)
{
  if (div == null)
  {
      return false;
  }

  var bScrolling = false;
  var stepSize = 10;
  var timerId = null;
  
  var up = {
    onmouseover : (aUp != null)? aUp.onmouseover: null,
        onmouseout : (aUp != null)? aUp.onmouseout: null,
        step : -stepSize
  };

  var down = {
    onmouseover : (aDown != null)? aDown.onmouseover: null,
        onmouseout : (aDown != null)? aDown.onmouseout: null,
        step : stepSize
  }

  if (aUp != null)
  {      
      aUp.onmouseover = (typeof up.onmouseover == "function")?
    function() {up.onmouseover(); return onmouseover(up.step);}:
                                       function() {onmouseover(up.step);};
      aUp.onmouseout = (typeof up.onmouseout == "function")?
                function() {up.onmouseout(); return onmouseout();}:
                                               function(){onmouseout(up.step);};
  }

  if (aDown != null)
  {
      aDown.onmouseover = (typeof down.onmouseover == "function")?
       function() {down.onmouseover(); return onmouseover(down.step);}:
                                                function() {onmouseover(down.step)};
      aDown.onmouseout = (typeof down.onmouseout == "function")?
                function() {down.onmouseout(); return onmouseout();}:
                                               function(){onmouseout();};
  }

  function onmouseout()
  {
     if (bScrolling)
     {
         bScrolling = false;
     }

     if (timerId != null)
     {
         window.clearTimeout(timerId);
         timerId = null;
     }    
  }

  function onmouseover(step)
  {
      
     if (bScrolling)
     {
         return;
     }

     bScrolling = true;
     stepSize = step;
     timerId = window.setTimeout(function() { scroll(); }, 100);
  }

  function scroll()
  {
     if (!bScrolling)
     {
      return;
     }

     var scrollTop = div.scrollTop + stepSize;

     if (scrollTop >= div.scrollHeight)
     {
         div.scrollTop = div.scrollHeight - 1;
     }
     else if (scroll < 0)
     {
         div.scrollTop = 0;
     }
     else
     {
         div.scrollTop = scrollTop;
     }
    
    timerId = window.setTimeout(function() { scroll(); }, 50);
  }

}