var scrollClock;
var scrollPos = 0;
var scrollPause = false;
var bounceNum = 5

function upArrowIndex() {
	
	scrollPause = true;
	clearTimeout(scrollClock);
	if(document.getElementById("scrollbox1").offsetHeight==-scrollPos)
		scrollPos=0;
	var count = document.getElementById("scrollbox1").getElementsByTagName("div").length-1;
	
	var count = document.getElementById("scrollbox1").getElementsByTagName("div").length-1;
	for(i=count; i >= 0; i--) {
		var item = "scrollbox1Item"+i;
		var start = "scrollbox1Item"+count;
		
		//ie bug counts the 'top' incorrectly, needs to manually set offset
		var top = document.getElementById(item).offsetTop-document.getElementById(start).offsetTop;
		var position = top+scrollPos;
		if(position > 0) {
			jumpupIndex(-top);
			return;
		}
	}
	jumpupIndex(-document.getElementById("scrollbox1").offsetHeight);
	//bounceupIndex(scrollPos+bounceNum);
}

function downArrowIndex() {
	scrollPause = true;
	clearTimeout(scrollClock);
	var count = document.getElementById("scrollbox1").getElementsByTagName("div").length-1;
	for(var i = 0; i <= count; i++)	{
		var item = "scrollbox1Item"+i;
		var start = "scrollbox1Item"+count;
		
		//ie bug counts the 'top' incorrectly
		var top = document.getElementById(item).offsetTop-document.getElementById(start).offsetTop;
		var position = top+scrollPos;
		if(position < 0) {
			jumpdownIndex(-top);
			return
		} 
	}
	//item = "scrollbox1Item0";
	//scrollPos= -document.getElementById("scrollbox1").offsetHeight;
	//jumpdownIndex(-document.getElementById(item).offsetTop);
	bouncedownIndex(scrollPos-bounceNum);
}

function jumpdownIndex(jumpto) {
	//document.title = "pos:"+scrollPos+" jumpto:"+jumpto;
	document.getElementById("scrollbox1").style.top = scrollPos;
	document.getElementById("scrollbox2").style.top = scrollPos;
	scrollPos = scrollPos+5;
	if(scrollPos>jumpto)
		scrollPos = jumpto;
	if(scrollPos<=jumpto)
		scrollClock = setTimeout('jumpdownIndex('+jumpto+')', 1);
}

function bouncedownIndex(bounceTo) {
	if(bounceTo < -scrollPos) {
		document.getElementById("scrollbox1").style.top = scrollPos;
		document.getElementById("scrollbox2").style.top = scrollPos;
		scrollPos++;
		scrollClock = setTimeout('bouncedownIndex('+bounceTo+')', 30);
	} else {
		scrollPos = bounceTo+bounceNum;
		document.getElementById("scrollbox1").style.top = scrollPos;
		document.getElementById("scrollbox2").style.top = scrollPos;
	}
}
		

function bounceupIndex(bounceTo) {
	if(bounceTo > scrollPos) {
		document.getElementById("scrollbox1").style.top = scrollPos;
		document.getElementById("scrollbox2").style.top = scrollPos;
		scrollPos++;
		scrollClock = setTimeout('bounceupIndex('+bounceTo+')', 30);
	} else {
		scrollPos = bounceTo-bounceNum;
		document.getElementById("scrollbox1").style.top = scrollPos;
		document.getElementById("scrollbox2").style.top = scrollPos;
	}
}


function jumpupIndex(jumpto) {
	//document.title = "pos:"+scrollPos+" jumpto:"+jumpto;
	document.getElementById("scrollbox1").style.top = scrollPos;
	document.getElementById("scrollbox2").style.top = scrollPos;
	scrollPos = scrollPos-5;
	if(scrollPos<jumpto)
		scrollPos = jumpto;
	if(document.getElementById("scrollbox1").offsetHeight < -scrollPos)
		scrollPos = 0;
	if(scrollPos>=jumpto)
		scrollClock = setTimeout('jumpupIndex('+jumpto+')', 1);
}

function playpauseScrollButton() {
	if(scrollPause) {
		scrollPause = false;
		scrollIndex();
	} else {
		clearTimeout(scrollClock);
		scrollPause = true;
	}
}


function scrollIndex() {
	if(!scrollPause) {
		clearTimeout(scrollClock);
		document.getElementById("scrollbox1").style.top = scrollPos;
		document.getElementById("scrollbox2").style.top = scrollPos;
		scrollPos--;
		if(document.getElementById("scrollbox1").offsetHeight < -scrollPos)
			scrollPos = 4;
		scrollClock = setTimeout('scrollIndex('+scrollPos+')', 150);
	}
}

function restartScroll() {
	if(!scrollPause) {
		clearTimeout(scrollClock);
		scrollClock = setTimeout('scrollIndex('+scrollPos+')', 300);
	}
}

function load() {
	scrollClock = setTimeout('scrollIndex()', 700);
}
