//We wrap all the code in an object so that it doesn't interfere with any other code
var scroller = {
  init:   function() {

    //collect the variables
    scroller.docH = document.getElementById("textContent").offsetHeight;
    scroller.contH = document.getElementById("textContainer").offsetHeight;
    scroller.scrollAreaH = document.getElementById("textScrollArea").offsetHeight;
   
    //calculate width of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)
    scroller.scrollH = 30;
    //scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
    //if(scroller.scrollH < 15) scroller.scrollH = 15;
    document.getElementById("textScroller").style.height = Math.round(scroller.scrollH) + "px";
    //document.getElementById("scroller").style.width = 25+"px";
    //what is the effective scroll distance once the scoller's width has been taken into account
    scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);
    
    //make the scroller div draggable
    Drag.init(document.getElementById("textScroller"),null,0,0,-1,scroller.scrollDist);
    //function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
    
    //Drag.init(document.getElementById("textScroller"),null,0,scroller.scrollDist,0,0);
    
    //add ondrag function
    document.getElementById("textScroller").onDrag = function (x,y) {
      var scrollY = parseInt(document.getElementById("textScroller").style.top);
      var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist);
      document.getElementById("textContent").style.top = docY + "px";
    }
  }
}

window.onload = scroller.init;