

/*====
 * rotator
 *================================================ */

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){
	$("div#topStories").removeClass('noscript'); 
	$("div#topStories").addClass("active");
	headline_count = $("div.topStoryItem").size();
	$("div.topStoryItem:eq("+current_headline+")").css('display','block');

	headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
	$("div#topStories").append('<div id="topStoryButtons"><ul></ul></div>');
	$('div#topStories .topStoryItem h3').each(function(index) { //if use topStoryItem h3 do not use any h3 in splash
		var $sectionLabel = $(this).remove().text();
		$("div#topStoryButtons ul").append('<li class="' + $sectionLabel + '">' + $sectionLabel + '</li>');
		$("#topStoryButtons li:eq(0)").addClass('activeControls'); 
	});
	$("div#topStories").append('</ul></div>');
	$("#topStoryButtons li:eq(0)").click(function() { 
		selected_headline = 0;
		$("div.topStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#topStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#topStoryButtons li:eq(0)").addClass('activeControls'); 
		$("div.topStoryItem:eq(0)").fadeIn("slow"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
	$("#topStoryButtons li:eq(1)").click(function() { 
		selected_headline = 1;
		$("div.topStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#topStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#topStoryButtons li:eq(1)").addClass('activeControls'); 
		$("div.topStoryItem:eq(1)").fadeIn("slow"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
	$("#topStoryButtons li:eq(2)").click(function() { 
		selected_headline = 2;
		$("div.topStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#topStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#topStoryButtons li:eq(2)").addClass('activeControls'); 
		$("div.topStoryItem:eq(2)").fadeIn("show"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
	$("#topStoryButtons li:eq(3)").click(function() { 
		selected_headline = 3;
		$("div.topStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#topStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#topStoryButtons li:eq(3)").addClass('activeControls'); 
		$("div.topStoryItem:eq(3)").fadeIn("slow"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
		$("#topStoryButtons li:eq(4)").click(function() { 
		selected_headline = 4;
		$("div.topStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#topStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#topStoryButtons li:eq(4)").addClass('activeControls'); 
		$("div.topStoryItem:eq(4)").fadeIn("slow"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
		
//rightBox
$("#rightBoxTabsBlog").click(function() {
		$(this).css("background-image","url(/images/splash/rightBoxBlogActive.gif)");
		$("#rightBoxTabsArticles").css("background-image","url(/images/splash/rightBoxArticlesOff.gif)");
		$("#rightBoxTabsConditions").css("background-image","url(/images/splash/rightBoxArticlesOff.gif)");
		$("#rightBoxBlog").css("visibility","visible");
		$("#rightBoxArticles").css("visibility","hidden");
		$("#rightBoxConditions").css("visibility","hidden");
});
$('#rightBoxTabsArticles').click(function() {
		$("#rightBoxTabsBlog").css("background-image","url(/images/splash/rightBoxBlogOff.gif)");
		$(this).css("background-image","url(/images/splash/rightBoxArticlesActive.gif)");
		$("#rightBoxTabsConditions").css("background-image","url(/images/splash/rightBoxArticlesOff.gif)");
		$("#rightBoxBlog").css("visibility","hidden");
		$("#rightBoxArticles").css("visibility","visible");
		$("#rightBoxConditions").css("visibility","hidden");
});
$("#rightBoxTabsConditions").click(function() {
		$("#rightBoxTabsBlog").css("background-image","url(/images/splash/rightBoxBlogOff.gif)");
		$("#rightBoxTabsArticles").css("background-image","url(/images/splash/rightBoxArticlesOff.gif)");
		$(this).css("background-image","url(/images/splash/rightBoxArticlesActive.gif)");
		$("#rightBoxBlog").css("visibility","hidden");
		$("#rightBoxArticles").css("visibility","hidden");
		$("#rightBoxConditions").css("visibility","visible");
});
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count; 
	$("div.topStoryItem:eq(" + old_headline + ")").fadeOut("slow");
	$("#topStoryButtons li:eq(" + old_headline + ")").removeClass('activeControls'); 
	$("#topStoryButtons li:eq(" + current_headline + ")").addClass('activeControls'); 
	$("div.topStoryItem:eq(" + current_headline + ")").fadeIn("slow"); 
	old_headline = current_headline;
}

