$(document).ready(function(){					   
	var list = $('.project_item');
	if ( list.length == 1 )
	{
		$('a.nextproject').hide();
		$('a.prevproject').hide();	
	} else {
		
		var next = 0;
		var timerChange = 0;
		var prev = list.length;
		
		function nextproject ()
		{
			$(list).hide();

			if ( next == list.length-1 )
			{
				next = 0;	
			}
			else
			{	
				next = next+1;	
			}
			
			prev = next;
			var project = list.eq(next);
			project.fadeIn('fast');
			clearTimeout ( timerChange );
			timerChange = window.setTimeout(nextproject, 4000);
		}
		
		function prevproject ()
		{
			$(list).hide();
			
			if ( prev == 0 )
			{
				prev = list.length-1;	
			}
			else
			{	
				next = prev;
				prev = prev-1;	
			}
			
			next = prev;
			var project = list.eq(prev);
			project.fadeIn('fast');
			clearTimeout ( timerChange );
			timerChange = window.setTimeout(nextproject, 4000);
		}
	
	}
	
	$('a.nextproject').click(function(){		
		nextproject();
		return false;
	});
	
	
	$('a.prevproject').click(function(){		
		prevproject();
		return false;
	});
	
	timerChange = window.setInterval(nextproject, 4000);
	
});
