(function(a){
    a.fn.lavaLamp=function(c){
        c=a.extend({
            fx:"swing",
            speed:500,
            click:function(){
                return true
                },
            startItem:"no",
            autoReturn:true,
            returnDelay:0,
            setOnClick:true,
            homeTop:0,
            homeLeft:0,
            homeWidth:0,
            homeHeight:0,
            returnHome:false
        },c||{});
        var b;
        if(c.homeTop||c.homeLeft){
            b=a('<li class="homeLava selectedLava"></li>').css({
                left:c.homeLeft,
                top:c.homeTop,
                width:c.homeWidth,
                height:c.homeHeight,
                position:"absolute"
            });
            a(this).prepend(b)
            }
            return this.each(function(){
            var h=location.pathname+location.search+location.hash;
            var f=new Object;
            var e;
            var i;
            var g;
            var j=a("li[class!=noLava]",this);
            if(c.startItem=="no"){
                f=a('li a[href$="'+h+'"]',this).parent("li")
                }
                if(f.length==0&&c.startItem=="no"){
                f=a('li a[href$="'+location.pathname.substring(location.pathname.lastIndexOf("/")+1)+location.search+location.hash+'"]',this).parent("li")
                }
                if(f.length==0||c.startItem!="no"){
                if(c.startItem=="no"){
                    c.startItem=0
                    }
                    f=a(j[c.startItem])
                }
                g=a("li.selectedLava",this)[0]||a(f).addClass("selectedLava")[0];
            j.mouseenter(function(){
                if(a(this).hasClass("homeLava")){
                    g=a(this)[0]
                    }
                    d(this)
                });
            i=a('<li class="backLava"><div class="leftLava"></div><div class="bottomLava"></div><div class="cornerLava"></div></li>').appendTo(this);
            a(this).mouseleave(function(){
                if(c.autoReturn){
                    if(c.returnHome&&b){
                        d(b[0])
                        }else{
                        if(c.returnDelay){
                            if(e){
                                clearTimeout(e)
                                }
                                e=setTimeout(function(){
                                d(null)
                                },c.returnDelay+c.speed)
                            }else{
                            d(null)
                            }
                        }
                }
            });
    j.click(function(k){
        if(c.setOnClick){
            a(g).removeClass("selectedLava");
            a(this).addClass("selectedLava");
            g=this
            }
            return c.click.apply(this,[k,this])
        });
    if(c.homeTop||c.homeLeft){
        i.css({
            left:c.homeLeft,
            top:c.homeTop,
            width:c.homeWidth
            //height:c.homeHeight
            })
        }else{
        i.css({
            left:g.offsetLeft,
            top:g.offsetTop,
            width:g.offsetWidth
            //height:g.offsetHeight
            })
        }
        function d(k){
        if(!k){
            k=g
            }
            var m=0,l=0;
        if(!a.browser.msie){
            m=(i.outerWidth()-i.innerWidth())/2;
            l=(i.outerHeight()-i.innerHeight())/2
            }
            i.stop().animate({
            left:k.offsetLeft-m,
            top:k.offsetTop-l,
            width:k.offsetWidth
            //height:k.offsetHeight
            },c.speed,c.fx)
        }
    })
}
})(jQuery);
