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

