(function($) {
  $(function () {
    // Property Type
    var property_type = $('#property_style');
    if (jQuery.fn.displetform.global_config.property_types != undefined
			&& jQuery.fn.displetform.global_config.property_types != null
			&& jQuery.fn.displetform.global_config.property_types.length != 0
			&& jQuery.fn.displetform.global_config.property_types != '') {

		  $.each(jQuery.fn.displetform.global_config.property_types, function (k,v) {
  			$('<option value="' + v + '">' + k + '</option>')
  				.appendTo(property_type);
  		});
		}
    
    // Area
    var area = $('#area');
    if (jQuery.fn.displetform.global_config.areas != undefined
			&& jQuery.fn.displetform.global_config.areas != null
			&& jQuery.fn.displetform.global_config.areas.length != 0
			&& jQuery.fn.displetform.global_config.areas != '') {

			$.each(jQuery.fn.displetform.global_config.areas, function (k,v) {
				$('<option value="' + v + '">' + k + '</option>').appendTo(area);
			});
		}
    
    // Max Price
    var maxListPrice = $('#maxListPrice');
    for (var price = jQuery.fn.displetform.global_config.options.priceMin;
			price <= jQuery.fn.displetform.global_config.options.priceMax;
			price += jQuery.fn.displetform.global_config.options.priceIncrement) {
			$('<option value="' + (price / 1000) + '">' + (price / 1000) + ',000</option>').appendTo(maxListPrice);
		}
    
    // Min Bedrooms
    var minBedrooms = $('#minBedrooms');
    for (var beds = jQuery.fn.displetform.global_config.options.bedsMin;
			beds <= jQuery.fn.displetform.global_config.options.bedsMax;
			beds++) {
				$('<option value="' + beds + '">' + beds + '+</option>').appendTo(minBedrooms);
			}
    
    // Min Bathrooms
    var minBathrooms = $('#minBathrooms');
    for (var baths = jQuery.fn.displetform.global_config.options.bathsMin;
			baths <= jQuery.fn.displetform.global_config.options.bathsMax;
			baths++) {
				$('<option value="' + baths + '">' + baths + '+</option>').appendTo(minBathrooms);
			}

			
    // Form Submit
    $('#cta_search_now a').click(function() {
      var url = (function (url) {
				if (url.lastIndexOf('/') != url.length) {
					url += '/';
				}
				url += '#';
				return url;
			})("http://search.wardrealestateaustin.com");

			$.each($('.displet'), function () {
				if (this.value != 'none' && this.value != '' && this.value != 'Subdivision' && this.value != 'Zip Code' && this.value != 'Keyword') {
					url += this.name + '=' + this.value + '/';
				}
			});

			window.location = url;
			return false;
    });
  });
})(jQuery);
