(function ($) {
    $.fn.lavaLamp = function (o) {
        o = $.extend({
            fx: "linear",
            speed: 500,
            click: function () {},
            current: "current_page_item"
        },
        o || {});
        return this.each(function () {
            var me = $(this),
            noop = function () {},
            $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
            $li = $("li", this),
            curr = $("li.current_page_item", this)[0] || $("li.current_page_ancestor", this)[0] || $("li."+o.current, this)[0] || $li[0];
            
            $(curr).addClass('current_page_item');
            
            $li.not(".back").hover(
            	function () {
                    $(curr).removeClass('current_page_item');                    
                	move(this);
            	},
            	noop
            );
            
            $(this).hover(
            	noop, 
            	function () {
                	move(curr);
                    $(curr).addClass('current_page_item');                    
            	}
            );
            
            $li.click(function (e) {});
            setCurr(curr);
            
            function setCurr(el) {
                $back.css({
                    "left": el.offsetLeft + "px",
                    "width": el.offsetWidth + "px"
                });
                curr = el;
            };
            
            function move(el) {
                $back.each(function () {
                    $.dequeue(this, "fx");
                }).animate({
                    width: el.offsetWidth,
                    left: el.offsetLeft
                },
                o.speed, o.fx);
            };
        });
    };
})(jQuery);