$(document).ready(function() {

    $(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);


    $(window).trigger('resize');


}); //document.ready



function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

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