var nav_timer;

$(document).ready(function() {

    $(document).on({
        mouseenter: function() {
            if ((currScrSize == 'xl') || (currScrSize == 'lg')) {
                var _currElem = $(this);
                var _currObj = $(this).children('.item-wrapper').children('.menu-caret'),
                    _currSubMenu = $($(_currObj).data('target'));
                nav_timer = setTimeout(function() {


                    if ($(_currElem).not('.trigger')) {
                        $('[data-toggle="navmenu"][data-target="' + $(_currObj).data('target') + '"]').addClass('trigger');
                        $(_currElem).addClass('trigger');
                    }

                    $($(_currObj).data('target')).slideDown(300, function() {
                        $($(_currObj).data('target')).addClass('in');
                        $($(_currObj).data('target')).css('display', '');
                    });
                }, 100);
            }

        },
        mouseleave: function() {
            if ((currScrSize == 'xl') || (currScrSize == 'lg')) {
                clearTimeout(nav_timer);
                var _currObj = $(this).children('.item-wrapper').children('.menu-caret'),
                    _currSubMenu = $($(_currObj).data('target'));

                if ($(this).is('.trigger')) {
                    $('[data-toggle="navmenu"][data-target="' + $(_currObj).data('target') + '"]').removeClass('trigger');
                    $(this).removeClass('trigger');

                    $($(_currObj).data('target')).find('.nav-menu.in').each(function(index, element) {
                        $(this).removeClass('in');
                        $('[data-toggle="navmenu"][data-target="#' + $(this).attr('id') + '"]').removeClass('trigger');
                    });
                }
                $($(_currObj).data('target')).slideUp(300, function() {
                    $($(_currObj).data('target')).css('display', '');
                    $($(_currObj).data('target')).removeClass('in');
                });

            }
        }


    }, ".nav-block .nav-item, .nav-block .menu-item");

    $(document).on({
        click: function() {
            event.preventDefault();
            if ($(this).data('ser')) {
                var dataStr = 'infoNo=' + $(this).data('ser');
                $.ajax({
                    url: "/tpl/sub/modal_info.php",
                    type: 'post',
                    data: dataStr,
                    dataType: 'html',
                    success: function(responseHtml) {

                        $('#info-modal').find('.modal-inner').html(responseHtml);
                        $('#info-modal').modal('show');
                    },
                    error: function(request) {
                        console.log(request.responseText);
                    }
                });

            }

        }
    }, '.fnmodal, .modal-link');

    $("#gotop").click(function() {
        $("html,body").animate({
            scrollTop: 0
        }, 1000);
    });

    $(window).scroll(function() {
        if ($(this).scrollTop() > 300) {
            $('#gotop').fadeIn("fast");
        } else {
            $('#gotop').stop().fadeOut("fast");
        }

        if ($('.stay-visible').length) {
            $('.stay-visible').each(function(idx, elem) {
                $(elem).stayVisible();
            });
        }
    });


    $('.wdg-contact-wrap .wdg-switch').on('click', function() {
        if ($('.wdg-contact-wrap').is('.show')) {
            $('.wdg-contact-wrap').removeClass('show');
            $(this).children('img').attr('src', '/images/icons/icon_more.svg?1');
        } else {
            $('.wdg-contact-wrap').addClass('show');
            $(this).children('img').attr('src', '/images/icons/icon_x.svg');
        }

    });

    setTimeout(function() {
        $('.wdg-contact-wrap .wdg-switch').addClass('jump');
    }, 3000);



}); //document.ready



function setCookie(key, value, minutes) {
    var expires = new Date();
    expires.setTime(expires.getTime() + (minutes * 60 * 1000));
    document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/';
}

function getCookie(key) {
    var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
    return keyValue ? keyValue[2] : null;
}

function delCookie(name) {
    createCookie(name, "", -1);
}