/*
 *	Simple DHTML Scroller
 *	minimal no-scrollbar scrolling library
 *	Copyright (C) 2005 Traction Corporation.  All Rights Reserved
 *	http://www.tractionco.com/
 */

var kScrollMax = 1;						// set by initScroller.  negative value of max vertical position to scroll to
var kScrollOrigin = 0;					// y origin of scrolled content
var kScrollContent = 'scrollContent';	// ID of object we're scrolling
var kScrollWrapper = 'scrollArea';		// ID of scroller object wrapper
var bContinueScroll = false;			// boolean flag for if there should currently be scrolling

function initScroller(){
	kScrollMax = (document.getElementById(kScrollWrapper).offsetHeight - document.getElementById(kScrollContent).offsetHeight);
}

function boundsCheck(edge,candidatePos){
	var returnState = false;
	if(edge == "bottom"){
		if(candidatePos <= kScrollMax){
			returnState=false;
		}else{
			returnState=true;
		}
	}else{
		if(candidatePos >= kScrollOrigin){
			returnState = false;
		}else{
			returnState = true;
		}
	}
	return returnState;
}

function doScroll(direction){
	// direction is a boolean.  true for up
	incrementSpeed = 10;	// to avoid 'lurching' make the setTimeout duration in moveTo() a multiple of incrementSpeed
	if(direction){
		// scrolling up
		posY = (document.getElementById(kScrollContent).offsetTop + incrementSpeed);
		if(boundsCheck("top",posY) && bContinueScroll){
			moveIt(direction,posY);
		}else{
			if(bContinueScroll){
				endIt(kScrollOrigin);
			}
		}
	}else{
		// scrolling down
		posY = (document.getElementById(kScrollContent).offsetTop - incrementSpeed);
		if(boundsCheck("bottom",posY) && bContinueScroll){
			moveIt(direction,posY);
		}else{
			if(bContinueScroll){
				endIt(kScrollMax);
			}
		}
	}
}

function moveIt(direction,position){
	moveTo(position);
	setTimeout("doScroll("+direction+")",20); // might be good if 1000 were a multiple of this number
}

function endIt(position){
	moveTo(position);
	bContinueScroll = false;
}

function moveTo(position){
	document.getElementById(kScrollContent).style.top = position + "px";
}

function scrollUp(){
	bContinueScroll = true;
	doScroll(true);
}

function scrollDown(){
	bContinueScroll = true;
	doScroll(false);
}
