(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"><div class="left"></div></li>').appendTo(me),
            $li = $("li", this), curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
			
			if ($('li.current a').hasClass("home")) {
			$back.css("opacity",0);
			}

        $li.not(".back").hover(function() {
            move(this);
			$('.back').css("display","block");
        }, noop);

        $(this).hover(noop, function() {
									 
			
							 
			if ($('li.current a').hasClass("home")) {
			move_home(curr);
			}
			else {
            move(curr);	
			}
        });

        $('li:not(.current)', this).hover(function() {
			$('li.current a.novedades').css('background-position','-32px 0');
            $('li.current a.empresa').css('background-position','-138px 0');
			$('li.current a.productos').css('background-position','-245px 0');
			$('li.current a.fabricantes').css('background-position','-360px 0');
			$('li.current a.premios').css('background-position','-683px 0');
			$('li.current a.contacto').css('background-position','-580px 0');
			$('li.current a.manufactures').css('background-position','-360px 0');
			$('li.current a.galeria').css('background-position',' -478px 0');
        },
		
		function() {
			$('li.current a.novedades').css('background-position','-32px -29px');
            $('li.current a.empresa').css('background-position','-138px -29px');
			$('li.current a.productos').css('background-position','-245px -29px');
			$('li.current a.fabricantes').css('background-position','-360px -29px');
			$('li.current a.premios').css('background-position','-683px -29px');
			$('li.current a.contacto').css('background-position','-580px -29px');
			$('li.current a.manufactures').css('background-position','-360px -29px');
			$('li.current a.galeria').css('background-position',' -478px -29px');
        }
		
		
		
		);

        setCurr(curr);

        function setCurr(el) {
            $back.css({ "left": el.offsetLeft+"px", "width": "80px" });
            curr = el;
        };

        function move(el) {
            $back.each(function() {
                $.dequeue(this, "fx"); }
            ).animate({
                left: el.offsetLeft,
				opacity: 1
            }, o.speed, o.fx);			
        };

		function move_home(el) {
            $back.each(function() {
                $.dequeue(this, "fx"); }
            ).animate({
                left: el.offsetLeft,
				opacity: 0
            }, o.speed, o.fx);
        };
		

    });
};
})(jQuery);

