// Scroll params and delays
var pOffset = 0;
var divOffset = 0;
var pScroll = 0;
var scrollTime = 90000;
var startDelay = 1000;

// Set initial scroll params
function setScrollParams() {
	divOffset = $('#scrollable').offset().top;
	pOffset = $('#scrollable')[0].scrollHeight;
	pScroll = pOffset + divOffset;
}

// Starts scrolling and always calculates the time remaining for the scroll based on current progress
function startScroll() {
	var currentScrollTop = $('#scrollable')[0].scrollTop;
	var currentTime = scrollTime * ((pScroll - currentScrollTop)/pScroll);
	$('#scrollable').animate({scrollTop: '+=' + pScroll + 'px'}, currentTime);
}

$(document).ready(function() {
		// Fade in the mission statement
		$('div.homeImage').fadeIn(2000);
		$('div.homeText').fadeIn(2000);
	
		// Start the news scrolling
	  setScrollParams();
	  $('#scrollable').animate({opacity: 1.0}, startDelay);
	  startScroll();
	  
	  // Pause scrolling on hover of the news div
	  $('#scrollable').hover(function() {
  		$('#scrollable').stop();
		}, function() {
  		startScroll();
		});
});