(function ($) {
$.fn.lavaLamp = function (o) {
o = $.extend({
fx: "linear",
speed: 500,
click: function () {}
}, o || {});
return this.each(function () {
var b = $(this),
noop = function () {}, $back = $('
').appendTo(b),
$li = $("li", this),
curr = $li.find('a.cr');
$li.not(".back").hover(function () {
move(this)
}, noop);
$(this).hover(noop, function () {
move(curr)
});
$li.click(function (e) {
setCurr(this);
return o.click.apply(this, [e, this]);
});
setCurr(curr.parent('li'));
function setCurr(a) {
if ( !a.length ) {
$back.css('left','-50px');
}
if ( a.length > 0 ) {
setTimeout ( function() {
$back.css({
"left": a.position().left + "px",
"width": a.outerWidth() + "px"
});
curr = a
},0);
}
}
function move(a) {
$back.each(function () {
$(this).dequeue();
}).animate({
width: a.offsetWidth,
left: a.offsetLeft
}, o.speed, o.fx);
}
})
}
})(jQuery);