function Slideshow () 
{
	
	var slideshow = null;
	var images = [];
	var numSlides = 0;
	var actIndex = 0;
	var slideWidth = 0;
	
	
	this.init = function (divSlideshow, divImagesArray)
	{
		slideshow = divSlideshow;
		images = divImagesArray;
		numSlides = $("div.slide", slideshow).length;
		slideWidth = $(slideshow).width() + 40;
		
		$("li.back a", slideshow).click(backward);
		$("li.forward a", slideshow).click(forward);
	};
	
	function backward ()
	{
		actIndex--;
		if (actIndex < 0) 
			actIndex = numSlides - 1;
		animate();
	};
	
	function forward ()
	{
		actIndex++;
		if (actIndex > (numSlides - 1)) 
			actIndex = 0;
		animate();
	};
	
	function animate ()
	{
		var targetMLeft = -(actIndex * slideWidth);
		$(".slidesContainer", slideshow).animate({ "margin-left": targetMLeft }, "slow");
		
		if (images.length == 0) 
			return;
		
		var maxZIndex = 0;
		for (var i = 0; i < images.length; i++) 
		{
			var imgs = $(images[i]).children();
			
			for (var j = 0; j < imgs.length; j++) 
			{
				if (parseInt($(imgs[j]).css("z-index")) > maxZIndex) 
					maxZIndex = parseInt($(imgs[j]).css("z-index"));
			}
			
			$(imgs[actIndex]).css("display", "none");
			$(imgs[actIndex]).css("z-index", maxZIndex + 1);
			$(imgs[actIndex]).fadeIn("slow");
		}
	};
}

