var news_scroller_current = 0;
var news_scroller_timeout = 3000;
var news_scroller_timer;

function news_scroller_select( position ) {
	window.clearTimeout( news_scroller_timer );

	$( "li:eq(" + news_scroller_current + ")", "#news_fader" ).animate(
		{
			"opacity": 0
		},
		{
			queue: false,
			duration: 1000,
			easing: "easeInOutSine",
			complete: function() {
				$( "li:eq(" + news_scroller_current + ")", "#news_fader" ).css( "display", "none" );
				$( "li:eq(" + position + ")", "#news_fader" ).css( "display", "block" );
				$( "li:eq(" + position + ")", "#news_fader" ).animate(
					{
						"opacity": 1
					},
					{
						queue: false,
						duration: 1000,
						easing: "easeInOutSine",
						complete: function() {
							news_scroller_current = position;
							news_scroller_timer = window.setTimeout( "news_scroller_next()", news_scroller_timeout );
						}
					},
					function () {
					}
				);
			}
		},
		function () {
		}
	);
}

function news_scroller_next() {
	var next_position = news_scroller_current + 1;

	if( next_position < news_scroller_images_length ) {
		news_scroller_select( next_position );
	} else {
		news_scroller_select(0);
	}
}

$( document ).ready( function() {
	$( "li:not(:eq(0))", "#news_fader" ).css({
		"display": "none",
		"opacity": 0
	});

	news_scroller_images_length = $( "li", "#news_fader" ).length;
	news_scroller_timer = window.setTimeout( "news_scroller_next()", news_scroller_timeout );
});

