(function ($) {
	$.fn.fixSelect = function (elString) {
		var isMSIE = function () { return navigator.appVersion.indexOf('MSIE ' + (arguments[0] || '')) != -1; };
		
		return !isMSIE() ? this : this.filter('select').each(function () {	// do stuff only in MSIE to select elements
			var self = $(this);							// puts $(this) in the scope for all members
			var selfInitWidth = parseInt(self.width());	// store this select element's width before any modifications occur
			var maxOptWidth = function () {				// gets maximum est. width of any option within this select element
				var maxLength = 0;
				$('option', self).each(function () {
					var estOptWidth = $(this).html().length * 7;	// coefficient should be approximate x-width of font
					maxLength = maxLength < estOptWidth ? estOptWidth : maxLength;
				});
				return maxLength;
			};
			var handlers = {
				// define all event handlers & helpers in the handlers object
				// we need the flexibility to bind & unbind these as necessary
				addAuto: function () { self.addClass('auto'); },
				removeAuto: function () { self.removeClass('auto'); },
				addClicked: function () { self.addClass('clicked'); },
				removeClicked: function () { self.removeClass('clicked'); },
				blur: function () {
					handlers.removeClicked();
					self.width(selfInitWidth);
					handlers.removeAuto();
				},
				mouseover: function () {
					var mow = maxOptWidth();
					if (mow > selfInitWidth) {
						self.not('.auto').animate({width: mow}, 100, handlers.addAuto);
					}
				},
				mouseout: function () {
					self.filter('.auto').not('.clicked').animate({width: selfInitWidth}, 100, handlers.removeAuto);
				},
				mousedown: function () {
					if (maxOptWidth() > selfInitWidth) {
						handlers.addAuto();
					}
				},
				click: function () {
					if (self.not('.clicked') && self.is('.auto')) {
						handlers.addClicked();
					}
				}
			};
			
			self.addClass('fixed').wrap(				// add class to select element and add wrapper with calculated css
				$(elString || '<div />').addClass('selectWrap').css({
					'width': selfInitWidth == 'auto' ? null : selfInitWidth,
					'margin-top': self.css('margin-top'),
					'margin-right': self.css('margin-right'),
					'margin-bottom': self.css('margin-bottom'),
					'margin-left': self.css('margin-left')
				})
			).css({'margin': 0});
			
			self.change(handlers.removeAuto);			// add change handler
			self.blur(handlers.removeAuto);				// add blur handler
			
			if (isMSIE(7)) {							// add IE7-specific compliment of event handlers
				self.mousedown(handlers.mousedown);
			} else if (isMSIE(6)) {						// add IE6-specific compliment of event handlers
				self.click(handlers.click);
				self.mouseover(handlers.mouseover);
				self.mouseout(handlers.mouseout);
				self.change(handlers.blur);
				self.blur(handlers.blur);
			}
		});
	};
})(jQuery);
