$.fn.droppy = function() {
  
  this.each(function() {
    
    var root = this, zIndex = 1000;
    
    function getSubnav(ele) {
      if (ele.nodeName.toLowerCase() == 'li') {
        var subnav = j$('> ul', ele);
        return subnav.length ? subnav[0] : null;
      } else {
        return ele;
      }
    }
    
    function getActuator(ele) {
      if (ele.nodeName.toLowerCase() == 'ul') {
        return j$(ele).parents('li')[0];
      } else {
        return ele;
      }
    }
    
    function hide() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      j$.data(subnav, 'cancelHide', false);
      setTimeout(function() {
        if (!j$.data(subnav, 'cancelHide')) {
          j$(subnav).slideUp("fast");
        }
      }, 0);
    }
  
    function show() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      j$.data(subnav, 'cancelHide', true);
      j$(subnav).css({zIndex: zIndex++}).slideDown("fast");
      if (this.nodeName.toLowerCase() == 'ul') {
        j$(getActuator(this)).addClass('hover');
      }
    }
    
    j$('ul, li', this).hover(show, hide);
    j$('li', this).hover(
      function() { j$(this).addClass('hover'); },
      function() { j$(this).removeClass('hover'); }
    );
    
  });
  
};
