﻿(function($) {
	$.fn.dropDownExpander = function() {
		if (detectBrowser()) {
			return this.each(function() {
				$(this).mousedown(ExpandDropDown);
				$(this).change(ContractDropDown);
				$(this).blur(ContractDropDown);
			});
		}
	}

	function ContractDropDown() {
		var ddlb = $(this);
		ddlb.css("position", "relative");
		ddlb.css("width", ddlb.data("origWidth"));
	}

	function ExpandDropDown() {
		var ddlb = $(this);
		var isInline = $(this).hasClass("autoExpand-inline");

		var origWidth = ddlb.data("origWidth");
		if (origWidth == null) {
			ddlb.data("origWidth", ddlb.css("width"));
		}
		
		var styleBase = "";
		if (!isInline) {
			ddlb.css("position", "absolute");
		} else {
			styleBase = "display: inline;";
		}
		ddlb.css("width", "auto");
		
		if (!ddlb.parent().is(".ddlbContainer")) {
			ddlb.wrap("<div class='ddlbContainer' style='" + styleBase + "height:" + ddlb.height() + "'></div>");
		}
		ddlb.focus();
	}
	
	function detectBrowser() {
		// use a better browser
		return ($.browser.msie && $.browser.version.substring(0,1) < 9);
	}

})(jQuery);

Sys.Application.add_load(function () {
    jQuery(function () {
		$("select.autoExpand").each(function() { $(this).dropDownExpander(); });
    });
});
if (typeof (Sys) !== 'undefined') {
    Sys.Application.notifyScriptLoaded();
}


