$(function(){
     $('#menus a').click(function() {
          var ul = $(this).parents('li:first').find('ul:first');
          if (ul.get(0)) {
            if(ul.is(':hidden')) return true
            else {
              ul.toggle();
              return false;
            }
          }
          return true;
    });
    $('#current').find('ul:first').show();
    $('#current').parents('ul').show();
    $('#menus2 ul').parent().each(function() {
      var o = $(this);
      o.find('>ul').after('<ul class="popup">' + o.find('>ul').html() + '</ul>');
      o.find('>ul:eq(1),>a').wrapAll('<div></div>');
        o.find('>div ul li').each(function(){
          $(this).find('>ul,>a').wrapAll('<div></div>')
        });
    })
    
    $('#menus2 div ul').parent().each(function() {
        var o = $(this);
        var s = o.find('>ul');
        var k = false;
        o.hover(
          function() {
            o.find('>a').attr('class','over');
            o.parents('ul:first').find('>li').find('div ul').hide();
            var th = o.parents('div');
            $('#menus2 li div').not(th).find('ul').hide();
            k = true;
            var p = o.position();
            var ts, ls;
              ts =  p.top;
              ls = p.left + o.width();
            s.css({
              top: ts,
              left: ls
            }).show();
          },
          function() {
            o.find('>a').attr('class','normal');
            k = false;
            window.setTimeout(function() {
              if (!k) s.hide();                
            }, 1500);
          }
        );
      });
})
