There's no easy way to do this using JavaScript actually. Such functionality is usually done on the server side, by dynamically matching the current page's URL with a particular menu item within the menu, then generating the appropriate HTML to "select" it. The tricky part is the matching itself.
The script does let you have a certain menu item expanded depending on the page the menu is on, but this does mean you have to modify the menu item links with a URL parameter, such as:
Code:
<li><a href="target.htm?mypets=1">My pets (2nd header expanded by default)</a></li>
More info here. But again, this doesn't take care of "highlighting" the selected menu item itself, which can really only be done reliably on the server side.
Bookmarks