var scrollSpeed = 1;        /* the higher the value the faster the scroll */
var updateInterval = 100;   /* rate at which scroll function is called */

var autoScroll;             /* on-off function */
var intervalId;             /* handler to setInterval functions */

var currentPos = 0;         /* misc variables */
var mode = 1;
var cursorPos1 = 0;
var cursorPos2 = -1;




function startScroll()
{
 autoScroll = 1;
 intervalId = setInterval( "scrollWindow()", updateInterval );
}


function stopScroll()
{
 autoScroll = 0;
 clearInterval( intervalId );
}


function scrollWindow()
{
 if ( document.all )
  tmpPos = document.body.scrollTop;
 else
  tmpPos = window.pageYOffset;

 mode = ( mode == 0 ) ? 1 : 0;

 if ( mode == 0 )
  cursorPos1 = tmpPos;
 else
  cursorPos2 = tmpPos;
 
 if ( cursorPos1 != cursorPos2 )
 {
  if ( document.all )
   currentPos = document.body.scrollTop + scrollSpeed;
  else
   currentPos = document.pageYOffset + speed;
 }
 else
  currentPos = 0;

 window.scroll( 0, currentPos );
}


function toggleAutoScroll()
{
 if ( autoScroll == 1 )
  stopScroll();
 else
  startScroll();
}


function initScroll()
{
 startScroll();
}
