// slide horyzontalny
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(document).ready(function(jQuery){		
	jQuery('#slideshow .imgDescription:not(:first)').hide().children().fadeOut();
	jQuery('#slideshow .imgDescription:first').animate({width:"250px"}, 200).addClass('open');

	jQuery('#slideshow li').click(function(){
		var current = jQuery(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 thisThis = jQuery(this);
				thisThis.children().fadeIn("slow");
				thisThis.addClass("open");
			}
		);
	};
});

jQuery('#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 =	jQuery('#slideshow').find("li:last img").offset();
		var s = jQuery('#slideshow').width();
		var so = jQuery('#slideshow').offset();
		//alert(s + " offset:"  + o.left + " slide offset" + so.left + " o-so=" + (o.left - so.left))

		var stopposition;
		stopposition = o.left - so.left + 100;

		if((stopposition >= s) || jQuery(this).hasClass('prev'))
			{
				return true;
			}
		else
			{
				return false;
			}
		}
	});
});