(function($) {
    $(function() {
        var jcarousel = $('.jcarousel').jcarousel({

      });
        var total_items = jcarousel.find('li').length;

        
        jcarousel
            .on('jcarousel:reload jcarousel:create', function () {
                var carousel = $(this),
                    width = carousel.innerWidth();

            })
            .jcarousel({
                wrap: 'circular'
            });

        $('.jcarousel-control-prev')
            .on('jcarouselcontrol:active', function() {
                $(this).removeClass('inactive');
            })
            .on('jcarouselcontrol:inactive', function() {
                $(this).addClass('inactive');

            })
            .jcarouselControl({
                target: '-=1'
            });

        $('.jcarousel-control-next')
            .on('jcarouselcontrol:active', function() {
                $(this).removeClass('inactive');
            })
            .on('jcarouselcontrol:inactive', function() {
                $(this).addClass('inactive');
            })
            .jcarouselControl({
                target: '+=1'
            });
        
        
        $(".jcarousel").swipe({
            swipeLeft: function (event, direction, distance, duration, fingerCount) {
               $('.jcarousel-control-next').trigger('click');
            },
            swipeRight: function (event, direction, distance, duration, fingerCount) {
               $('.jcarousel-control-prev').trigger('click');
               
            },
            //Default is 75px+ set to 0 for demo so any distance triggers swipe
            threshold: 90,
            maxTimeThreshold:500,
            triggerOnTouchEnd:false,
            triggerOnTouchLeave:true,

        });

        
        $(".jcarousel").bind({
            hover: function() {
                $(this).removeClass("closedhand");
                $(this).addClass("openhand");
                $(".jcarousel").removeClass("closedhand");
                $(".jcarousel").addClass("pointer");
            },
            mousedown: function() { 
                $(this).removeClass("openhand");
                $(this).addClass("closedhand");
                $(".jcarousel").removeClass("openhand");
                $(".jcarousel").addClass("closedhand");
            },
            mouseup: function() { 
                $(this).removeClass("closedhand");
                $(this).addClass("openhand");
                $(".jcarousel").removeClass("closedhand");
                $(".jcarousel").addClass("pointer");
            }
        });

    });
})(jQuery);
