var slideshowPref =
{
	timeout: 3000
};

$(

	function()
	{
		
		// ukrycie wszystkich zdjęć prócz pierwszego w drzewie html
		$(".image-slideshow .slide:not(:first-child)").hide();

		// ustawienie szerokości zdjęcia i wysokości ramki względem pierwszego
		// zdjęcia w drzewie html, czekanie na wczytanie obrazka, dalej wszystkie
		// operacje
		$(window).load
		(
			function()
			{

				// inicjalizacja linkowania po kliknięciu na cały obraz
				$(".image-slideshow .slide img").each
				(
					function()
					{
						if ($(this).siblings("a").length > 0)
						{
							$(this)
							.css({"cursor":"pointer"})
							.click(function(){ window.location = $(this).siblings("a").attr("href"); });

							$(this).parents(".image-slideshow").find(".description")
							.css({"cursor":"pointer"})
							.click(function(){ window.location = $(this).siblings("a").attr("href"); });
						}
					}
				);

				$(".image-slideshow .slide:first-child").each
				(
					function()
					{
						var minHeight = $(this).height();

						// wyszukiwanie najmniejszej wysokości zdjęcia
						$(this).siblings('.slide').each
						(
							function()
							{
								var currentHeight = $(this).height();
								
								if (currentHeight < minHeight)
									minHeight = currentHeight;
							}
						);

						// ustawienie wysokości kontenera na najniższe zdjęcie
						$(this).parent().height(minHeight).children(".slide").height(minHeight);
						

						if ($(this).siblings(".slide").length > 0)
							setTimeout(timeoutCallback, slideshowPref.timeout, this);
					}
				);

			}
		);

	}

);

function timeoutCallback(sender)
{

	$(sender).fadeOut("slow");

	var next = $(sender).next(".slide");

	if ($(next).length == 0)
	{
		next = $(sender).siblings(".slide").first();
	}

	$(next).fadeIn("slow", function() {setTimeout(timeoutCallback, slideshowPref.timeout, next);});

}



