var newstotal = null;
var newsmargin = 0;

window.addEvent('domready', function() {
	var newslist = $$('#marqueeWrapper ul');
	newstotal = newslist[0].getChildren('li').length * 39;
	newslist.setStyle('height', newstotal + 'px'); //sets the width of the ul given the number of li's
	
	if (newslist[0].getChildren('li').length>1) {
		(function() { StartNewsSlider() }).delay(2500);
	}
});

function StartNewsSlider() {	
	//if we are about to slide the last news article out, we want to move the last li to the front of the ul and then reset the margins, so the scrolling continues correctly!
	if ((newstotal-(newstotal*2)+39)==newsmargin) {
		var ul = $('marqueeSlider');
		var lastitem = $$('#marqueeWrapper li:last-child');
		
		lastitem.inject(ul, 'top');
		ul.setStyle('margin-top','0px');
		newsmargin = 0;
	}
	var newsslide = new Fx.Morph('marqueeSlider', {duration:750, transition:Fx.Transitions.Quad.easeInOut, link:'ignore'});
	newsslide.start({ 'margin-top': [(newsmargin-39) + 'px'] });
	newsslide.addEvent('complete', function() {
		newsmargin = newsmargin-39;
		(function() { StartNewsSlider() }).delay(5000);
	});
};