//
//  Scroller utility for 4+ browsers
//
//  Emmanuel Zabey - NewAccess
//  2001
//


//  Requires : NWABrowserHandling.js
//    <script language="javascript" src="path/NWABrowserHandling.js"></script>
//
//  Use absolute positionning only !
//
//    <div id="ScrollExampleBase" style="position:relative;clip:rect(0,200,200,0);"> 
//      <div id="ScrollExample" style="position:absolute;">
//        the stuff to scroll
//      </div>
//    </div>
//
//    rect coordinates are  (top, right, bottom, left)
//
//  Then add the ScrollInit command in the <body> tag
//
//    <body onLoad="ScrollInit('ScrollExample');">
//
//  Then add the following event handler on the scroll button/link/image/...
//
//    onMouseOver="Scroll('ScrollExample', sUp);"  (or sDown, or sLeft, or sRight)
//
//  To override default values :
//
//    <script language="javascript" src="NWAScrollIE.js"></script>
//    <script> 
//      ScrollStep=10;
//      ScrollDelay=2;
//      ,,,
//    </script>
//


//
//  Constants
//
var sUp=1, sDown=2, sLeft=3, sRight=4;

//
//  Variables
//
var ScrollTimer;

//
//  Step for scrolling in pixels
//
var ScrollStep = 1;

//
//  Delay between two scroll steps
//
var ScrollDelay = 1;

//
//  Describes how the layer can move partially out of the display window
//
var ScrollBottomVisible = 210;
var ScrollRightVisible = 50;
var ScrollTopBlank = 0;
var ScrollLeftBlank = 0;


//
//  Messages when scrolling
//
var ScrollUpMsg = "Scrolling up...";
var ScrollDownMsg = "Scrolling down...";
var ScrollLeftMsg = "Scrolling left...";
var ScrollRightMsg = "Scrolling Right...";

//
//  Delay before clearing the status bar when the scrolling has stopped
//
var ScrollMsgDelay = 1000;



//
//  Scrolls the layer
//
function Scroll(ScrollObject, ScrollMode)
{
  var theScroll = GetStyleFromBase(ScrollObject);
  var theScrollHeight;
  var theScrollWidth;
  if(BrowserType == 'IE')
  {
    theScrollHeight = GetObjFromBase(ScrollObject).offsetHeight;
    theScrollWidth = GetObjFromBase(ScrollObject).offsetWidth;
  }
  else
  {
    theScrollHeight = 500;
    theScrollWidth = 400;
  }
  switch(ScrollMode)
  {
    case sUp :
      status = ScrollUpMsg;
      if(GetTop(theScroll)+ScrollStep-ScrollTopBlank <= 0)
        Move(theScroll, 0, ScrollStep);
      else
        MoveToY(theScroll,ScrollTopBlank); 
      break;
    case sDown :
      status = ScrollDownMsg;
      if(ScrollBottomVisible-GetTop(theScroll)+ScrollStep <= theScrollHeight)
        Move(theScroll, 0, -ScrollStep);        
      else
        MoveToY(theScroll, ScrollBottomVisible-theScrollHeight);
      break;
    case sLeft :
      status = ScrollLeftMsg;
      if(GetLeft(theScroll)+ScrollStep-ScrollLeftBlank <= 0)
        Move(theScroll, ScrollStep, 0);
      else
        MoveToX(theScroll, ScrollLeftBlank);
      break;
    case sRight :
      status = ScrollRightMsg;
      if(ScrollRightVisible-GetLeft(theScroll)+ScrollStep <= theScrollWidth)
        Move(theScroll, -ScrollStep, 0);
      else
        MoveToX(theScroll, ScrollRightVisible-theScrollWidth);
      break;
  }
  ScrollTimer = setTimeout("Scroll('"+ScrollObject+"',"+ScrollMode+")",ScrollDelay);	
}

//
// Stops the scroll
//
function StopScroll()
{
  clearTimeout(ScrollTimer)
  setTimeout("status=''", ScrollMsgDelay);
}






