(function($) {
$.fn.lavaLamp = function(o) {
    
    o = $.extend({ fx: "linear", speed: 300, click: function(){} }, o || {});

    return this.each(function() {
        var me = $(this), 
            noop = function(){}, 
            $back = $('#slideBG'),            
            $li = $("li", this), 
            curr = $("li.selected", this)[0];

        $li.hover(function() {
            move(this);
        }, noop);

        $(this).hover(noop, function() {
            move(curr);
        });

        $li.click(function(e) {
            setCurr(this);
            return true;
        });

        setCurr(curr);

        function setCurr(el) {  
            if(el)   
            {        
                $back.css({ "left": el.offsetLeft+190+"px", "width": el.offsetWidth+"px" });    // Added delta for correct left offset
                $back.show();
            }
            else
            {
                $back.css({ "left": "0px", "width": "0px" });
                $back.hide();
            }
            curr = el;
        };

        function move(el) {
            $back.each(function() {
                $(this).dequeue(); }
            ).stop().animate({
                width: el ? el.offsetWidth : "0px",
                left: el ? el.offsetLeft+190 : "0px"    // Added delta for correct left offset
            }, (el) ? o.speed : 400, (el) ? o.fx : "linear", function(){
                if(!el) $back.hide();                   // Make sure to hide the silder if the no menu item is selected
            });      
        };

    });
};
})(jQuery);

