var container = $(".menu-login-container");
            var mouse_is_inside = false;
            var menuButtonWrapperLogin = $(".menu-button-logged").closest('.menu-element');
            var containerTop = 0;
            var containerLeft = 0;

            function hideOverlay() {
                $('.overlay-bg').remove();
                $('.my-account-overlay-info-wrapper').hide();
                //$('#loginMenuButton').css({'z-index': '1'});
            }


            $(document).ready(function () {



                $('body').delegate('.my-account-close-overlay-x', 'click', function () {
                    hideOverlay();
                    return false;
                });

                $('body').delegate('.overlay-bg', 'click', function () {
                    hideOverlay();
                    return false;
                });


                $('body').delegate('.my-account-button', 'click', function () {

                    if ($('.overlay-bg').length === 0) {

                        var loginOffset = $('#loginMenuButton').offset();
                        var offsetTop = loginOffset.top + 45;
                        var offsetLeft = loginOffset.left - 180;

                        $('#loginMenuButton').css({'z-index': '101'});
                        $('body').append('<div class="overlay-bg"></div>');
                        $('.my-account-overlay-info-wrapper').show();
                        $('.my-account-overlay-info-wrapper').css({'top': offsetTop + 'px', 'left': offsetLeft + 'px'});
                        $('.overlay-bg').show();

                    }
                    return false;
                });


                $(document).delegate("body", "click", function (event) {
                    if (!$(event.target).parents('.menu-button-wrapper').length > 0) {
        if (!mouse_is_inside && $(".menu-login-container").css('display') === 'block') {
                            $(".menu-login-container").removeClass('show');
                            $(".menu-login-container").hide();
                        }
                    }
                });

                $(document).delegate(".menu-close-overlay-x", "click", function (event) {
                    hideOverlay();
                    event.stopPropagation();
   if ($(".menu-login-container").hasClass('show')) {
                        $(".menu-login-container").removeClass('show');
                        $(".menu-login-container").hide();
			$(".menu-button-logged .hamburger-container span").text('r');
                    }
                });
                $(document).delegate(".menu-button-logged", "click", function (event) {
                    hideOverlay();
                    event.stopPropagation();
                    if ($(".menu-login-container").hasClass('show')) {
                        $(".menu-login-container").removeClass('show');
                        $(".menu-login-container").hide();
                        $(".menu-button-logged .hamburger-container span").text('r');
                    } else {
                        $(".menu-button-logged .hamburger-container span").text('s');
                        showContainer();
                    }
                });

                $(document).delegate(".menu-login-container", "click", function (event) {
                    event.stopPropagation();
                });

  $(window).resize(function () {
                    if (typeof $(".menu-button-logged").closest('.menu-element').offset() !== "undefined") {
                        //showContainer();
                    }
                });

                container.hover(function () {
                    mouse_is_inside = true;
                }, function () {
                    mouse_is_inside = false;
                });


                function showContainer() {
                    hideOverlay();
    containerTop = $(".menu-button-logged").closest('.menu-element').position().top + $(".menu-button-logged").closest('.menu-element').height();
                    containerLeft = $(".menu-button-logged").closest('.menu-element').position().left;

                    $(".menu-login-container").addClass('show');
                    $(".menu-login-container").css({'top': containerTop, 'left': containerLeft});
                    $(".menu-login-container").show();

                }


                function closeNewMessageMenu() {

                    $('#loginMenuButton').apiAjax({
                        action: "showNewMessage",
                        params: {
                            name: "showNewMessage",
                            value: true,
                            domain: "",
                            type: 2
                        }
                    }, function (e) {
                        $("#loginMenuMessage").remove();
                        clearInterval(timer);
                        hideOverlay();
                        showContainer();
                        $('#loginMenuButton').unbind('click');

                    }, function (e) {
                        $("#loginMenuMessage").remove();
                        clearInterval(timer);
                        showContainer();
                        $('#loginMenuButton').unbind('click');
                    });

                    function blink() {
                        if (flag === 1) {
                            elm.css('display', 'block');
                        } else {
                            elm.css('display', 'none');
                        }
                        flag = 1 - flag;
                    }

                    var elm = $('#loginMenuMessage');
                    var flag = 0;
                    var timer = setInterval(blink, 1500);

                }
                if ($('#loginMenuMessage').length > 0) {
                    closeNewMessageMenu();
                }
            });

            $.fn.apiAjax = function (options, callbackSuccess, callbackError) {

                var settings = $.extend({
                    action: '',
                    params: {},
                    url: '/ajax_acl.php?ajax_acl=1'
                }, options);
                return this.each(function () {
                    var element = $(this);

                    $(element).click(function () {
                        $.ajax(
                                {
                                    url: settings.url + '&ajax_action=' + settings.action,
                                    type: 'post',
                                    data: settings.params,
                                    dataType: 'json',
                                    error: function (data) {
                                        if (typeof callbackError == 'function') { // make sure the callback is a function
                                            callbackError.call(this, data); // brings the scope to the callback
                                        }
                                    },
                                    success: function (data) {
                                        if (typeof callbackSuccess == 'function') { // make sure the callback is a function
                                            callbackSuccess.call(this, data); // brings the scope to the callback
                                        }
                                    }
                                }
                        );

                    });
                });
            };

var BookmarkModalCall = {
    opening: false,
    addBookmark: function (articleId, ob, offsetLeft) {
        if (!($('#bookmark-modal').css('display') == 'absolute') && !($('#bookmark-modal').css('display') == 'block') && !this.opening) {
            this.opening = true;
            var data = {
                'action': 'showModalWindow',
                'articleId': articleId,
                'offsetLeft': offsetLeft,
                'offsetTop': $(ob).position().top - $(window).scrollTop() - 50,
            }
            var date = new Date();

            $.ajax({
                url: '/ajax_zakladki.php?t=' + date.getTime(),
                type: 'POST',
                cache: false,
                data: data,
                success: function (zwrot) {
                    $('body').append(zwrot);
                },
                complete: function() {
                    BookmarkModalCall.opening = false;
                }
            });
        }
        return false;
    }

}

handleButtonClose();


function handleButtonClose(){

    let  clearTextInFieldButton = document.getElementById('clear-text-in-field-button');
    let searchFormPhraseInput = document.getElementById('fraza');
    let clearTextInFieldButtonContainer = document.getElementById('clear-text-in-field-button-container');

    if( (clearTextInFieldButton== null) || (searchFormPhraseInput== null) || (clearTextInFieldButtonContainer== null) ){
        return;
    }


    checkIfInputValueNotEmptyThenShowClearTextInFieldButton(clearTextInFieldButton, clearTextInFieldButtonContainer, searchFormPhraseInput);

    searchFormPhraseInput.addEventListener("input", function() {
        checkIfInputValueNotEmptyThenShowClearTextInFieldButton(clearTextInFieldButton, clearTextInFieldButtonContainer, this);
    });

    clearTextInFieldButton.addEventListener("click", function() {
        searchFormPhraseInput.value = '';
        this.style.display = 'none';
        clearTextInFieldButtonContainer.style.display = 'none';
    });

}

function checkIfInputValueNotEmptyThenShowClearTextInFieldButton(clearTextInFieldButton, clearTextInFieldButtonContainer, searchFormPhraseInput){

    if( searchFormPhraseInput.value.length>0 && (searchFormPhraseInput.value != 'wpisz szukane słowo lub frazę' ) ){

        clearTextInFieldButton.style.display = 'inline';
        clearTextInFieldButtonContainer.style.display = 'flex';

    }else{
        clearTextInFieldButton.style.display = 'none';
        clearTextInFieldButtonContainer.style.display = 'none';
    }

}