jQuery.fn.dropdown = function(){
  var source = $(this);
  var selected = source.find("option[selected]");
  var options = $("option", source);
  
  var _dropdown = document.createElement('dl');
  $(_dropdown).addClass('dropdown');
  
  $(_dropdown).append('<dt><a href="#">' + selected.text() + 
      '<span class="value">' + selected.val() + 
      '</span></a></dt>')
  $(_dropdown).append('<dd><ul></ul></dd>')
  
  options.each(function(){
    $(_dropdown).find('dd ul').append('<li><a href="#">' + 
      $(this).text() + '<span class="value">' + 
      $(this).val() + '</span></a></li>');
  });
  
  $(source).after(_dropdown)
  
  $(_dropdown).find('dt a').click(function() {
      $(_dropdown).find('dd ul').toggle();
      return false;
  });
  
  $(document).bind('click', function(e) {
    var $clicked = $(e.target);
    if (!$clicked.parents().hasClass("dropdown")) {
      $(_dropdown).find('dd ul').hide();
    }
  });
              
  $(_dropdown).find('dd ul li a').click(function() {
    var text = $(this).html();
    $(".dropdown dt a").html(text);
    $(_dropdown).find('dd ul').hide();
    
    source.val($(this).find("span.value").html());
    return false;
  });
}
