(function($) {
$.fn.menuLamp = function(o) {
    //для каждого выбранного элемента (применяется только к таблицам)
    return this.each(function() {

        var me = $(this);        //таблица меню
        var noop = function(){}; //пустая функция

        $lamp = $('<div class="menu-lamp"><div class="menu-lamp-left"></div></div>').hide();
        $(me).parent().append($lamp);

        $a = $("a", this);
        curr = ($("a.current", this).size() > 0) ? $("a.current", this)[0]: null;

        $a.hover(function() {
            move(this);
        }, noop);

        $(this).hover(noop, function() {
            move(curr);
        });

        setCurr(curr);
        move(curr);

        function setCurr(el) {
            if(el != null) {
                $lamp.css("left",getOffsetLeft(el)+"px")
                     .css("width",el.offsetWidth+"px")
                     .css("top",getOffsetTop(el)+"px");
            }
            curr = el;
        };

        function getOffsetLeft(el) {
            var offsetLeft = el.offsetLeft;
            if(el.offsetParent != null) {
                offsetLeft += getOffsetLeft(el.offsetParent);
            }
            return offsetLeft;
        }

        function getOffsetTop(el) {
            var offsetTop = el.offsetTop;
            if(el.offsetParent != null) {
                offsetTop += getOffsetTop(el.offsetParent);
            }
            return offsetTop;
        }

        function move(el) {
          
            $("a",me).css('color', '#5C6463').css('fontSize', '16px');

            if(el != null) {
                $(el).css('color', '#ffffff').css('fontSize', '18px');

                $lamp.show();

                $lamp.each(function() {
                    $(this).stop();}
                ).animate({
                    width: el.offsetWidth,
                    left: getOffsetLeft(el),
                    top: getOffsetTop(el)+4,
                    height: 30
                }, 500,"backout");
            }
            else {
                $lamp.each(function() {
                    $(this).stop();}
                ).hide();
            }

        };

    });
};
})(jQuery);
