jQuery(function($){
	"use strict";
	jQuery('.main-menu-navigation > ul').superfish({
		delay:       500,
		animation:   {opacity:'show',height:'show'},  
		speed:       'fast'
	});
});

function storefront_ecommerce_menu_open() {
	jQuery(".menu-brand.primary-nav").addClass('show');
}
function storefront_ecommerce_menu_close() {
	jQuery(".menu-brand.primary-nav").removeClass('show');
}

var storefront_ecommerce_Keyboard_loop = function (elem) {
    var storefront_ecommerce_tabbable = elem.find('select, input, textarea, button, a').filter(':visible');

    var storefront_ecommerce_firstTabbable = storefront_ecommerce_tabbable.first();
    var storefront_ecommerce_lastTabbable = storefront_ecommerce_tabbable.last();

    /*redirect last tab to first input*/
    storefront_ecommerce_lastTabbable.on('keydown', function (e) {
        if ((e.which === 9 && !e.shiftKey)) {
            e.preventDefault();
            storefront_ecommerce_firstTabbable.focus();
        }
    });

    /*redirect first shift+tab to last input*/
    storefront_ecommerce_firstTabbable.on('keydown', function (e) {
        if ((e.which === 9 && e.shiftKey)) {
            e.preventDefault();
            storefront_ecommerce_lastTabbable.focus();
        }
    });

    /* allow escape key to close insiders div */
    elem.on('keyup', function (e) {
        if (e.keyCode === 27) {
            elem.hide();
        }
        ;
    });
};

// scroll
jQuery(document).ready(function () {
	jQuery(window).scroll(function () {
	    if (jQuery(this).scrollTop() > 0) {
	        jQuery('#scrollbutton').fadeIn();
	    } else {
	        jQuery('#scrollbutton').fadeOut();
	    }
	});
	jQuery(window).on("scroll", function () {
	   document.getElementById("scrollbutton").style.display = "block";
	});
	jQuery('#scrollbutton').click(function () {
	    jQuery("html, body").animate({
	        scrollTop: 0
	    }, 600);
	    return false;
	});
});

jQuery(function($){
	$('.mobiletoggle').click(function () {
        storefront_ecommerce_Keyboard_loop($('.menu-brand.primary-nav'));
    });
});

// preloader
jQuery(function($){
    setTimeout(function(){
        $(".frame").delay(1000).fadeOut("slow");
    });
});

// sticky header
(function( $ ) {

    $(window).scroll(function(){
        var sticky = $('.sticky-header'),
        scroll = $(window).scrollTop();

        if (scroll >= 100) sticky.addClass('fixed-header');
        else sticky.removeClass('fixed-header');
    });

})( jQuery );

// sticky copyright
(function ($) {
    $(window).on('scroll', function () {
        var scroll = $(window).scrollTop();
        var sticky = $('.sticky-copyright');

        if (sticky.length) {
            if (scroll >= 100) {
                sticky.addClass('fixed-copyright');
            } else {
                sticky.removeClass('fixed-copyright');
            }
        }
    });
})(jQuery);

/* Progress Bar */
document.addEventListener("DOMContentLoaded", function () {
    const storefront_ecommerce_progressBar =
        document.getElementById("storefront_ecommerce_elemento_progress_bar");
    if (!storefront_ecommerce_progressBar) return;
    window.addEventListener("scroll", function () {
        const storefront_ecommerce_scrollTop =
            document.documentElement.scrollTop || document.body.scrollTop;
        const storefront_ecommerce_height =
            document.documentElement.scrollHeight -
            document.documentElement.clientHeight;
        const storefront_ecommerce_scrolled =
            (storefront_ecommerce_scrollTop / storefront_ecommerce_height) * 100;
        storefront_ecommerce_progressBar.style.width =
            storefront_ecommerce_scrolled + "%";
    });
});
