// +----------
// | jQuery dropMe v1.2
// | Release: Sept 22, 2010
// | Author: Kai Johnson
// | Author URI: www.goldentreestudio.com
// +----------

(function($){
	
	$.dropMe = function(el){
		var dM = this;
		dM.$select = $(el); // <select>
		dM.$select.wrap('<div class="select-drop" />');
		dM.$input = $('<input type="text" readonly="readonly" id="' + dM.$select.attr('id') + '" name="' + dM.$select.attr('name') + '" />');
		dM.$ul = $('<ul class="select"></ul>').insertAfter(dM.$select);
		
		dM.$select.children().each(function(){ // <option>
			$child = $(this);
			$child.appendTo(dM.$ul).replaceWith('<li class="option"><a href="' + $child.val() + '">' + $child.text() + '</a></li>');
		});
		
		dM.$select.replaceWith(dM.$input.val(dM.$ul.children(':eq(0)').text()));
		dM.$ul.hide().children(':eq(0)').remove();
				
		dM.$ul.hover(function(){
			dM.$ul.show();
		}, function(){
			dM.$ul.hide();
		});		
		
		dM.$input.hover(function(){
			dM.$ul.show();
		}, function(){
			dM.$ul.hide();
		});		
		
		dM.$ul.children('li').click(function(){
			$child = $(this);
			$child.hide().siblings().show();
			dM.$input.val($child.text()).trigger('click');
			dM.$ul.hide();
		});		
	}	
	
	$.fn.dropMe = function(){
		return this.each(function(){
			new $.dropMe(this);
		});
	}
	
})(jQuery);
