// JavaScript Document
/*
	*** Created by Matthew Bagley
	*** http://www.paramiliar.com
	*** requires prototype and scriptaculous
*/

function nextentry(){
	entries = $$('#scrolling_news div.scrolling');
	current = $$('#scrolling_news div.active');
	height = parseInt(current[0].offsetHeight);	
	if (typeof(jumptofirst) == 'undefined')jumptofirst = 0;
	if (entries.length > 1){
		for (var i = 0; i < entries.length; i++){
			if (entries[i].className.indexOf('active') > -1){
				if (i == (entries.length - 1)){// move them all around
					for (var j = 0; j < (entries.length - 1); j++)
						entries[j].style.top = height +  "px";
					next = 0;
					jumptofirst = 1;
				} else {
					offset = i + 1;
					next = i + 1;
				}
				new Effect.Opacity(entries[i], { from: 0.99, to: 0, duration: 0.75 });
			} else {
				new Effect.Opacity(entries[i], { from: 0, to: 0.99, duration: 1.5 });
			}
			new Effect.Move(entries[i], { x: 0, y: (height * -1) });
		}
		if (jumptofirst == 1 && parseInt(next) == 1){
			entries[(entries.length - 1)].style.top = 0 + "px";
			jumptofirst = 0;
		}
		entries[next].className = "scrolling active";
		current[0].className = "scrolling";
	}
}

Event.observe(window, 'load', function() { 	
	var pe = new PeriodicalExecuter(function() {nextentry();}, 5);
	$('scrolling_news').observe('mouseover', function(){pe.callback = function(){return false;};});
	$('scrolling_news').observe('mouseout', function(){pe.callback = function() {nextentry();};});
});				
