var pauseScroll = false;
var timeoutID;
var lineHeight = 18;
var numLines = 0;
var bottomValue = 452;	
var prevFound;


function autoScroll() {
	if (!pauseScroll) {
		var before = $('#scrollableWrapper').scrollTop();
		
		if (before>=bottomValue) {
			//back to the top
			$('#scrollableWrapper').animate({
    				'scrollTop': '0'
  				}, 500, function() {
    				// Animation complete.
  				});				
		} else {
			//one more step down
			$('#scrollableWrapper').animate({
    				'scrollTop': '+='+ lineHeight
  				}, 250, function() {
    					// Animation complete.
  					});
			}
		timeoutID = window.setTimeout('autoScroll()', 1000);
	} //if
} //autoscroll

$(document).ready(function() {

	endString = (jQuery.support.opacity?"</p>":"</P>");
						   
	//get handle to #scrollableContent
	var h_scrollContent = document.getElementById("scrollableContent");
	var scrollContent = h_scrollContent.innerHTML;
//alert('scrollContent: ' + scrollContent);
	prevFound = scrollContent.indexOf(endString);
	
	while (prevFound != -1) {
	//start while loop on indexOf("</p>") <> -1
		numLines++;
		prevFound = scrollContent.indexOf(endString, prevFound+4);
		
	//increase count
	}
	bottomValue = (numLines-17)*lineHeight;
	
	//alert('bottomValue: ' + bottomValue);

	$('#scrollableWrapper').mouseover(function(){
		pauseScroll=true;
		window.clearTimeout(timeoutID);
	});

	$('#scrollableWrapper').mouseout(function(){
		pauseScroll=false;
		timeoutID = window.setTimeout('autoScroll()', 1000);
	});
	

	timeoutID = window.setTimeout('autoScroll()', 1000);
});


