//###############################################################################################
//#
//#	MSOE BEC Template developed by WSI 
//#	Date: 04/13/2011 
//#	Contact: Dave Rank, Dave.Rank@wsiMarketReach.com, 262-617-6170
//#
//# Portions of the software may be (c) 2003-2011 by the Sterling Technologies Group, Ltd., Milwaukee, WI. 
//# 414-455-5492. For more information, please contact <Info@SterlingTech.Net>. Used with permission.
//#
//###############################################################################################
// Update History
//
// 2011-03-30 MAZ Removed IE-style opacity settings due to an IE8 display artifacts; dimming on scroll
//                now only occurs on browsers supporting the Mozilla opacity model.
//
//###############################################################################################

var INITAL_OPACITY = 40;
var ANIMATION_DELAY_TIMER = 10;
var ANIMATION_SPEED = 1;
var PIXELS_TO_MOVE = 3;

function smoothScrollDiv(scrollingDiv,prefix,timer) 
{
	var current_pos = Math.abs(scrollingDiv.current);
	var target_pos = Math.abs(scrollingDiv.target);
	var dir = scrollingDiv.direction;

	if((target_pos - current_pos <= ANIMATION_SPEED && dir == -1) || (current_pos - target_pos <= ANIMATION_SPEED && dir == 1)) 
	{
		scrollingDiv.style.top = (scrollingDiv.target * -1) + 'px';
		scrollingDiv.style.opacity = 1;
//		scrollingDiv.style.filter = 'alpha(opacity=100)';
		clearInterval(scrollingDiv.timer);
		if(scrollingDiv.scrollActive) 
		{
			scrollingDiv.timer = setTimeout( function() { autoScroll(scrollingDiv.id,prefix,timer) }, timer * 1000);
		}
	}
	else 
	{
		var pos = (dir == 1) ? parseInt(scrollingDiv.current) + ANIMATION_SPEED*10 : scrollingDiv.current - ANIMATION_SPEED;
		scrollingDiv.current = pos;
		scrollingDiv.style.top = pos + 'px';
	}
}


function scrollAnimate(div,dir,limit) 
{
	div.style.top = div.style.top || '0px';
	var top = div.style.top.replace('px','');
	if(dir == 1) 
	{
		if(limit - Math.abs(top) <= PIXELS_TO_MOVE) 
		{
			div.style.opacity = 1;
			div.style.filter = 'alpha(opacity=100)';
			clearTimeout(div.timer);
			div.style.top = '-' + limit + 'px';
		}
		else
		{
			div.style.top = top - PIXELS_TO_MOVE + 'px';
		}
	}
	else
	{
		if(Math.abs(top) - limit <= PIXELS_TO_MOVE) 
		{
			div.style.opacity = 1;
			div.style.filter = 'alpha(opacity=100)';
			clearTimeout(div.timer);
			div.style.top = limit + 'px';
		}
		else
		{
			div.style.top = parseInt(top) + PIXELS_TO_MOVE + 'px';
		}
	}
}


function autoScroll(id,prefix,timer,restart) 
{
	var div = document.getElementById(id);
	div.scrollActive = (div.scrollActive || restart);
	if(div.scrollActive) 
	{
		var length = div.getElementsByTagName('div').length;
		div.section = ((div.section && div.section < length) ? div.section + 1 : 1);
		var currentMovingSection = document.getElementById(prefix + '-' + div.section);
		if (currentMovingSection != null)
		{
			var scrollingDiv = currentMovingSection.parentNode;
			clearInterval(scrollingDiv.timer);
			scrollingDiv.target = currentMovingSection.offsetTop;
			scrollingDiv.style.top = scrollingDiv.style.top || '0px';
			scrollingDiv.current = scrollingDiv.style.top.replace('px','');
			scrollingDiv.direction = (Math.abs(scrollingDiv.current) > scrollingDiv.target) ? 1 : -1;
			scrollingDiv.style.opacity = INITAL_OPACITY * .01;
//			scrollingDiv.style.filter = 'alpha(opacity=' + INITAL_OPACITY + ')';
			scrollingDiv.timer = setInterval( function() { smoothScrollDiv(scrollingDiv,prefix,timer) }, ANIMATION_DELAY_TIMER);
		}
	}
}


// Used with mouseover to stop scroll
function cancelAutoScroll(id) 
{
	var div = document.getElementById(id);
	div.scrollActive = false;
	div.style.opacity = 1;
//	div.style.filter = 'alpha(opacity=100)';
	clearTimeout(div.timer);
}





// Used with mouseout to stop scroll
function restartAutoScroll(id,prefix,timer,restart) 
{
	// Stall for 0.75 scroll delays (5 secs vs. 7), then start the scroll as before
	var div = document.getElementById(id);
	div.scrollActive = true;
	clearInterval(div.timer);
	div.timer = setTimeout( function() { autoScroll(id,prefix,timer,restart) }, timer * 0.75 * 1000);
}


