// scrolling pane script
// Mike Pratt, Syrox, 05/05/2006

// change these variables

var scrollSpeed = 2;          // 1 = slow, 10 = fast
var scrollDirection = 1;      // 1 = up, -1 = down
var pauseOnRollover = true;   // true or false
var scrollTimeout = 40;       // delay in ms between scroll steps

// don't change anything below this line

var currentSpeed = scrollSpeed;  
var scrollContainer;
var scrollContentHeight;
var scrollContentHeightHalf;
var scrollContent;
var currentScroll

function scrollUp() {
	scrollDirection = 1;
	setScroll( normaliseScroll ( getScroll() ) );
}

function scrollDown() {
	scrollDirection = -1;
	setScroll( normaliseScroll ( getScroll() ) );
}  

function pauseScroll() {
	if ( pauseOnRollover )
	  currentSpeed = 0;  
}

function unpauseScroll() {
	if ( pauseOnRollover )
	  currentSpeed = scrollSpeed;
}

function doScroll() {
	var scroll = getScroll();
	
	scroll += scrollDirection * currentSpeed;
	
	scroll = normaliseScroll(scroll);
	
	setScroll(scroll);
	window.setTimeout(doScroll,scrollTimeout);
}  

function getScroll() {
	return -parseInt(scrollContent.style.top);
}

function setScroll(v) {
	scrollContent.style.top = (-v) + "px";
}  

function normaliseScroll(value) {
	if ( scrollDirection == 1 && value > scrollContentHeightHalf )
	  value -= scrollContentHeightHalf;
	else if ( scrollDirection == -1 && value < 0 )
	  value += scrollContentHeightHalf;
	return value;
}

function initScroll() {
	scrollContainer = document.getElementById("scrollercontainer");
	scrollContent = document.getElementById("vmarquee");
	scrollContentHeight = parseInt ( scrollContent.offsetHeight );
	scrollContentHeightHalf = scrollContentHeight / 2;    
	window.setTimeout(doScroll,scrollTimeout);
	setScroll(0);
}

if (window.addEventListener)
	window.addEventListener("load", initScroll, false);

else if (window.attachEvent)
	window.attachEvent("onload", initScroll);

else if (document.getElementById)
	window.onload=initScroll;