(function($) {

	$.extend( jQuery.easing,
	{
		easeUberNav: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return c/2*t*t*t + b;
			return c/2*((t-=2)*t*t + 2) + b;
		}
	});

	$.fn.uberNav = function(settings) {
		var config = {'slidespeed': 400, 'scrollspeed': 500};
 
		if (settings) $.extend(config, settings);	
		
		var currentIndex=-1;
		var totalheight=$('#navstage').children('.navbox').length*346;
		$('#navstage').css({height:totalheight});
		$('#nav').children('a.maintopic').click(function() {
			if (currentIndex!=-1) {
				$('#nav').children('a.maintopic').eq(currentIndex).removeClass('selected'+(currentIndex+1));
			}
			if (currentIndex==-1) {
				$(this).addClass('selected'+($(this).index()+1));
				$('#navstage').css({bottom:($(this).index()+1)*346-totalheight});
				$('#closer').fadeIn();
				$('#navpopup').css({height:0, left:20}).animate({height:346},{duration:config.slidespeed, easing:'easeUberNav'});
				currentIndex=$(this).index();
			} else if (currentIndex==$(this).index())
			{
				$('#navpopup').animate({height:0},{duration:400, easing:'easeUberNav'});
				currentIndex=-1;
				$('#closer').fadeOut();
			} else {
				$(this).addClass('selected'+($(this).index()+1));
				$('#navstage').animate({bottom:($(this).index()+1)*346-totalheight},{duration:config.scrollspeed, easing:'easeUberNav'});
				currentIndex=$(this).index();
			}
			
			return false;
		});
		
		$('#closer').click(function() {
			if (currentIndex!=-1) {
				$('#nav').children('a.maintopic').eq(currentIndex).removeClass('selected'+(currentIndex+1));
			}
			$('#navpopup').animate({height:0},{duration:config.slidespeed, easing:'easeUberNav'});
			currentIndex=-1;
			$('#closer').fadeOut();		
		});
		return this;
	};
 })(jQuery);
