$(document).ready(function(){
	
	var prevID = 1;
	
	$("#slide-show #image1").show();
	$("#slide-show .nav #ss1").addClass("active");
	//$("#slide-show #image1").fadeOut("2000");
	
	var timer = setInterval(switchImage, 8000);
	
	$("#slide-show .slide-nav .nav .nav-item").click(function(){
															  
		clearInterval(timer);
		
		var imgID = $(this).attr("id").split("ss")[1];
		
		$("#slide-show .nav").children().removeClass("active");
		$(this).addClass("active");
		
		if(imgID > prevID){
			$("#slide-show #image"+imgID).fadeIn("3000", function(){
				$("#slide-show #image"+prevID).hide();	
				prevID = imgID;
			});
		}
		else if(imgID < prevID){
			$("#slide-show #image"+imgID).show();
			$("#slide-show #image"+prevID).fadeOut("3000", function(){	
				prevID = imgID;
			});	
		}
	});
	
	function switchImage(){
		if(prevID != 8){	
			var imgID = prevID + 1;
		}else{
			imgID = 1;
		}
		
		$("#slide-show .nav").children().removeClass("active");
		$("#slide-show .nav #ss" + imgID).addClass("active");
		
		if(imgID > prevID){
			$("#slide-show #image"+imgID).fadeIn("3000", function(){
				$("#slide-show #image"+prevID).hide();	
				prevID = imgID;
			});
		}
		else if(imgID < prevID){
			$("#slide-show #image"+imgID).show();
			$("#slide-show #image"+prevID).fadeOut("3000", function(){	
				prevID = imgID;
			});	
		}	
	}
});
