var totalNewsItems = 4;
	
$(document).ready(function() {
	
	$('#main #featuredNews').css({'overflow':'hidden'});
	$('#main #featuredNewsWrapper').css({'overflow':'hidden'});
	$('#main #featuredNews #moreNews').show();
	
	$('.newsItem').attr("id", function (arr) {
  	return "newsItem" + arr;
  	});
	
	$('.newsItem').each(function(index){
		$(this).css({'display':'none'});
		});
	
	$('#newsItem0').css({'display':'block'});

	$('.newsItem .mainImage img').each(function(index) {
		var currentImage = $(this).attr("src");
		$('#newsItem' + index + ' .mainImage').css({'background':'url(/' + currentImage + ') left top no-repeat'});
		$(this).addClass('hidden');
		});

	$('#featuredNewsWrapper').append(function(){
		var newHTML = '<div id="newsLinks"><ul>';
		$('.newsItem .newsCopy h3').each(function(index){
			if(index == 0){
				newHTML = newHTML + '<li class="first selected"><a href="javascript:" onClick="showNews(' + index + ');">' + $(this).text() + '</a></li>';
			}
			else if(index == totalNewsItems-1){
				newHTML = newHTML + '<li class="last"><a href="javascript:" onClick="showNews(' + index + ');">' + $(this).text() + '</a></li>';
			}
			else {
				newHTML = newHTML + '<li><a href="javascript:" onClick="showNews(' + index + ');">' + $(this).text() + '</a></li>';
			}
			});
		newHTML = newHTML + '</ul></div>';
		return newHTML;
		});
	
});

function showNews(newsIndex){
	$('.newsItem').each(function(index){
		$(this).css({'display':'none'});
		});
	
	$('#newsItem'+newsIndex).css({'display':'block'});
	
	$('#newsLinks li').each(function(index){
		
		$(this).removeAttr("class");

		if(index == 0){
			$(this).addClass("first");
			}
		if(index == totalNewsItems-1){
			$(this).addClass("last");
			}
		if(index == newsIndex){
			$(this).addClass("selected");
			}
		
		});
	}
