var JSScroller = function( outerDiv,  //the outer div for the positioning constraints
                           innerDiv ) //inner div is scrolled around masked under the outer
{
   this.outerDiv = $( outerDiv );
   this.innerDiv = $( innerDiv );
   this.scrollWidth = this.outerDiv.scrollWidth;
   this.scrollHeight = this.outerDiv.scrollHeight;
   this.outerObjStyle = (document.defaultView) ? document.defaultView.getComputedStyle( this.outerDiv, "") : this.outerDiv.currentStyle;
   this.innerObjStyle = (document.defaultView) ? document.defaultView.getComputedStyle( this.innerDiv, "") : this.innerDiv.currentStyle;
   this.minLeftMargin = ( parseInt( this.scrollWidth ) - JSEffectsHelper.getElementWidth( this.outerDiv ) ) * -1; // min means negative margin to moving things to the left
   this.minTopMargin = ( parseInt( (document.all) ? this.scrollHeight : this.innerObjStyle.height ) - JSEffectsHelper.getElementHeight( this.outerDiv ) ) * -1;
   this.autoScrollInterval;
   this.isAutoScroll = false;
}
//JSScroller.prototype = new AbstractDispatcher();  // REQUIRES AbstractDispatcher to dispach events for listeners
JSScroller.prototype =
{
   scrollContentRight : function( step )
   {
      var innerML = parseInt( this.innerDiv.style.marginLeft == '' ? 0: this.innerDiv.style.marginLeft );
      if( innerML > this.minLeftMargin )
      {
         this.innerDiv.style.marginLeft = innerML - Math.min( step, Math.abs( this.minLeftMargin - innerML ) ) + "px";
      }
      else if( this.isAutoScroll )
      {
         this.killAutoScroll();
      }
   },

   scrollContentLeft : function( step )
   {
      var innerML = parseInt( this.innerDiv.style.marginLeft == '' ? 0: this.innerDiv.style.marginLeft );
      if( innerML < 0 )
      {
         this.innerDiv.style.marginLeft = innerML + Math.min( step, Math.abs( 0 - innerML ) ) + "px";
      }
      else if( this.isAutoScroll )
      {
         this.killAutoScroll();
      }
   },

   scrollContentUp : function( step )
   {
      var innerMT = parseInt( this.innerDiv.style.marginTop == '' ? 0: this.innerDiv.style.marginTop );
      if( innerMT < 0 )
      {
         this.innerDiv.style.marginTop = innerMT + Math.min( step, Math.abs( 0 - innerMT ) ) + "px";
      }
      else if( this.isAutoScroll )
      {
         this.killAutoScroll();
      }
   },

   scrollContentDown : function( step )
   {
      var innerMT = parseInt( this.innerDiv.style.marginTop == '' ? 0: this.innerDiv.style.marginTop );
      if( innerMT > this.minTopMargin )
      {
         this.innerDiv.style.marginTop = innerMT - Math.min( step, Math.abs( this.minTopMargin - innerMT ) ) + "px";
      }
      else if( this.isAutoScroll )
      {
         this.killAutoScroll();
      }
   },

   autoScrollRight : function( step, interval )
   {
      this.killAutoScroll();
      this.isAutoScroll = true;
      var thisObj = this;
      this.autoScrollInterval = setInterval( function(){ thisObj.scrollContentRight( step ) }, interval );
   },

   autoScrollLeft : function( step, interval )
   {
      this.killAutoScroll();
      this.isAutoScroll = true;
      var thisObj = this;
      this.autoScrollInterval = setInterval( function(){ thisObj.scrollContentLeft( step ) }, interval );
   },

   autoScrollUp: function( step, interval )
   {
      this.killAutoScroll();
      this.isAutoScroll = true;
      var thisObj = this;
      this.autoScrollInterval = setInterval( function(){ thisObj.scrollContentUp( step ) }, interval );
   },

   autoScrollDown : function( step, interval )
   {
      this.killAutoScroll();
      this.isAutoScroll = true;
      var thisObj = this;
      this.autoScrollInterval = setInterval( function(){ thisObj.scrollContentDown( step ) }, interval );
   },

   killAutoScroll : function()
   {
      this.isAutoScroll = false;
      clearInterval( this.autoScrollInterval );
      //this.dispatchEvent( "onScrollComplete" );
   }
}