Accordion and sub-menus

Accordion and sub-menus

I've created a menu using the accordion, and everything seems to be working correctly except for one small detail.  When I select a sub-menu item, the sub-menu does not remain "open" when visiting the selected page.  That's how it should work, isn't it?  I'm sure there is something obvious missing, but I don't see it.  The active tags appear to be set correctly.  I'd appreciate some help from the community with this one.

Here's the relevant code:
  1. <script type="text/javascript">
  2.         var nav = 0;

  3.         $('.sub-menu').hover(function () { // finding mouse position
  4.             nav = 1; // if mouse on submenu
  5.         }, function () {
  6.             nav = 0; // if mouse not on submenu
  7.         });

  8.         $(document).ready(function () {
  9.             $('#nav > li > a').click(function () {
  10.                 if ($(this).attr('class') != 'active') {
  11.                     $('#nav li ul').slideUp();
  12.                     $(this).next().slideToggle();
  13.                     $('#nav li a').removeClass('active');
  14.                     $(this).addClass('active');
  15.                 }
  16.                 else {
  17.                     if (nav == 0) {
  18.                         $('.sub-menu').slideUp();
  19.                         $(this).removeClass('active');
  20.                     }
  21.                     //$('#nav li ul').slideUp();
  22.                     //$('#nav li a').removeClass('active');
  23.                 }
  24.             });
  25.         });

  26.         $(function () {
  27.             // this will get the full URL at the address bar
  28.             var url = window.location.href;

  29.             // passes on every "a" tag
  30.             $("#menu_block a").each(function () {
  31.                 // checks if its the same on the address bar
  32.                 if (url == (this.href)) {
  33.                     $(this).closest("li").addClass("active");
  34.                 }
  35.             });
  36.         });
  37. </script>
  38. ...

  39. <div id="menu_block">
  40.     <ul id="nav" class="menu_item">
  41.         <li id="menuIndex" runat="server"><asp:HyperLink ID="hypIndex" runat="server" NavigateUrl="index.aspx">Home</asp:HyperLink></li>
  42.         <li id="menuViewProfile" runat="server"><asp:HyperLink ID="hypViewProfile" runat="server" NavigateUrl="~/secure/profile.aspx">View Profile</asp:HyperLink></li>
  43.         <li id="menuChartering" runat="server"><asp:HyperLink ID="hypChartering" runat="server" NavigateUrl="~/secure/chartering.aspx">Chartering</asp:HyperLink></li>
  44.         <li id="menuRegistry" runat="server" style="cursor:pointer"><asp:HyperLink ID="hypRegistry" runat="server">Registry</asp:HyperLink>
  45.             <ul class="sub-menu">
  46.                 <li id="menuNotified" runat="server"><asp:HyperLink ID="hypNotified" runat="server" NavigateUrl="~/secure/notified.aspx">Notified</asp:HyperLink></li>
  47.                 <li id="menuAuthorized" runat="server"><asp:HyperLink ID="hypAuthorized" runat="server" NavigateUrl="~/secure/authorized.aspx">Authorized</asp:HyperLink></li>
  48.                 <li id="menuResearch" runat="server"><asp:HyperLink ID="hypResearch" runat="server" NavigateUrl="~/secure/research.aspx">Research</asp:HyperLink></li>
  49.             </ul>
  50.         </li>
  51.     ...
  52.     </ul>
  53. </div>