(function($){

	$.fn.spasticNav = function(options) {
	
		options = $.extend({
			overlap: 5,
			speed: 500,
			reset: 1500,
			color: '#f80000',
			easing: 'easeOutExpo'
			
		}, options); 
		
		return this.each(function() {
		
			var nav = $(this),
				currentPageItem = $('#selected', nav),
				main_nav,
				reset;
				
			$('<li id="main_nav"></li>').css({
				width: currentPageItem.outerWidth(),
				height: currentPageItem.outerHeight() + options.overlap,
				left: currentPageItem.position().left,
				top: currentPageItem.position().top - options.overlap / 2,
				backgroundColor: options.color
			}).appendTo('#nav');
		
			main_nav = $('#main_nav', nav);
			
			$('li', nav).hover(function() {
					clearTimeout(reset);
					main_nav.animate (
						{
							left : $(this).position().left,
							width : $(this).width()
						},
						{
							duration : options.speed,
							easing : options.easing,
							queue : false
						}
					);
				},	function() {
					// mouse out
					
					main_nav.stop().animate({
						left : $(this).position().left,
						width : $(this).width()
					}, options.speed);
					
					// reset
					reset = setTimeout(function() {
						main_nav.animate({
							width : currentPageItem.outerWidth(),
							left : currentPageItem.position().left
						}, options.speed)
					}, options.reset);
				
				});
				
		});
	
	
	};
	
})(jQuery);
