var ieSelectFix = function($) {
	/*
	****
	presumes the following classes:
	.expandMe - apply to all select elements that should be monitored, 
	THIS CLASS SHOULD ALSO CONTAIN THE CONTRACTED WIDTH VALUE, other style settings can be added here as well
	
	the following vars need to be set:
	expandedW - the width of the expanded state of the select (usually auto)
		
	Each select menu needs to have a unique ID in order to keep track of which one is currently focused
	****
	*/
	
	var expandedW = "auto"; //generally set to auto
	var currentFocus = null;
	var threshhold = 23; //character count minimum, any menus with a longest option lower than the threshold will not use the effect
	
	var qualifies = function(el) {
		var qualified = false;
		if (el.options.length > 0) {
			var defaultLen = el.options[0].text.length;
			var longestLen = 0;
			for (i=1; i<=(el.options.length - 1); i++) {
				var x = el.options[i].text.length;
				if ( x > longestLen)
					longestLen = x;
			}
			if (longestLen > defaultLen && longestLen > threshhold) {
				qualified = true;
			}
		}

		if (qualified) {
			return true;
		} else {
			return false;
		}
	};
	
	var contract = function() {
		if (this.id != currentFocus) {
			//this check keeps the focused element expanded but allows hovered (but not focused) els to contract
			//if the element is hovered and focused, it will be contracted via the blur event
			$(this).css("width","");
			$(this).unbind("blur mouseleave", contract);
		}
	};

	var expand = function() {
		if (qualifies(this)) {
			$(this).css("width",expandedW);
			$(this).bind("blur mouseleave", contract);
		} else {
			// stop trying if it fails
			//$(this).unbind("mouseenter focus", expand);
		}
	};
	
	var focused = function() {
		currentFocus = this.id;
	};

	var blurred = function() {
		currentFocus = null;
	};
	
	return {
		init : function() {
			$('select.expandMe').bind("mouseenter focus", expand);
			$('select.expandMe').bind("focus", focused);
			$('select.expandMe').bind("blur", blurred);
		}
	};
}($);


/*
This is called from VariantDropdownWidget instead of here to make sure it works everytime the quick look layer is launched

$(document).ready(function(){
	if(jQuery.browser.msie){
		ieSelectFix.init();
	}
});
*/
