(function($) {
	$.fn.exmenus = function(options) {
		var settings = {};
		
		return this.each(function() {
			var $this = $(this);
			var $parse_navigation_uri = window.location.hash.split('/');
			
			if (options) {
				$.extend( settings, options );
			}
			
			var $lvl_parent = $("ul:first li.lvl_parent:has(ul)", $this);
			var $lvl_child = $("ul li.lvl_one:has(ul)", $lvl_parent);
			var $lvl_one = null;
			var $lvl_two = null;
			var $lvl_parent_id_name = null;

			switch($parse_navigation_uri[0]) {
				case "#products":
					$("#nav_prod").next().show();
					$lvl_one = $("#navigation #lvl_parent_products .subnav_lvl_one");
					
					switch ($parse_navigation_uri[1]) {
						case 'customsoft':
							$lvl_two = $("#navigation #lvl_one_customsoft .subnav_lvl_two").show();
							break;
						case'softspecialty':
							$lvl_two = $("#navigation #lvl_one_softspecialty .subnav_lvl_two").show();
							break;
						case 'gaspermeable':
							$lvl_two = $("#navigation #lvl_one_gaspermeable .subnav_lvl_two").show();
					}
					break;
				case "#practitionerinfo":
					$("#nav_prac").next().show();
					$lvl_one = $("#navigation #lvl_parent_pracinfo .subnav_lvl_one");
					break;
				case "#patientinfo":
					$("#nav_link").next().show();
					$lvl_one = $("#navigation #lvl_parent_patinfo .subnav_lvl_one");
					break;
			}
			
			
			$lvl_parent.children("a").click(function(e) {
				if ($lvl_one != null) {
					$lvl_one.slideUp();
				}
				
				var $cur_parent_id_name = $(e.target).attr("id");
				
				$lvl_one = $("#" + $cur_parent_id_name).next().first();
				$lvl_one_toggled = $lvl_one.css('display');
				
				if ($lvl_one_toggled == 'none') {
					$lvl_one.slideDown();
				} else {
					$lvl_one.slideUp();
				}

				e.preventDefault();
			});
			
			$lvl_child.children("a").click(function(e) {
				if ($lvl_two != null) {
					$lvl_two.slideUp();
				}
				
				$lvl_two = $(e.target).next().first();
				$lvl_two_toggled = $lvl_two.css('display');
				
				if ($lvl_two.css('display') == 'none') {
					$lvl_two.slideDown();
				} else {
					$lvl_two.slideUp();
				}
				
				e.preventDefault();


			});
		});
	};
})(jQuery);
