var canAnimate = true;

$(document).ready(function() {
	$(".smallnewslink").mouseenter(
		function(e) {
			stopAnimating();
			showNews($(e.currentTarget).attr("seria_pos"));
		}
	);

	$(".smallnewslink.active").mouseleave(
		function(e) {
			toid = setTimeout(showNextNews, 6000);
		}
	);
	showNextNews();
});

function stopAnimating() {
	if (toid) clearTimeout(toid);
}

var toid = false;

function showNextNews() {
	showNews((currentIndex < 4 && currentIndex !== false ? (parseInt(currentIndex) + 1) : 0));
	if (toid) clearTimeout(toid);
	toid = setTimeout(showNextNews, 6000);
}

var lastIndex = false;
var currentIndex = false;
function showNews(index) {
	if (lastIndex !== index) {
		if (currentIndex !== false) {
			$("#news_active_" + currentIndex).stop(true, true).fadeOut(400);
		}
		$("#news_active_" + index).stop(true, true).fadeIn(400);

		$("#big_news_" + index).stop(true, true).fadeIn(400);
		if (currentIndex !== false && currentIndex != index) {
			$("#big_news_" + currentIndex).stop(true, true).fadeOut(400);
		}
	}
	currentIndex = index;
	lastIndex = index;
}

