if (typeof wms === "undefined") { wms = {}; wms.optout = []; } if (jQuery.inArray("jquery.lotsizedropdown.js", wms.optout) === -1) {
	;(function ( $, window, document, undefined ) {

		var pluginName = 'lotSizeDropDown',
		defaults = {
			zIndex: 10000
		};

		function Plugin( element, options ) {
			obj = this;
			this.element = element;
			this.options = $.extend( {}, defaults, options) ;

			this.current = null;

			this._defaults = defaults;
			this._name = pluginName;

			this.buildDivs();

			$(this.element).bind("click", function() {
				obj.init(jQuery('input[name=ls_conversion]:checked').val(), this);
			});


		}

		Plugin.prototype.init = function (context, el) {

			$(".lotSizeDropDowns,.priceDropDowns").css({display : "none"});

			this.current = el;

			var placement = jQuery(el).offset();

			var ctx = ($(el).attr("name").indexOf("min") > 0) ? "min" : "max";

			jQuery("#" + context + "_" + ctx + "_div").css({display : "block"});

			jQuery("#" + context + "_" + ctx + "_div").bind("mouseleave", function() {
				$(this).css({display : "none"});
			});

			jQuery("#" + context + "_" + ctx + "_div").css({
				position : "absolute",
				top : placement.top + $(el).outerHeight(),
				left : placement.left
			});

			// Dynamic way to tell if the dropdown is being hovered over.
			jQuery("#" + context + "_" + ctx + "_div").hover(
			    function() { $.data(this, 'hover', true); },
			    function() { $.data(this, 'hover', false); }
			).data('hover', false);

			// Check for hover every two seconds.
			var hoverInterval1 = setInterval(function() {
				if (!jQuery("#" + context + "_" + ctx + "_div").data('hover')) {
					jQuery("#" + context + "_" + ctx + "_div").css({display : "none"});
					clearInterval(hoverInterval1);
				}
			}, 3000);

		};

		Plugin.prototype.buildDivs = function() {
			var sqft_min_div = '';
			var sqft_max_div = '';
			var acres_min_div = '';
			var acres_max_div = '';

			sqft_min_div += '<div id="sqft_min_div" class="lotSizeDropDowns">';
				sqft_min_div += '<div>No Min</div>';
				sqft_min_div += '<div>2,000 sqft</div>';
				sqft_min_div += '<div>4,500 sqft</div>';
				sqft_min_div += '<div>6,500 sqft</div>';
				sqft_min_div += '<div>8,000 sqft</div>';
				sqft_min_div += '<div>10,890 sqft</div>';
				sqft_min_div += '<div>21,780 sqft</div>';
			sqft_min_div += '</div>';

			sqft_max_div += '<div id="sqft_max_div" class="lotSizeDropDowns">';
				sqft_max_div += '<div>No Max</div>';
				sqft_max_div += '<div>2,000 sqft</div>';
				sqft_max_div += '<div>4,500 sqft</div>';
				sqft_max_div += '<div>6,500 sqft</div>';
				sqft_max_div += '<div>8,000 sqft</div>';
				sqft_max_div += '<div>10,890 sqft</div>';
				sqft_max_div += '<div>21,780 sqft</div>';
			sqft_max_div += '</div>';

			acres_min_div += '<div id="acres_min_div" class="lotSizeDropDowns">';
				acres_min_div += '<div>Min Acres</div>';
				acres_min_div += '<div>.25 acres</div>';
				acres_min_div += '<div>.5 acres</div>';
				acres_min_div += '<div>1 acre</div>';
				acres_min_div += '<div>2 acres</div>';
				acres_min_div += '<div>3 acres</div>';
				acres_min_div += '<div>4 acres</div>';
				acres_min_div += '<div>5 acres</div>';
				acres_min_div += '<div>10 acres</div>';
				acres_min_div += '<div>40 acres</div>';
				acres_min_div += '<div>100+ acres</div>';
			acres_min_div += '</div>';

			acres_max_div += '<div id="acres_max_div" class="lotSizeDropDowns">';
				acres_max_div += '<div>Max Acres</div>';
				acres_max_div += '<div>.25 acres</div>';
				acres_max_div += '<div>.5 acres</div>';
				acres_max_div += '<div>1 acre</div>';
				acres_max_div += '<div>2 acres</div>';
				acres_max_div += '<div>3 acres</div>';
				acres_max_div += '<div>4 acres</div>';
				acres_max_div += '<div>5 acres</div>';
				acres_max_div += '<div>10 acres</div>';
				acres_max_div += '<div>40 acres</div>';
				acres_max_div += '<div>100+ acres</div>';
			acres_max_div += '</div>';

			if (jQuery("#sqft_min_div").length < 1) {
				$("body").append(sqft_min_div);
			}
			if (jQuery("#sqft_max_div").length < 1) {
				$("body").append(sqft_max_div);
			}
			if (jQuery("#acres_min_div").length < 1) {
				$("body").append(acres_min_div);
			}
			if (jQuery("#acres_max_div").length < 1) {
				$("body").append(acres_max_div);
			}

			$("#sqft_min_div, #sqft_max_div, #acres_min_div, #acres_max_div").css({
				position: "absolute",
				background: "#f5f5f5",
				width: "inline-block",
				left: 0,
				top: 0,
				"z-index": obj.options.zIndex,
				display: "none",
				height: 100,
				"overflow-y": "scroll",
				"overflow-x": "hidden",
				"font-size": "10px",
				cursor: "pointer"
			});

			$("#sqft_min_div div, #sqft_max_div div, #acres_min_div div, #acres_max_div div").css({
				padding: 5
			});

			$("#sqft_min_div div, #sqft_max_div div, #acres_min_div div, #acres_max_div div").bind("click", function() {
				jQuery(obj.current).val($(this).html().replace(/[^0-9.]/g, ""));
				jQuery(this).parent().css({display : "none"});
			});

			$("#sqft_min_div div, #sqft_max_div div, #acres_min_div div, #acres_max_div div").bind("mouseover", function() {
				$(this).css({
					"background-color" : "#ccc"
				});
			}).bind("mouseout", function() {
				$(this).css({
					"background-color" : "#f5f5f5"
				});
			});
		};

		$.fn[pluginName] = function ( options ) {
			return this.each(function () {
				if (!$.data(this, 'plugin_' + pluginName)) {
					$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
				}
			});
		}

	})(jQuery, window, document);
	
}

