/* Header Section Sticky function */
/* -------------------------------------------------------------------- */


function sticky_header() {
    var $mk_header = $('#mk-header').first();
    if ($mk_header.hasClass('sticky-header') && global_window_width > mk_nav_res_width) {

            var header_structure = $mk_header.attr('data-header-structure');

            if(header_structure == 'vertical') {
                var mk_header_height = 100;
            } else {
                var mk_header_height = parseInt((mk_header_padding * 2) + mk_logo_height) + 30;
            }


        var chopScrollAnimation = function() {
            if (global_window_width > mk_nav_res_width) {
                if (scrollY > mk_header_height) {
                    $mk_header.addClass('sticky-trigger-header');
                } else {
                    $mk_header.removeClass('sticky-trigger-header');
                }
            }
            // setTimeout(function() {
            //     mk_main_navigation();
            // }, 200);
        }
        debouncedScrollAnimations.add(chopScrollAnimation);
    }

}



function transparent_header_sticky() {
    var $mk_header = $('#mk-header');
    if ($mk_header.hasClass('transparent-header') && $mk_header.hasClass('sticky-header') && global_window_width > mk_nav_res_width) {


        var trigger = false;

        var chopScrollAnimation = function() {
            var edge_active = $('.mk-edge-slider.first-el-true').find('.swiper-slide-active').attr('data-header-skin'),
                header_structure = $mk_header.attr('data-header-structure');
                if(header_structure == 'vertical') {
                    var mk_header_height = 100;
                } else {
                    var mk_header_height = parseInt((mk_header_padding * 2) + mk_logo_height) + 30;
                }

            mk_header_trans_offset = (mk_header_trans_offset == 0) ? global_window_height : mk_header_trans_offset;

                if (global_window_width > mk_nav_res_width) {
                    if (scrollY > mk_header_height || trigger) {
                        $mk_header.addClass('header-offset-passed');
                    } else {
                        $mk_header.removeClass('header-offset-passed');
                    }

                    if (scrollY > mk_header_trans_offset  || trigger) {
                        $mk_header.addClass('transparent-header-sticky sticky-trigger-header').removeClass('light-header-skin dark-header-skin');

                    } else {
                        if (edge_active != '' && typeof edge_active !== 'undefined') {
                            $mk_header.removeClass('transparent-header-sticky sticky-trigger-header').addClass(edge_active + '-header-skin');
                        } else {
                            $mk_header.removeClass('transparent-header-sticky sticky-trigger-header').addClass($mk_header.attr('data-transparent-skin') + '-header-skin');
                        }
                    }
                }

                // setTimeout(function() {
                //     mk_main_navigation();
                // }, 200);
        }
        debouncedScrollAnimations.add(chopScrollAnimation);

        $('body').on('page_intro', function() { 
            setTimeout(function() {
                trigger = true;
                chopScrollAnimation();
            }, 1000);
        });
        $('body').on('page_outro', function() { 
            setTimeout(function() {
                trigger = false;
                chopScrollAnimation();
            }, 500);
        });

    }

}