var myInterval = '';
var activeNews = 5;
var numNews = 6;

function startTicker() {
	activeNews = $('#ticks > div').length - 1;
	numNews = $('#ticks > div').length;
	$("#ticks > *").hover(function(){
		$(this).css("cursor","pointer");
		if ($(this).hasClass("tickerbottom")) {
			$(this).toggleClass("tickerbottomover");
		} else {
			$(this).toggleClass("tickerover");
		}
	},function(){
		if ($(this).hasClass("tickerbottom")) {
			$(this).toggleClass("tickerbottomover");
		} else {
			$(this).toggleClass("tickerover");
		}
	});
	
	$("#ticks > *").click(function() {
		if (myInterval > 0) {
			clearInterval(myInterval);
			myInterval = -1
		}
		$("#ticks > *").removeClass("tickerselect");
		$(this).addClass("tickerselect");
		changeNews($(this).attr("storyid"));
	});
	
	changeTicker();
	myInterval = setInterval("changeTicker()",6000);
}

function changeTicker() {
	$("#news"+(activeNews+1)).removeClass("tickerselect");
	activeNews = (++activeNews%numNews);
	$("#news"+(activeNews+1)).addClass("tickerselect");
	changeNews(activeNews+1);
}

function changeNews(storyID) {
	for (x=1;x<=numNews;x++) {
		$("#newslide"+x).css("display","none");
	}
	$("#newslide"+storyID).css("display","block");
}

$(document).ready(function(){
	$('#leadersInterface li.leader-item a').click(
		function()
		{
			var $curParent = $(this).parents('li.leader-item');
			if(!$curParent.hasClass('current-leader'))
			{
				var $curLeader = $('#leadersInterface li.current-leader');
				var leaderId = $('a', $curLeader).attr('id');
				var thisId = $(this).attr('id');

				$curLeader.removeClass('current-leader')
				$curParent.addClass('current-leader')
				$('#'+leaderId+'-div').removeClass('current-leader');
				$('#'+thisId+'-div').addClass('current-leader');
			}
			return false;
		}
	);
});