$(document).ready(function(){
	
	//bottom left
	$("#index_bottomLeft ul li:not(:first-child):not(.newsNavDivider)").click(function(){
		clearInterval(bottomLeftInterval);
		clearTimeout(bottomLeftTimeout);
		
		$("#index_newsArticles .newsArticle:not(.displayNone)").addClass("displayNone");
		$("#index_newsArticles .newsArticle:nth-child("+$(this).children("a").attr("href").substring(1)+")").css("display","none");
		$("#index_newsArticles .newsArticle:nth-child("+$(this).children("a").attr("href").substring(1)+")").removeClass("displayNone");
		$("#index_newsArticles .newsArticle:nth-child("+$(this).children("a").attr("href").substring(1)+")").fadeIn();
		$(this).parent().children().removeClass("selected");
		$(this).addClass("selected");
	})
	
	var bottomLeftTimeout;
	if($("#index_newsArticles .newsArticle").length>1){
		var bottomLeftInterval = setInterval(function() {
			var currentIndex = $("#index_newsArticles .newsArticle:not(.displayNone)").index()+1;
			$("#index_newsArticles .newsArticle:nth-child("+currentIndex+")").fadeOut(500);
			var oldIndex = currentIndex;
			bottomLeftTimeout = setTimeout(function(){
				$("#index_newsArticles .newsArticle:nth-child("+oldIndex+")").addClass("displayNone");
				$("#index_bottomLeft ul li").removeClass("selected");
				$('#index_bottomLeft ul li a[href="#'+currentIndex+'"]').parent().addClass("selected");
			},500)
	
			if(currentIndex==($("#index_newsArticles .newsArticle").length)){
				currentIndex=1;				
			}else{
				currentIndex++;
			}
	
			$("#index_newsArticles .newsArticle:nth-child("+currentIndex+")").css("display","none");
			$("#index_newsArticles .newsArticle:nth-child("+currentIndex+")").removeClass("displayNone");
			$("#index_newsArticles .newsArticle:nth-child("+currentIndex+")").delay(500).fadeIn("slow");		
			
		}, 10000);
	}else{
		$("#index_bottomLeft ul li:not(li:first-child)").css("visibility", "hidden");
	}
	
	//bottom right top
	if($("#index_bottomRightTop .bottomRight_article").length>1){
		$("#index_bottomRightTop .bottomRight_totalArticles").html("- "+($("#index_bottomRightTop .bottomRight_article:not(.displayNone)").index()-1)+" of "+$("#index_bottomRightTop .bottomRight_article").length+" -");				
		setInterval(function() {
			var currentIndex = $("#index_bottomRightTop .bottomRight_article:not(.displayNone)").index()+1;
			$("#index_bottomRightTop .bottomRight_article:nth-child("+currentIndex+")").fadeOut(500);
			var oldIndex = currentIndex;
			setTimeout(function(){
				$("#index_bottomRightTop .bottomRight_article:nth-child("+oldIndex+")").addClass("displayNone");
				$("#index_bottomRightTop .bottomRight_totalArticles").html("- "+($("#index_bottomRightTop .bottomRight_article:not(.displayNone)").index()-1)+" of "+$("#index_bottomRightTop .bottomRight_article").length+" -");			
			},500);
			
	
			if(currentIndex==($("#index_bottomRightTop .bottomRight_article").length+2)){
				currentIndex=3;					
			}else{
				currentIndex++;
			}
	
			$("#index_bottomRightTop .bottomRight_article:nth-child("+currentIndex+")").removeClass("displayNone");
			$("#index_bottomRightTop .bottomRight_article:nth-child("+currentIndex+")").css("display","none");		
			$("#index_bottomRightTop .bottomRight_article:nth-child("+currentIndex+")").delay(500).fadeIn("slow");
		}, 5200);
	}else{
		//$("#index_bottomRightTop .bottomRight_links").css("visibility","hidden");
	}
	
	//bottom right bottom
	if($("#index_bottomRightBottom .bottomRight_article").length>1){
		$("#index_bottomRightBottom .bottomRight_totalArticles").html("- "+($("#index_bottomRightBottom .bottomRight_article:not(.displayNone)").index()-1)+" of "+$("#index_bottomRightBottom .bottomRight_article").length+" -");
		setInterval(function() {
			var currentIndex = $("#index_bottomRightBottom .bottomRight_article:not(.displayNone)").index()+1;
			$("#index_bottomRightBottom .bottomRight_article:nth-child("+currentIndex+")").fadeOut(500);
			var oldIndex = currentIndex;
			setTimeout(function(){
				$("#index_bottomRightBottom .bottomRight_article:nth-child("+oldIndex+")").addClass("displayNone");
				$("#index_bottomRightBottom .bottomRight_totalArticles").html("- "+($("#index_bottomRightBottom .bottomRight_article:not(.displayNone)").index()-1)+" of "+$("#index_bottomRightBottom .bottomRight_article").length+" -");			
			},500)		
			
			
			if(currentIndex==($("#index_bottomRightBottom .bottomRight_article").length+2)){
				currentIndex=3;					
			}else{
				currentIndex++;
			}
			$("#index_bottomRightBottom .bottomRight_article:nth-child("+currentIndex+")").removeClass("displayNone");					
			$("#index_bottomRightBottom .bottomRight_article:nth-child("+currentIndex+")").css("display","none");		
			$("#index_bottomRightBottom .bottomRight_article:nth-child("+currentIndex+")").delay(500).fadeIn("slow")		
	
		}, 6400);
	}else{
		//$("#index_bottomRightBottom .bottomRight_links").css("visibility","hidden");
	}

})
