/*
	News Carousel 
	@author Luke Williams
	@version 1, built for Radical Distrust / Red Root
*/


function init_carousel()
{
	var i;
	var nextItem;
	
	
	
	// set up the links
	$("#carouselButtons ul li").each(function(i,val)
	{
		
		$(this).click(function()
		{
			if($(this).hasClass("currentLink") == false)
			{

				i = $(this).html(); // grab the number inside
				i--; // increment to matche indexes on newsItem divs
				
				nextItem = $("#carousel .workItem"+i);
				
				if(nextItem.length) // if this item exists
				{
					// .current has a z-index of 5, so make next item appear behind it using removeClass
					
					
					// next, fadeOut the current item and remove its class.
					$("#carousel .workItem.current").fadeOut(function()
					{
						$(this).removeClass("current");
					});
					//nextItem.removeClass("hide");
					nextItem.fadeIn();
					
					// add current to the new item and update links
					nextItem.addClass("current");
					nextItem.css("display","block");
					$(this).addClass("currentLink");
					$(this).siblings().removeClass("currentLink");
				}
			}
		});
	});
	
	// add current to first
	$("#carouselButtons ul li:first").addClass("currentLink");
	
}

$(document).ready(function() {
	init_carousel();
});
