/**
 * jQuery select plugin.
 *
 * @requires jQuery v1.1 or later
 *
 * @author  Eugene Leonovich
 * @version SVN: $Id: jquery.select.js 78 2010-02-11 11:47:01Z Eugene $
 */

;(function($) {

  $.fn.select = function(options) {
    var o = $.extend(true, {
      selector: {
        title: 'dt',
        ddbox: 'dd'
      }
    }, options);

    return this.each(function() {
      var self = this, $dt = $(o.selector.title, this), $dd = $(o.selector.ddbox, this);

      $dt.click(function() {
        $dd.show();
      });

      $('a', $dd).click(function() {
        var $obj = $(this), $input = $('input', $dd), val = $obj.attr('href').substr(1);
        if (val != $input.val()) {
          $input.val(val).change();
          $dt.html($obj.html());
        }
        $dd.hide();
        return false;
      });

      $(document).click(function(e) {
        if (-1 == $.inArray(self, $(e.target).parents().andSelf())) {
          $dd.hide();
        }
      });
    });
  }
})(jQuery);
