(function($, Lego) {

    Lego.block['b-wc-status'] = function() {
        var $this = $(this);

        var $wcToggle = $this.find(".c-toggle"), $wcPopup = $this.find('.b-wc-status__popup');

        toggle();

        $wcToggle.click(function() {
            $this.toggleClass("b-wc-status_off");
            toggle();
            return false;
        });

        $this.mouseenter(function() {
            $this.addClass("b-wc-status__hover");
        });

        $wcPopup.mouseenter(function() {
            window.clearTimeout($this.data("timeout"));
        });

        $wcPopup.mouseleave(function() {
            $this.data("timeout", window.setTimeout(function() {
                $this.removeClass("b-wc-status__hover");
            }, 1000));
        });

        function toggle() {
            $wcToggle.html($this.hasClass("b-wc-status_off") ? "Включить" : "Выключить");
        }
    };

})(jQuery, window.Lego);
