(function($){
	$.fn.extend({
		betterSelect: function(){
			return this.each(function(){
					this.length = $('li', this).length;
					$('li', this).live('click', function(){
						var parent = $(this.parentNode);
						if(!parent.hasClass('open')){
							parent.trigger('click').trigger('focus');
							parent.addClass('open');
							$(this).siblings().css('display', 'block');
						} else {
							if($(this).hasClass('selected')){
								parent.removeClass('open');
								$(this).siblings().css('display', 'none');
							} else {
								parent.removeClass('open');
								$(this).insertBefore(parent.children()[0]);
								$(this).addClass('selected').siblings().removeClass('selected').css('display', 'none');
								parent[0].selected = parent.children('.selected')[0];
								parent[0].value = parent.children('.selected').attr('value');
								parent[0].text = parent.children('.selected')[0].innerHTML;
								parent.trigger('change');
							}
						}
					});
					this.append = function(value, label){
						$(this).append($('<li value="'+ value +'">'+ label +'</li>'));
					}
					this.remove = function(idx){
						
						if(idx == 0){
							$(this).children().eq(idx).remove();
							$(this).children().eq(0).css('display', 'block').addClass('selected');
							this.selected = $(this).children('.selected');
							this.value = $(this).children('.selected').attr('value');
							this.text = $(this).children('.selected').innerHTML;
							$(this).trigger('change');
						} else {
							$(this).children().eq(idx).remove();
						}
					}
			});
		}
	});
})(jQuery)