/* Minification failed. Returning unminified contents.
(37,17-18): run-time error JS1195: Expected expression: )
(37,20-21): run-time error JS1195: Expected expression: >
(45,6-7): run-time error JS1195: Expected expression: ,
 */
if (jQuery) {
    var originalFn = $.fn.data;
    $.fn.data = function () {
        if (arguments[0] !== '$binding')
            return originalFn.apply(this, arguments);
    }
}

function scrollToCategory(parentCatId, catId) {
    var headerHeight = $('#sticky-menu').height();
    var productNavHeight = $('.products-nav-container').height();
    var offset = headerHeight + productNavHeight;
    var $el = $('#cat_' + catId);
    var top = $el.offset().top - offset;
    $('.category-submenu').height(0).focus();
    $('html,body').animate({ scrollTop: top }, 1800);
}


function focusOnIput(ev, id) {
    var $el = $(id);
    // create invisible dummy input to receive the focus first
    const fakeInput = document.createElement('input')
    fakeInput.setAttribute('type', 'text')
    fakeInput.style.position = 'absolute'
    fakeInput.style.opacity = 0
    fakeInput.style.height = 0
    fakeInput.style.fontSize = '16px' // disable auto zoom

    // you may need to append to another element depending on the browser's auto 
    // zoom/scroll behavior
    document.body.prepend(fakeInput)

    // focus so that subsequent async focus will work
    fakeInput.focus()

    setTimeout(() => {

        // now we can focus on the target input
        $el.focus()

        // cleanup
        fakeInput.remove()

    }, 100);
}
(function ($) {
    $(document).ready(function () {
        $(".carousel-inner").swipe({
            //Generic swipe handler for all directions
            swipeRight: function (event, direction, distance, duration, fingerCount) {
                $(this).parent().carousel('prev');
            },
            swipeLeft: function () {
                $(this).parent().carousel('next');
            },
            //Default is 75px, set to 0 for demo so any distance triggers swipe
            threshold: 0
        });

        headerMenu.initialize();

        $(".form").validate({
            errorClass: 'customErrorClass',
        });

        feedback.ratingTouchListener();
        validation.extendEmail();
        validation.extendZipCode();
        validation.extendPhone();
        scrollTop.initialize();

        $('.html-content').attr("contenteditable", false);
    });
})(jQuery);

var feedback = {
    ratingTouchListener: function () {
        $('.rating label').bind("touchstart", function (e) { });
    }
}

var headerMenu = {
    initialize: function () {
        $('.link-wrapper').hover(function () {
            //mouse in
            var $el = $(this);
            clearTimeout($el.data('timeout'));
            $('.subnav').removeClass('active');
            $('.active-link').removeClass('active-link');
            $el.addClass('active-link');
            $el.children('.subnav').addClass('active');

        }, function (delay) {
            var $el = $(this);
            var delay = 500;

            var t = setTimeout(function () {
                //mouse out
                $el.removeClass('active-link');
                $el.children('.subnav').removeClass('active');
            }, delay);

            $el.data('timeout', t);
        });
    }
}

var validation = {
    extendEmail: function () {
        $.validator.methods.email = function (value, element) {
            var email = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            return email.test(value);
        }
    },
    extendZipCode: function () {
        jQuery.validator.addMethod('zipcode', function (value, element) {
            return this.optional(element) || !!value.trim().match(/^\d{5}(?:[-\s]\d{4})?$/);
        }, 'Invalid zip code');
    },
    extendPhone: function () {
        jQuery.validator.addMethod("phone-us", function (phone_number, element) {
            phone_number = phone_number.replace(/\s+/g, "");
            return this.optional(element) || phone_number.length > 9 &&
                phone_number.match(/^(\+?1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
        }, "Please enter a valid phone number");
    }
}

$(document).bind("touchstart", function (e) {
    if ($(e.target).closest("#dropdown-cart").length === 0) {
        $('#dropdown-cart').addClass('ng-hide');
    }
});

var scrollTop = {
    initialize: function () {
        $(window).scroll(function () {
            //$(this).scrollTop() > 200 && $(window).width() < 1100 ? $(".go-top").fadeIn(200) : $(".go-top").fadeOut(200)
            $(this).scrollTop() > 200 ? $(".go-top").fadeIn(200) : $(".go-top").fadeOut(200)
        });

        $(".go-top").click(function (n) {
            n.preventDefault();
            $("html, body").animate({ scrollTop: 0 }, 300)
        });
    }
};

(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

;
