jQuery auto increment for class name
Probably something like this would enable you to extract it. Basically I'd suggest looping through hiding everything then setting the one you want to open, you could be clever and check if the menu selected is already one, but hopefully this will give you the idea:

$("menubar ul").each(function(){
   $("li", this).click({
      $("menubar ul").each(function(){
         $("li ul", this).hide()
      })
      $("ul",this).toggle(...
   })
})