/**
 * @Project NUKEVIET 4.x
 * @Author VINADES.,JSC <contact@vinades.vn>
 * @Copyright (C) 2014 VINADES.,JSC. All rights reserved
 * @License GNU/GPL version 2 or any later version
 * @Createdate 31/05/2010, 00:36
 */

$(document).ready(function() {
    function isScreenMd() {
        return $('#isScreenMd').is(':visible');
    }

    var stickyHeaderHeight = 96;
    var timercheckMenuSticky;

    function checkMenuSticky() {
        if ($(window).scrollTop() > stickyHeaderHeight && isScreenMd()) {
            $("body").addClass("sticky-menu");
        } else {
            $("body").removeClass("sticky-menu");
        }
    }

    $(window).on('resize', function() {
        if (timercheckMenuSticky) {
            clearTimeout(timercheckMenuSticky);
        }
        timercheckMenuSticky = setTimeout(function() {
            checkMenuSticky();
        }, 100);
    });

    $(window).on('scroll', function() {
        checkMenuSticky();
    });

    // Điều kiển menu mobile
    $('[data-toggle="toggleMenuMobile"]').on('click', function(e) {
        e.preventDefault();
        $("body").toggleClass('mobile-nav-open');
    });

    $('.mobile-nav-bg').on('click', function(e) {
        e.preventDefault();
        $("body").removeClass('mobile-nav-open');
    });
});

$(document).ready(function() {
    // Tự động reponsive bảng ở tin tức
    $('#news-bodyhtml table').each(function() {
        if (!$(this).parent().is('.table-responsive') && $(this).find('tr').first().find('td').length >= 2 ) {
            $(this).wrap('<div class="table-responsive table-responsive-all"></div>');
        }
    });

    // Tự động reponsive bảng ở page
    $('#page-bodyhtml table').each(function() {
        if (!$(this).parent().is('.table-responsive') && $(this).find('tr').first().find('td').length >= 2 ) {
            $(this).wrap('<div class="table-responsive table-responsive-all"></div>');
        }
    });
});