/* @group core */

	jQuery.fn.selectReplace = function(options) {
		if (!(jQuery.browser.msie && jQuery.browser.version < 7)) {
			var opts = jQuery.extend({}, jQuery.fn.selectReplace.defaults, options);
			return this.each(function() {
				var $this = jQuery(this);
				var o = jQuery.meta ? jQuery.extend({}, opts, $this.data()) : opts;

				$this.change(function() {
					$this.parent().find('span.value').html($this.find('option[value=' + $this.val() + ']').html());
				});

				$this.trigger('change');

			});
		}
	};

	jQuery(document).ready(function() {

		var p_location = jQuery( "#propertyLocation, #price_range, #bedrooms, #baths" );
		var city_selects = jQuery(".location-city-wrapper");
		var location_wrapper = p_location.parent();
		
		jQuery('#advancedSearch').click(function(e) {
			e.preventDefault();
			$('#advancedSearchPopup').show();
			$("#searchBox").hide();
		});
		
		jQuery('#simpleSearch').click(function(e) {
			e.preventDefault();
			$("#searchBox").show();
			$('#advancedSearchPopup').hide();
		});

		jQuery('#price_range, #bedrooms, #baths, .location-city, #location-state').selectReplace();
		
		
		if(jQuery('.active-city').length == 0) {
			jQuery('.location-city-wrapper').eq(0).addClass('active-city');
		}
		
		jQuery('#location-state').change(function() {
			city_selects.removeClass('active-city');
			var state = $(this).val() != "" ? "-" + $(this).val() : "";
			$('#location-city-wrapper'+state).addClass('active-city');
			$('#location-city'+state).trigger('change');
		});
		
		city_selects.find('select').change(function() {
			var location = $(this).val();
			$('#propertyLocation').val(location);
			updateSearchActionURL();
		});
		
		p_location.change(function() {
			updateSearchActionURL();
		});

		// p_type.change();

	});
	 
	function updateSearchActionURL() {
		var p_type = jQuery( "#propertyType" ).val(), 
		p_location = jQuery( "#propertyLocation" ).val();
		
		var url = p_type + "/" + p_location;
		
		if ( !p_location ) url = "property_search";
		
		jQuery( "#propertyTypeSearch" ).attr( "action", "/" + url );
	}

/* @end */

/* @group ga */

	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-2103471-2']);
	_gaq.push(['_setDomainName', '.kettler.com']);
	_gaq.push(['_trackPageview']);

	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();

function recordOutboundLink(link, category, action) {
		_gat._getTrackerByName()._trackEvent(category, action);
		setTimeout('document.location = "' + link.href + '"', 100);
	}

/* @end */

/* @group clicktale */

	var WRInitTime=(new Date()).getTime();

/* @end */

