(function($) {

    $.fn.spasticNav = function(options) {
    
        options = $.extend({
            overlap : 20,
            speed : 1000,
            reset : 1500,
            color : '#F5F5F5',
            easing : 'easeOutExpo'
        }, options);
    
        return this.each(function() {
        
            var nav = $(this),
                currentPageItem = $('#selected', nav),
                blob,
                reset;
                
            $('<li id="blob"></li>').css({
                width : currentPageItem.outerWidth(),
                height : 30,
                left : currentPageItem.position().left,
                top : currentPageItem.position().top + 31,
                backgroundColor : options.color
            }).appendTo(this);
            
            blob = $('#blob', nav);
                        
            $('li:not(#blob)', nav).hover(function() {
                // mouse over
                clearTimeout(reset);

                if ($(this).is('.lava')) {
                    blobPos = $(this).position().left;
                    blobWidth = $(this).width();
                } else {
                    blobPos = $(this).parent.position().left;
                    blobWidth = $(this).parent.width;
                }

                
                blob.animate(
                    {
                        left : blobPos,
                        width : blobWidth
                    },
                    {
                        duration : options.speed,
                        easing : options.easing,
                        queue : false
                    }
                );
            }, function() {
                // mouse out    
                reset = setTimeout(function() {
                    blob.animate({
                        width : currentPageItem.outerWidth(),
                        left : currentPageItem.parent.position().left
                    }, options.speed)
                }, options.reset);
                
            });
         
        
        }); // end each
    
    };

})(jQuery);


