(function($) {
	//public functions
	var methods = {
		init : function(options) {
			var defaults = {
				navLinkClass	: ".navLink"
			};
			
			opts = $.extend(defaults, options);
			
			//grab elements			
			$t = $(this);
			$mainLinks = $t.find("a.main");
						
			//set up main link and sub nav links			
			$mainLinks.click(showSubNav);
			$t.find("a.navLink").click(navLinkClick);
			
			return this;
		}
	},	
	/*
		private vars
	*/
	$mainLinks = [], opts,	
	
	//constants
	ANIMATIONTIME = 500;	
	/*
		private functions
	*/
	function navLinkClick(){
			$("a.current.navLink").removeClass("current");
			$(this).addClass("current");
	}
	
	function showSubNav(){
		$link = $(this);
		$('a.main.open').removeClass('open');
		// Mark nav button as open
		$link.addClass('open');
		//the first cell is the width of the current li the second is the width of every other
		var relArr = ($link.attr("rel")).split("|");
		$link.clearQueue().animate({
			marginLeft: -$link.width()
		}, ANIMATIONTIME)
		.parent("li").clearQueue().animate({
			width: relArr[0]
		}, ANIMATIONTIME);
		
		var $otherLinks = $mainLinks.not(this);				
		$otherLinks.not(this).clearQueue().animate({
			width: relArr[1]-2,
			marginLeft: 0
		}, ANIMATIONTIME)
		.parent("li:not(.last)").clearQueue().animate({
			width: relArr[1]
		});				
		$otherLinks.not(this).parent("li.last").clearQueue().animate({
			width: relArr[1]-2
		}, ANIMATIONTIME);
		
		return false;
	}
	
	
	//Initializer
	$.fn.mainNav = function(method) {
		//Method Calling Login
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		} else if (typeof method === 'object' || !method) {
			return methods.init.apply(this, arguments);
		} else {
			$.error('Method ' + method + ' does not exist on jQuery.');
		}
	};
})(jQuery);
