jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
jQuery(function( $ ){
	var $prev = $('#product-variants div.product-variants-arrow-left'),//prev button
		$next = $('#product-variants div.product-variants-arrow-right');//next button
	$('#slideshow').serialScroll({
		items:'li',
		prev:'#product-variants div.product-variants-arrow-left',
		next:'#product-variants div.product-variants-arrow-right',
		offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		step:4, //how many elements to scroll on each action
		exclude:4, //exclude the last x elements, so we cannot scroll past the end
		duration:1200,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: true, //click on the images to scroll to them
		onBefore:function( e, elem, $pane, $items, pos ){
			$prev.add($next).show();
			if (pos == 0) {
				$prev.css("opacity", "0");
				$prev.css("filter", "alpha(opacity=0)");
				if ($items.length > 5) {//più di una pagina
					$next.css("opacity", "1");
					$next.css("filter", "alpha(opacity=100)");
				}
			}
			else {
				$prev.css("opacity", "1");
				$prev.css("filter", "alpha(opacity=100)");
				if (pos >= $items.length - 5) {//1+exclude!
					$next.css("opacity", "0");
					$next.css("filter", "alpha(opacity=0)");
				}
				else {
					$next.css("opacity", "1");
					$next.css("filter", "alpha(opacity=100)");
				}
			}
		}
	});
});