$(document).ready(function(){
	var newsIndexCount = 0;
	myInterval = setInterval(function() {
		changeNews((++newsIndexCount<3)?newsIndexCount:newsIndexCount=0);
	}, 5500);
	
	$("#MainNews").find('a').hover(function(){
		clearInterval(myInterval);
		newsIndex = $("#MainNews ul li").index($(this).parents('li'));
		newsIndexCount = newsIndex;
		changeNews(newsIndex);
	},function(){
		myInterval = setInterval(function() {
			changeNews((++newsIndexCount<3)?newsIndexCount:newsIndexCount=0);
		}, 5500);
	});
	
	$(".georgian-courts").find('a').click(function(){
		$("#GeorgianCourtsBox").toggle();
		return false;
	})
});

function changeNews(newsIndex){
	
	if ($("#MainNews").find("img:animated").length)
	{
		$("#MainNews").find(".photo").hide();
		$("#MainNews").find("img").css({opacity: 1});
		$("#MainNews").find('a.active').parents('li').find('.photo').show();
	}
	
	CurrentNewsBlock = $("#MainNews ul").children('li:eq('+newsIndex+')');

	LatestNewsBlock = $("#MainNews").find('a.active');
	
	$(LatestNewsBlock).removeClass('active');
	
	$(CurrentNewsBlock).find('a').addClass('active');
	
	$(LatestNewsBlock).parents('li').find(".photo")
		.css('background-image','url('+$(CurrentNewsBlock).find(".photo img").attr('src')+')');

	$(LatestNewsBlock).parents('li').find(".photo img").animate(
			{opacity: 0},
			400,
			function(){
				$("#MainNews").find(".photo img").css({opacity: 1});
				$("#MainNews").find(".photo").hide();
				$(CurrentNewsBlock).find(".photo").show();
			}
	);
}
