var scrollerStep = 1;
var scrollerIntervalMs = 200;

function initScroller()
{
	$('.autoscroll').each( function() {

		$(this).mouseover(function() { doPause(this); });

		$(this).mouseout(function() { doPause(this); });

	});

	setInterval("doScroll()", scrollerIntervalMs);	
}

function doScroll()
{
	$('.autoscroll').filter(':not(".paused")').each( function() {

		var x = this.scrollTop;

		// The height of the div, as defined by CSS
		var divHeight = parseInt($(this).css('height'));
		var divPadding = parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom'));
		
		// The height of the div's contents
		var contentHeight = this.scrollHeight;

		// Increment the position we're scrolling to by 1px
		x += scrollerStep;

		// Start over if we've scrolled too far
		if(x > (contentHeight - (divHeight + divPadding))) x = 0;
					
		// Scroll!
		this.scrollTop = x;

	});
}

function doPause(el)
{
	$(el).toggleClass('paused');
}

$(document).ready(function() {
   initScroller();
});
