var timer = new Array();

$(document).ready(function() {
	if ($("div#Slideshow").length) {
		$("div#Slideshow").each(function() {
			$("div.Slide:first", $(this)).show();
			timer[$(this).attr('id')] = setTimeout("showNextImage('" + $(this).attr('id') + "');", 10000);
		});
	}

	$("div.Menu div").click(function() {
		var slider = $("#Slideshow");
		clearTimeout(timer[slider.attr("id")]);
		$("div.Slide:visible", slider).fadeOut(500);
		$("div.Slide:eq(" + $("div.Menu div").index(this) + ")", slider).fadeIn(500);
		timer[slider.attr("id")] = setTimeout("showNextImage('" + slider.attr('id') + "')", 10000);
	});
});

function showNextImage(slideshowId) {
	$("div.Slide:visible", $("div#Slideshow#" + slideshowId)).fadeOut(500);
	
	if ($("div.Slide:visible", $("div#Slideshow#" + slideshowId)).next("div.Slide").length) {
		$("div.Slide:visible", $("div#Slideshow#" + slideshowId)).next().fadeIn(500);
	} else {
		$("div.Slide:first", $("div#Slideshow#" + slideshowId)).fadeIn(500);
	}
	timer[slideshowId] = setTimeout("showNextImage('" + slideshowId + "');", 10000);
}

