function fadeSlider(gallery) {

	var fadeDuration = "1000"; //fade duration in ms
	var fadeInterval = "8000"; //time between fades in ms
	var activeIndex = 0; //start index
	
	var slideItems = $(".slides", $(gallery)).children();
	var menuItems = $(".menu", $(gallery)).children();

	var slideCount = $(slideItems).length;

	function setActive(index, duration) {
		//we reset all slides, make current active slide visible again,
		//bring the new active slide to top and fade it in
		$(slideItems).css({"z-index": 10, "display": "none"});
		$(slideItems[activeIndex]).css("display","block");
 		$(slideItems[index]).css("z-index", 20).fadeIn(duration);

		$(menuItems).removeClass("active");
		$(menuItems[index]).addClass("active");

		activeIndex = index; //set new activeIndex
	}

	//advances to the next slide or resets to first slide
	//checks if advancing to the next would push us over the slide count
	function advance() {
		if (activeIndex + 1 >= slideCount) {
			setActive(0);
		} else {
			setActive(activeIndex + 1);
		}
	}

	//menu items are mapped to slides via index
	//the first menu item links to first slide etc
	$(menuItems).each(function (index) {
		$(this).click(function () {
			setActive(index, fadeDuration);

			//click resets the advance timer
			clearInterval(timer);
			timer = setInterval(advance, fadeInterval);
		});
	});

	var timer = setInterval(advance, fadeInterval);

	setActive(activeIndex, 0); //duration of 0 for instant display
}
