var auto;                   //This will be our timeout ID for the manual scroller functions
var sspeed;                 //This is the automatic scroll speed
var resumesspeed = sspeed;  //When the thing starts scrolling again, it needs to know how fast to go
var containerA;             //This is the container that will hold the scrolling container
var containerheightA;       //The height of containerA

//This function will start the automatic scroller.
function start(whatcontainer, whatdiv, scrollspeed) { 
  sspeed = scrollspeed;
  resumesspeed = sspeed;
  
  if (document.getElementById)  {
    autoscrollV(document.getElementById(whatcontainer), document.getElementById(whatdiv));
  }
}
     
//This function sets the necessary variables with the needed data	    
function autoscrollV(whatcontainer, thediv) {
  containerA = eval(whatcontainer);
  containerheightA = containerA.offsetHeight;
  
  ourdiv=eval(thediv);            //Which div are we talking about
  ourdiv.style.top = 0 + "px";    //Where to place it
  sizeup = ourdiv.offsetHeight;   //How tall is the block
  
  if (sizeup > containerheightA) { //If the content overflows the block, then call the scroller function 
    scrolltext();
  }
}
    
//This function does the scrolling	    
function scrolltext() { 
	
  if (parseInt(ourdiv.style.top) >= sizeup * (-1)) {
    theTop = parseInt(ourdiv.style.top) - sspeed;
    ourdiv.style.top = theTop + "px";
  
	setTimeout("scrolltext()",100); 
  } 
  else {
    ourdiv.style.top = containerheightA + "px";
    scrolltext(); 
  } 
}

//This function does a vertical manual scroll automatically (if that makes sense)
function manualscrollV(direction, div, scrollerdiv, distance, speed) {
  //Clear the current recursion
  clearTimeout(auto);
  
  //The height of the outer div
  container = eval(document.getElementById(div));
  containerheight = container.offsetHeight;
  
  //The height of the div that will scroll. (Should be bigger than the outer div)
  currentHeight = document.getElementById(scrollerdiv).offsetHeight;
  
  //This is where it is currently positioned
  currentposition = parseInt(document.getElementById(scrollerdiv).style.top);
  
  
  //This is the highest point it should be allowed to scroll
  upperBound = containerheight - currentHeight;
  
  
  if (direction == 'up' && currentposition > upperBound)  {
    document.getElementById(scrollerdiv).style.top = (currentposition - distance) + "px";
	currentposition = parseInt(document.getElementById(scrollerdiv).style.top);
	auto = setTimeout("manualscrollV('" + direction + "', '" + div + "', '" + scrollerdiv + "', '" + distance + "', '" + speed + "')", speed);
  }
  if (direction == 'down' && currentposition < 0)  {
    document.getElementById(scrollerdiv).style.top = (parseInt(currentposition) + parseInt(distance)) + "px";
	currentposition = parseInt(document.getElementById(scrollerdiv).style.top);
	auto = setTimeout("manualscrollV('" + direction + "', '" + div + "', '" + scrollerdiv + "', '" + distance + "', '" + speed + "')", speed);
  }
}

//This function does a horizontal manual scroll automatically (if that makes sense)
function manualscrollH(direction, div, scrollerdiv, distance, speed) {
  //Clear the current recursion
  //clearTimeout(auto);   
  
  //The width of the outer div
  container = eval(document.getElementById(div));
  containerwidth = container.offsetWidth;  
  
  //The width of the div that will scroll. (Should be bigger than the outer div)
  currentWidth = document.getElementById(scrollerdiv).offsetWidth;
  
  //This is where it is currently positioned
  currentposition = parseInt(document.getElementById(scrollerdiv).style.left);
 
  //This is the farthest point left it should be allowed to scroll
  leftBound = containerwidth - currentWidth;
  
  if (direction == 'left' && currentposition < 0)  {
    document.getElementById(scrollerdiv).style.left = (parseInt(currentposition) + parseInt(distance)) + "px";
	currentposition = parseInt(document.getElementById(scrollerdiv).style.left);
    auto = setTimeout("manualscrollH('" + direction + "', '" + div + "', '" + scrollerdiv + "', '" + distance + "', '" + speed + "')", speed);
  }

  if (direction == 'right' && currentposition > leftBound)  {
    document.getElementById(scrollerdiv).style.left = (currentposition - distance) + "px";
	currentposition = parseInt(document.getElementById(scrollerdiv).style.left);
    auto = setTimeout("manualscrollH('" + direction + "', '" + div + "', '" + scrollerdiv + "', '" + distance + "', '" + speed + "')", speed);
  }
}
