var UserUtils = {
	HideNestedChild: function(element) {
		element = $(element);
		if(!element.match('ul')) {
			throw $break;
		} else {
			element.hide();
		}
		return true;
	},
	HideNestedChildren: function(element) {
		element = $(element);
		element.up().nextSiblings().each(Element.HideNestedChild);
		return true;
	},
	HideNestedSibling: function(element) {
		element = $(element);
		if(!element.match('ul')) {
			throw $break;
		} else {
			if(element.readAttribute('currentsubnav') == null) {
				element.hide();
			}
		}
		return true;
	},
	HideNestedSiblings: function(element) {
		element = $(element);
		element = element.up().up();
		element.HideNestedSibling();
		element.previousSiblings().each(Element.HideNestedSibling);
		element.nextSiblings().each(Element.HideNestedSibling);
		return true;
	},
	ProtectSibling: function(element) {
		element = $(element);
		if(!element.match('ul')) {
			throw $break;
		} else {
			element.writeAttribute({currentsubnav: '1'});
		}
		return true;
	},
	ProtectSiblings: function(element) {
		element = $(element);
		element = element.up().up();
		element.ProtectSibling();
		element.previousSiblings().each(Element.ProtectSibling);
		element.nextSiblings().each(Element.ProtectSibling);
	}
};
Element.addMethods(UserUtils);

document.observe("dom:loaded", function() {
	if($$('div.boxcontent > ul.nav > li > a[href="'+ window.location.pathname.replace('/','') +'"]').size() != 0) {
		// current page is a non-nested nav item.  hide all nested nav items except nav items nested under this one.
		$$('div.boxcontent > ul.nav > li > a[href!="'+ window.location.pathname.replace('/','') +'"]').each(Element.HideNestedChildren);
	} else if($$('div.boxcontent > ul.nav > ul > li > a[href="'+ window.location.pathname.replace('/','') +'"]').size() > 0) {
		// current page is a nested nav item.  hide all nested nav items except siblings of this one.
		$$('div.boxcontent > ul.nav > ul > li > a[href="'+ window.location.pathname.replace('/','') +'"]').first().ProtectSiblings();
		$$('div.boxcontent > ul.nav > ul > li > a[href!="'+ window.location.pathname.replace('/','') +'"]').each(Element.HideNestedSiblings);
	} else {
		// current page is the section landing page, or some other page not linked in the nav.  hide all nested items in the nav.
		$$('div.boxcontent > ul.nav > li > a').each(Element.HideNestedChildren);
	}
});