/*
Scroller.js - a DHTML scroller
This JS scroller -- in combination with 2 DIV objects and some light CSS for each DIV -- allows for event driven
text scrolling without ugly scroll bars.
The basic idea makes use of the CSS "overflow" declaration's standard behavior.

INSTRUCTIONS FOR USE:
1) Include this script in the HEAD block of the HTML file where it is needed or copy it into a script block.
2) Create 2 DIVs in the BODY block.  They should be nested so that 1 DIV is contained by the other.
3) Give each of the new DIV blocks a unique id and change the values of the global variables containerDiv and contentDiv accordingly (see below).
4) Set the following CSS styles for each DIV either inline or in a style sheet:
	For "containerDiv" --
	position:absolute;
	top:Tpx;
	left:Lpx;
	width:Wpx;
	height:Hpx;
	overflow:hidden;
	
	***** (Note: T,L,W, and H may have whatever value you wish, but they must be declared.) *****
	
	For "contentDiv" --
	position:absolute;
	top:0px;
	left:0px;

5) Create 2 "<A>" (Link objects) to trigger scrolling up and down in the body of the HTML.
6) Choose 1 of the following pairs of event triggers to include in the Links created in step 5:
	-- 'onMouseOver' + 'onMouseOut':
		Scrolling will occur when the mouse pointer is placed over the link and will cease when it is moved away.
		
	-- 'onMouseDown' + 'onMouseUp':
		Behaves more like traditional scroll bars. Clicking and holding down on a link will cause the content to scroll.
		Releasing the mouse button causes scrolling to stop.
		
	** 	Assign 'scrollUp()' or 'scrollDown()' (depending on what is desired) to the start event
		and 'stopScroll()' to the stop event.

7) Review the global variables below, some customization is possible.


*/


// Required Global Variables
var containerDiv = "container"; // the id of the Containing DIV Block
var contentDiv = "content"; // the id of the Content DIV Block

var scrollIncr = 3; // Must be greater than 0. Higher numbers increase scroll rate but scrolling is smoother with lower numbers.
var timeoutDelay = 10; // The Delay (in ms) of the scrolling timeout. Use with scrollIncr to control scrolling speed. Limited by processing time.
var positionUnit = "px"; // Unit of measure used when scrolling the contentDiv. 

// Private global variables, do not change these, they are used by the methods below.
var direction = null; // DO NOT SET MANUALLY! direction can be "up" or "down" and is set by the methods below.
var timeoutID = null; // DO NOT SET MANUALLY! holds the timeoutID while the timeout is set.

// Cross-Browser microAPI Function

function getObj(name)
{
  if (document.getElementById)
  {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
        this.obj = document.all[name];
        this.style = document.all[name].style;
  }
  else if (document.layers)
  {
        this.obj = document.layers[name];
        this.style = document.layers[name];
  }
}

// Scroller Functions


function scrollUp(containerDivId,contentDivId)
{
	direction = "up";
	containerDiv = containerDivId;
	contentDiv = contentDivId;
	scrollIncr = Math.abs(scrollIncr);
	scroll();
}

function scrollDown(containerDivId,contentDivId)
{
	direction = "down";
	containerDiv = containerDivId;
	contentDiv = contentDivId;
	scrollIncr = Math.abs(scrollIncr) * -1;
	scroll();
}

function stopScroll()
{
	clearTimeout(timeoutID);
}


function scroll()
{
	// Initialize Objects and Variables
	var inner = new getObj(contentDiv);
	var outer = new getObj(containerDiv);
	
	var bContinue = true; // used to prevent scrolling too far in either direction.
	var upLimit = 0;
	var downLimit = outer.obj.offsetHeight - inner.obj.offsetHeight;		
	
	var innerTop_num = inner.obj.offsetTop;
	if((direction == "up" && innerTop_num >= upLimit) || (direction == "down" && innerTop_num <= downLimit)) bContinue = false;
	
	if(bContinue){
		innerTop_num = innerTop_num + scrollIncr;
		inner.style.top = innerTop_num.toString() + positionUnit;
	}
	
	timeoutID = setTimeout("scroll()",timeoutDelay);
				
}


// ---------------------------------------------------------

function lib_numeric_value(inp,unit_str)
{
	return Number(inp.substring(0,inp.indexOf(unit_str)));
}