
	jQuery(window).load(function() {
		var $ = jQuery,
			slideDuration = 8000,
			fadeDuration = 2000;
		
		
		$("ul.image-animation").each(function() {
			
			var viewport = {
				width: $(this).width(),
				height: $(this).height()
			}
			
			var images = $("li", this),
				currentIndex = images.length-1;
				
			function fadeImage(currentImage) {
				
				var startAt = currentIndex % 2 ? 0 : -100,
					stopAt = currentIndex % 2 ? -100 : 0;
				
				
				
				
				currentImage.show()/*.css("top", startAt).animate({top:stopAt}, {queue:false, duration: slideDuration, easing: "linear"})*/;
				window.setTimeout(function() {
					/*currentIndex = currentIndex > 0 ? currentIndex-1 : images.length-1;*/
					currentIndex = Math.floor(Math.random() * (images.length - 1));
					var nextImage = $(images.get(currentIndex));
					// primitivní způsob, jak zajistit, aby se v prolínačce fotky neopakovaly (resp. aby se toto riziko snížilo na minimum) :)
					if(nextImage === currentImage)
					{
					    newIndex = Math.floor(Math.random() * (images.length-1));
					    var nextImage = $(images.get(newIndex));
          }    
					if(nextImage === currentImage)
					{
					    newIndex = Math.floor(Math.random() * (images.length-1));
					    var nextImage = $(images.get(newIndex));
          }  
					
					if (currentIndex == images.length-1) {
						nextImage.fadeIn(fadeDuration);
					}
					else {
						currentImage.fadeOut(fadeDuration);
					}
					
					fadeImage(nextImage);
				}, slideDuration-fadeDuration);
			}
			
			fadeImage($(images.get(currentIndex)));
			
		});
		
	});
