(function($){
	$.selectreplace = function(el, options){
		if ($.browser.msie && $.browser.version == '6.0') return;
		
		var base = this;
		base.$el = $(el);
		base.el = el;

		base.init = function(){

			base.options = $.extend({},$.selectreplace.defaultOptions, options);
			
			var replace;
			
			if (base.$el.is('select')) {
				replace = base.$el;
			} else {
				replace = $('select', base.$el);
			}
			
			replace.wrap(function(index) {
				if ($(this).closest(base.options.wrapper+'.'+base.options.wrapperClass).length === 0) {
					return $('<'+base.options.wrapper+' class="'+base.options.wrapperClass+'"/>');
				}
			}).after(function(index) {
				var $this = $(this);
				if ($this.siblings(base.options.value+'.'+base.options.valueClass).length === 0) {
					return $('<'+base.options.value+' class="'+base.options.valueClass+'"/>').text($('option[value="'+$this.val()+'"]', $this).text());
				}
			}).change(function(e) {
				var $this = $(this);
				$this.siblings(base.options.value+'.'+base.options.valueClass).text($this.find('option[value="' + $this.val() + '"]').text());
			});
		};
		base.init();
	};

	$.selectreplace.defaultOptions = {
		wrapper		: 'div',
		wrapperClass: 'select-wrapper',
		value		: 'p',
		valueClass	: 'value'
	};

	$.fn.selectreplace = function(value, options){
		return this.each(function(){
			(new $.selectreplace(this, value, options));
		});
	};

})(jQuery);
