// slide horyzontalny
$.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(document).ready(function($){		
	$('#slideshow .imgDescription:not(:first)').hide().children().fadeOut();
	$('#slideshow .imgDescription:first').animate({width:"250px"}, 200).addClass('open');

	$('#slideshow li').click(function(){
		var current = $(this);
		if(current.find('.open').length === 0){
			current.parent().find('.open').removeClass('open').hide(200).children().fadeOut();
			current.find('.imgDescription').animate({width:"250px"}, 200,
			function(){
				var $this = $(this);
				$this.children().fadeIn("slow");
				$this.addClass("open");
			}
		);
	};
});

$('#slideshow').serialScroll({
	items:'li',
	prev:'#foto-scroll a.prev',
	next:'#foto-scroll a.next',
	axis:'x',
	offset:0, //when scrolling to photo, stop 10 before reaching it (from the left)
	start:0, //as we are centering it, start at the 2nd
	duration:1200,
	force:true,
	stop:true,
	lock:true,
	cycle:false, //don't pull back once you reach the end
	easing:'easeOutQuart', //use this easing equation for a funny effect
	jump: false, //click on the images to scroll to them
	onBefore:function(){
		var o =	$('#slideshow').find("li:last div").offset();
		var koniec = $('#slideshow').find("li:last div").width() + o.left;
		var s = $('#slideshow').width();
		var so = $('#slideshow').offset();
		//alert(s + " offset:"  + o.left + "\nslide offset" + so.left + "\no-so=" + (o.left - so.left) + "\n#slideshow width: " + s)
		

		var stopposition;
		stopposition = koniec - so.left;
//console.log("offset.left:"  + o.left + "\nslide offset: " + so.left + "\n o-so.left=" + (o.left - so.left) + "\n#slideshow width: " + s + "\n koniec: " + koniec + "\nstopposition: " + stopposition);

		if((stopposition >= s) || $(this).hasClass('prev'))
			{
				return true;
			}
		else
			{
				return false;
			}
		}
	});
});