navigation menu slideDown based on url

navigation menu slideDown based on url

hi,
trying to get a vertical menu working. I'm trying to show menu-items based on the url. 
Guess I've got the current URL right based on:  $(location).attr('href');
But I can not seem to get it working/debugging. Appreciate a hint in the right direction .
This is what I've got:


UPDATE
changed the code but still not working.
If I'm on page "A-Second" and in my sidebar click on the visible A-Third (the b-section is collapsed) then.... on this new page A-Third it is my goal that the sidebar shows A-First, A-Second and A-Third visible.

Hope I made it more clear and thank you for your help.

  1. <ul class="csm">
     <li> <span> a-section </span> 
     <ul> 
     <li><a href="a-first">A-First</a></li>
     <li><a href="a-second">A-Second</a></li>
     <li><a href="a-third">A-Third</a></li>
     </ul> 
     </li>
     <li> <a href="y-only">Y-Only</a> </li>
     <li> <a href="z-only">Z-Only</a> </li>
     <li> <span> b-section </span> 
     <ul> 
     <li><a href="c-first">C-First</a></li>
     <li><a href="c-second">C-Second</a></li>
     </ul>
     </li>
    </ul>

    <script> 
    // initiate accordion 
    $(".csm > li > span").click(function(){
     if(false == $(this).next().is(':visible')) {
     $('.csm ul').slideUp(300);
     } $(this).next().slideToggle(300);
    });
    </script> 
    <script>
    var path=$(location).attr('href');  
    var fileNameIndex = path.lastIndexOf("/") + 1;
    var filename = path.substr(fileNameIndex);
    $(document).ready( function(){ 
     $('.csm a').each(function(){
     var listofhref = $(this).attr('href');
     if (filename.substring(0,listofhref.length)===listofhref){
     $(this).closest('span').slideDown('normal'); 
     }
     });
    }); 
    </script>