problem with Accordion menu

problem with Accordion menu

Hi,

I`m trying to integrate this accordion menu that is placed in Marco's blog with
simple vertical menu in CMSMS project :
  1.  function initMenu() {
   2. $('#menu ul').hide();
   3. $('#menu ul:first').show();
   4. $('#menu li a').click(
   5. function() {
   6. var checkElement = $(this).next();
   7. if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
   8. return false;
   9. }
  10. if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
  11. $('#menu ul:visible').slideUp('normal');
  12. checkElement.slideDown('normal');
  13. return false;
  14. }
  15. }
  16. );
  17. }
  18. $(document).ready(function() {initMenu();});

This is my complete menu schema without accordion JS script :
Image
For this menu I used these tags to make a accordion menu for my website :
function initMenu() {
  $('div#menu_vert ul li ul').hide();
  $('div#menu_vert ul li.activeparent ul').show();
  $('div#menu_vert ul li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul li.activeparent ul')) && (checkElement.is(':visible'))) {
        return false;
        }
      if((checkElement.is('ul li ul')) && (!checkElement.is(':visible'))) {
        $('div#menu_vert ul li ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
       return false;
        }
             }
    );
  }
$(document).ready(function() {initMenu();});


Now my menu works correctly but not completely
As you see in below screenshot for example "CSS" item is one
of items that has 'ul li ul' tag in my code and when I click on
it , related page will load :
Image
But I have some items that are subset of those items that get
'ul li ul' property , for example "Modules" item in my menu has
two subset items that are named as "News" and "Menu Manager" and
get 'ul li ul li ul' property .
I tried to embed 'ul li ul li ul' in my code but I didn`t acquire
any success , and now when I click on "Modules" and "Tags" items
my menu will hide these items and doesn`t show for example "News" and
"Menu Manager" items to me .

Could you please suggest me proper code ?

Thanks
Omid