/* setMenu()
**
** 1) Find the <a> tag that matches the given id tag and store its
**    parent <li> tag in $parentLi.  
** 2) Using the parent <li> (of the active <a> tag), do the following...
**    a) make all of its child (nested) <ul> tags visible
**    b) find any <a> tags within the <li> and add the 'selected' css class
**    c) now we need to move up a level so...
**          i) get the parent <ul> tag of the current <li> tag ($parentLi)
**         ii) find its parent <li> and re-assign it to the $parentLi variable
**        iii) try the iteration again and repeat for the next level 'up
**             the tree'
** 3) Job done, every <a> tag above, and including, the currently active <a>
**    tag will have the 'selected' css class assigned to it, further more, the
**    active branch of the tree will be visible (second-level <ul> tags
**    are set to 'display: none;' in the css - these are now set visible).
**
** To ininitialise the menu, you must...
**
** 1) Include this script.
** 2) Call the setMenu() function with the string of the to be selected menu 
**    item's id tag, e.g.
**
** // Syncs to the menu item with id="menu.login"
** $(function() {
**    setMenu('menu.login');
** });
*/

var setMenu = function(action)
{
	$("ul.menu a").each(function() {
		var tmpAction = this.id;
		if (tmpAction === action) {
			var $parentLi = $(this).parent("li");
			while (($parentLi) && ($parentLi.length > 0))
			{
				$parentLi.children("ul").show();
				var $activeLink = $parentLi.children("a");
				$activeLink.addClass("selected");
				$parentLi = $parentLi.parent("ul").parent("li");
			}
			return;	// There can only be one current page!
		}
	});
};
