/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

// JavaScript Document
var news_index = 0;
var news_fading = true;
var news_mouseon = false;

$(function(){
	$(".news").hide();
	$(".news").each(function(index, domElement) {
			$(this).bind("mouseenter", index, enterBtn);
			$(this).bind("mouseleave", index, leaveBtn);
		});
	$(".news:eq(" + news_index + ")").fadeIn(2000, function(){
			news_fading = false;
	   });

	setTimeout("checkNews()", 5000);
});

function enterBtn(ev)
{
	news_mouseon = true;
	$(".news:visible").addClass("news_on");
}

function leaveBtn(ev)
{
	news_mouseon = false;
	$(".news:visible").removeClass("news_on");
}

function checkNews()
{
	if (!news_mouseon)
	{
		news_index++;

		if (news_index == $(".news").length)
			news_index = 0;

		fading = true;
		$(".news:visible").fadeOut("fast", function(){
				$(".news:eq(" + news_index + ")").fadeIn("slow", function(){
						fading = false;
						setTimeout("checkNews()", 5000);
				   });
			});
	}
	else
		setTimeout("checkNews()", 5000);
}
