var ajax_news_timer = 0;
var ajax_news_direction = 1;

function AjaxNews_Go( cur_index , auto )
{
	//***************************
	if( ajax_news_timer != 0 )
	clearInterval(ajax_news_timer);
	
	if( auto == 0 )
	ajax_news_direction = 1;
	//***************************
	
	//***************************
	new Ajax.Request( '/news/act/ajax_index_item/?cur_index=' + cur_index ,
	{
		method:'get',
		onSuccess: function(transport)
		{
			$j('#index_news_container').fadeOut(400,function(){
				$('index_news_container').innerHTML = transport.responseText;
				$j('#index_news_container').fadeIn(400,function(){
					if( auto == 1 )
					AjaxNews_AutoSlide();
				});
			});
		},
		onFailure: function()
		{
			 $('index_news_container').innerHTML = transport.responseText;
		}	
	}
	);
	//***************************
}
function AjaxNews_AutoSlide()
{
	//***************************
	if( document.getElementById('ajax_news_next') != undefined ||
		document.getElementById('ajax_news_preview') != undefined )
		{	
			ajax_news_timer = setInterval( function()
			{
				if( ajax_news_direction == 1 && document.getElementById('ajax_news_next') == undefined )
				ajax_news_direction = 0;
				if( ajax_news_direction == 0 && document.getElementById('ajax_news_preview') == undefined )
				ajax_news_direction = 1;
				
				if( ajax_news_direction == 1 && document.getElementById('ajax_news_next') != undefined )
				AjaxNews_Go( document.getElementById('ajax_news_next').value , 1 );
				if( ajax_news_direction == 0 && document.getElementById('ajax_news_preview') != undefined )
				AjaxNews_Go( document.getElementById('ajax_news_preview').value , 1 );
			} , 5000 );
		}
	//***************************
}