/* Secondary Header Scripts */
/* -------------------------------------------------------------------- */

var secondary_header_offset;

function mk_secondary_header_res() {
    if ($.exists('.mk-secondary-header')) {
        secondary_header_offset = $('.mk-secondary-header').offset().top; // switched from position(). We need val relative to document.
        // console.log(secondary_header_offset);
    }
}

function secondary_header() {
    var $this = $('.mk-secondary-header');
    if ($this.length) {

        var mk_header = 0; 

        if ($.exists("#mk-header.sticky-header")) {
            mk_header = parseInt($("#mk-header.sticky-header").attr('data-sticky-height'));
        }
        if ($.exists(".mk-header-toolbar") && $.exists('#mk-header.sticky-header')) {
            mk_header += 35;
        }

        if(!$('.mk-secondary-header').parent().hasClass('theme-main-header')) {
            var dsitance_from_top = secondary_header_offset - mk_header - global_admin_bar_height;

            var animationSet = function() {
                if (scrollY > dsitance_from_top) {
                    $this.addClass('secondary-header-sticky').css('top', (mk_header + global_admin_bar_height));
                    $('.secondary-header-space').addClass('secondary-space-sticky');
                } else {
                    $this.removeClass('secondary-header-sticky').css('top', 'auto');
                    $('.secondary-header-space').removeClass('secondary-space-sticky');
                }
            }
            debouncedScrollAnimations.add(animationSet);
        }
    }
}
