$.fn.droppy =
function()
{
  var active = {};

  this.each(
    function()
    {
      function remove(id)
      {
        if (typeof(active[id]) !== 'undefined')
          delete active[id];
      }

      function hoverIn()
      {
        var parent_ptr            = $(this);
        var parent_id             = parent_ptr.attr('id');

        if (typeof(active[parent_id]) !== 'undefined')
          return;

        for (var key in active)
          $('#'.concat(key)).trigger('mouseleave', true);

        active[parent_id]         = 1;
        parent_ptr.addClass('hover');
        $('a', this).addClass('hover');
        var button_section        = $('img', this)[0];
        var button_section_width  = 0;

        if (typeof (button_section) !== 'undefined')
          button_section_width = button_section.clientWidth - 3;

        $('ul', this).each(
          function ()
          {
            if (button_section_width > 0)
              $(this).css({'minWidth': button_section_width});

            $(this).slideDown('fast');
          });
      }

      function hoverOut(ev, fast)
      {
        var parent_ptr            = $(this);
        parent_id                 = parent_ptr.attr('id');

        parent_ptr.removeClass('hover');
        $('a', this).removeClass('hover');

        var elements_ptr          = $('ul', this);
        var last                  = elements_ptr.length - 1;

        elements_ptr.each(
          function (index)
          {
            $(this).hide(0,
                         function ()
                         {
                           if (last === index)
                             remove(parent_id);
                         });
          });
      }

      $('dt, dd', this).hover(hoverIn, hoverOut).bind('mouseover', hoverIn);
    });
};

