$(document).ready(function(){

	counter = 1;
	
	$(".home_bg, .home_work").hide();
	$(".home_bg:first").addClass("activeBg").show();
	$(".home_work:first").addClass("activeDesc").show();
	$(".featuredlink:first").addClass("featured").show();


	$(".next-featured").click(function(){	
		counter++;
		totalFeatured = $(".home_bg").length;
		if(counter <= totalFeatured){
		
			$(".activeBg + .home_bg").addClass("activeBg").fadeIn(600, function(){
			$(".activeBg:first").removeClass("activeBg").fadeOut(500);
			$(".activeDesc + .home_work").addClass("activeDesc");
			$(".activeDesc:first").removeClass("activeDesc").fadeOut(600, function(){
			$(".activeDesc").fadeIn(200);
			});
			
			$(".featured + .featuredlink").addClass("featured");
			$(".featured:first").removeClass("featured");

			});

			}else{
			
			counter = 1;
					if(totalFeatured > 1){
			$(".home_bg:first").addClass("activeBg").fadeIn(600, function(){
			$(".activeBg:last").removeClass("activeBg").fadeOut(500);

			$(".featured:first").addClass("featured");
			$(".featured:last").removeClass("featured");

			$(".home_work:first").addClass("activeDesc");
			$(".activeDesc:last").removeClass("activeDesc").fadeOut(600, function(){
			$(".home_work:first").fadeIn(200);			
			});
			});
		}
		}
	
	});


	$(".prev-featured").click(function(){	
		counter--;
		totalFeatured = $(".home_bg").length;

		if(counter >= 1){
		
			$(".activeBg").prev(".home_bg").addClass("activeBg").fadeIn(600, function(){
			$(".activeBg:last").removeClass("activeBg").fadeOut(500);
			
			$(".featured").prev(".featured").addClass("featured");
			$(".featured:last").removeClass("featured");
			
			$(".activeDesc").prev(".home_work").addClass("activeDesc");
			$(".activeDesc:last").removeClass("activeDesc").fadeOut(600, function(){
			$(".activeDesc").fadeIn(200);
			});
			});

			}else{

			counter = totalFeatured;
			if(totalFeatured > 1){
			$(".home_bg:last").addClass("activeBg").fadeIn(600, function(){
			$(".activeBg:first").removeClass("activeBg").fadeOut(500);
			
			$(".featured:last").addClass("featured");
			$(".featured:first").removeClass("featured");
			
			$(".home_work:last").addClass("activeDesc");
			$(".activeDesc:first").removeClass("activeDesc").fadeOut(600, function(){
			$(".home_work:last").fadeIn(200);			
			});
			});
		}
		}
	
	});

});
