$.fn.selectfixedwidth = function(options) {
	var defaults = {
		// A timeout is needed to execute the change event handler before the 
		// mousedown one and let IE hide the options list. 300ms works for me but 
		// you might need to adjust this value. If it's too short a change event 
		// handler won't be executed. Another behaviour affected by the timeout is 
		// when the select box with its list deployed is double clicked. If it's 
		// too short it will be expanded without the list being displayed and it 
		// won't behave as expected
		timeout: 300
	};
	
	// Extend default options with those provided.
  var opts = $.extend(defaults, options);
	
	return $(this).each(
		function() {
			var $this = $(this);
			if (!jQuery.support.cssFloat && $this.is("select")) { // only if ie and a select box
				if (jQuery.browser.msie && jQuery.browser.version > 6) { // ie6 not supported
					// wrap the select and apply some css to avoid breaking up the layout when 
					// expanding the select box
					var $span = $('<span class="fixedwidthselect" />');
					$span.css("position", "relative");
					$this.css("position", "absolute");
					$this.wrap($span);
					
					// original size read from the css
					var width = $(this).css("width");
					// keeps state the size
					var state = 'short';
					// timeout
					var t;
					
					$this
					.mousedown(
						function() {
							if (state == 'short') {
								$this.css("width", "auto");
								state = 'long';
							} else {
								t = setTimeout(function() {
									$this.css("width", width);
									state = 'short';
									t = null;
								}, opts.timeout);
							}
						}
					)
					.bind("blur change", 
						function() {
							$this.css("width", width);
							state = 'short';
						}
					)
					.dblclick(
						function() {
							if (t) {
								// if timeout is not null it means the select box has been double
								// clicked when the list was displayed. It doesn´t need to be 
								// shortened so the timeout is cleared and the variable reseted.
								clearTimeout(t);
								t = null;
							} else {
								$(this).trigger("mousedown");
							}
						}
					);
				}
			}
		}
	);
}
