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-optical-variants-arrow-up'), //prev button
		$next = $('#product-variants div.product-optical-variants-arrow-down'); //next button
    $('#slideshow3x3').serialScroll({
        items: 'li',
        prev: '#product-variants div.product-optical-variants-arrow-up',
        next: '#product-variants div.product-optical-variants-arrow-down',
        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: 6, //how many elements to scroll on each action
        exclude: 0, //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: false, //click on the images to scroll to them
        onBefore: function(e, elem, $pane, $items, pos) {
            $prev.add($next).show();
//            alert(pos + '-len:' + $items.length); 
            if ($items.length < 10) {
                $prev.css("opacity", "0");
                $prev.css("filter", "alpha(opacity=0)");
                $next.css("opacity", "0");
                $next.css("filter", "alpha(opacity=0)");
            }
            else
                if (pos < 3) {
                    $prev.css("opacity", "0");
                    $prev.css("filter", "alpha(opacity=0)");
                    if ($items.length < 10) {//più di una pagina
                        $next.css("opacity", "0");
                        $next.css("filter", "alpha(opacity=0)");
                    }
                    else {
                        $next.css("opacity", "1");
                        $next.css("filter", "alpha(opacity=100)");
                    }
                }
                else {
                    $prev.css("opacity", "1");
                    $prev.css("filter", "alpha(opacity=100)");
                    if ($items.length - pos > 2) {//1+exclude!
                        $next.css("opacity", "0");
                        $next.css("filter", "alpha(opacity=0)");
                    }
                    else {
                        $next.css("opacity", "1");
                        $next.css("filter", "alpha(opacity=100)");
                    }
            }
        }
    });
});