$(document).ready(function() {
	var fadeSpeed = 1000;
	var currentSlide = 3;
	var setSeconds = 18;
	var pauseAuto = setSeconds;		

	setInterval(slAuto, 1000);				
	$(".sl_next").click(slNext);
	$(".sl_back").click(slBack);
	
	$("#slideshow li").hide();
	$("#slideshow li:last").show();
	
	var totalSlides = $("#slideshow li").length;

	$("#slideshow li").each(function() {
		var slIndex = $("#slideshow li").index(this);
		slIndex++;
		$(this).find(".sl_of").text("" + ((totalSlides - slIndex) + 1) + " of " + totalSlides);
	});

			
	function slAuto() { 
		if (pauseAuto != 0) { pauseAuto--; } else {
			pauseAuto = setSeconds;
			moveNext();				
			return false;
		}
	}
	
	function slNext() { 
		pauseAuto = setSeconds;
		moveNext();				
		return false;							
	}
	
	function slBack() { 
		pauseAuto = setSeconds;
		moveBack();				
		return false;							
	}
	
	function moveNext() { 
		$("#slideshow li:eq(" + currentSlide + ")").fadeOut(fadeSpeed);
		if (currentSlide == 0) { currentSlide = (totalSlides - 1); } else { currentSlide--; }
		$("#slideshow li:eq(" + currentSlide + ")").fadeIn(fadeSpeed);		
	}
	
	function moveBack() { 
		$("#slideshow li:eq(" + currentSlide + ")").fadeOut(fadeSpeed);
		if (currentSlide == (totalSlides - 1)) { currentSlide = 0; } else { currentSlide++; }
		$("#slideshow li:eq(" + currentSlide + ")").fadeIn(fadeSpeed);	
	}		

});		

