// JavaScript Document

var check = new Array();
for (i=0;i<boxes.length;i++) {
	check[boxes[i]] = false;
}


$(document).ready(function(){
	for (i=0;i<boxes.length;i++)
	{
	   innitiateList(boxes[i]);
	}
});

function innitiateList(whichList)
{
	/* start at a random position - get total height, divide it by height of each box -turn that into an integer to get number of boxes, then choose a random start point */
	var units = Math.floor(($('#'+whichList+" .rollList").height() - 80)/40);
	$('#'+whichList+" .rollCont").scrollTop(Math.floor(Math.random()*units)*40);
	
	moveList(whichList);
	$("#"+whichList).hover(
	 function()
	 {
		 check[whichList] = true;
	 },
	 function()
	 {
		 check[whichList] = false;
	 });
}
					   

function moveList(whichList){
	currentTop = $('#'+whichList+" .rollCont").scrollTop();
	if(currentTop >= ($('#'+whichList+" .rollList").height() - 80) )
	{
		newTop = 0;
		/* jump to the top of the list */
	}else{
		newTop = currentTop + 40;
	}
	if(check[whichList] === false)
	{
		if(newTop == 0)
		{
			$('#'+whichList+" .rollCont").scrollTop(0);
			newTop = 40;
		}
		$('#'+whichList+" .rollCont").animate({
		scrollTop: newTop
		},500);
	}
	
	setTimeout(function(){
		moveList(whichList);
	  },1000);
};
