/*http://gmarwaha.com/blog/?p=7*/
(function($) {
$.fn.lavaLamp = function(o) {
    o = $.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

    return this.each(function() {
        var me = $(this);
        var $back = $('<li class="back"><div class="left"></div></li>').appendTo(me);
        var $li = $("li", this);
        
        //select .current, or make the first one the .current
        var curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
        var hovered;
        $li.not(".back")
        .bind("mouseenter",function(){
        	move(this);
        	hovered = this;
        });
        
        $li.click(function(e) {
        	if($(this).hasClass('back'))
          	move(curr = hovered);
        	else
          	move(curr = this);
          //return o.click.apply(curr, [e, curr]);
          ShowTab($(curr).children('a')[0].href.match(/#[\w\-]+/)[0]);
          e.preventDefault();
        });

        $(this).bind("mouseleave",function(){
        	move(curr);
        	hovered = curr;
//        	$(this).children("a").stop().animate({color:"black"}, 700)
        });


        function setCurr(el) {//todo: animate
        	//if(this.setup == undefined)
          	//$back.css({ left: el.offsetLeft, width: el.offsetWidth, opacity:2 }).animate({opacity:0 }, 700);
          $back.css({ left: el.offsetLeft, width: el.offsetWidth });
          move(curr = el);
        };
        move(curr);

        function move(el) {
        	$("li a.hovered").removeClass("hovered").stop().animate({color:"black"}, 700);
        	$(el).children("a").addClass("hovered").stop().animate({color:"white"}, 700);
          $back.dequeue()
          .animate({
              width: el.offsetWidth,
              left: el.offsetLeft
          }, o.speed, o.fx);
          //if(el!=curr) $(curr).children("a").stop().animate({color:"black"}, 700);
        };

    });
};
})(jQuery);
