(function ($) {

    $.fn.spasticNav = function (options) {

        $('#nav .selected').addClass('bloblink');

        options = $.extend({
            overlap: 20,
            speed: 500,
            centrespeed: 500,
            reset: 500,
            color: '#f48829',
            easing: 'easeOutExpo'
        }, options);



        return this.each(function () {

            var nav = $(this),
		 		currentPageItem = $('.selected', nav),
		 		blob,
		 		reset,
				linkset;

            $('<li id="blob"><span class="blobL"></span><span class="blobC"></span><span class="blobR"></span></li>').css({
                height: currentPageItem.outerHeight() + options.overlap,
                left: currentPageItem.position().left,
                color: options.txtcolor,
                display: $(currentPageItem).attr('id') == 'liHidden' ? 'none' : 'block'
            }).appendTo(this);

            $('.blobC').width(currentPageItem.outerWidth() - 15);

            $('#blob a').css({
                color: options.txtcolor
            }).appendTo(this);

            blob = $('#blob', nav);

            $('li:not(#blob)', nav).hover(function () {
                // mouse over
                $('#blob', nav).show();
                clearTimeout(linkset);
                clearTimeout(reset);
                blob.find('.blobC').animate(
                    {
                        width: $(this).width() - 15
                    },
					{
					    duration: options.centrespeed,
					    easing: options.easing,
					    queue: false
					}
                );
                blob.animate(
					{
					    left: $(this).position().left
					},
					{
					    duration: options.speed,
					    easing: options.easing,
					    queue: false
					}
				);

                $('#nav li').removeClass('bloblink');
                $(this).addClass('bloblink');

            }, function () {
                // mouse out	
                reset = setTimeout(function () {
                    $('#nav .notselected').removeClass('bloblink');

                    blob.find('.blobC').animate({
                        width: currentPageItem.outerWidth() - 15
                    }, options.speed)
                    blob.animate({
                        left: currentPageItem.position().left
                    }, options.speed)


                }, options.reset);
                linkset = setTimeout(function () {
                    $('#nav .selected').addClass('bloblink')
                }, options.speed + 500);
            });
        }); // end each

    };

})(jQuery);
