// clear search field on focus, and reset to "Search this site" on blur if search field is left blank

function searchFocus () {
	
	$("form.search input.search").val("");
	
}

function searchBlur () {
	
	if($("form.search input.search").val().length <= 0)
		$("form.search input.search").val("Search this site");
	
}

Function.prototype.sleep = function (millisecond_delay) {
	if(window.sleep_delay != undefined) clearTimeout(window.sleep_delay);
	var function_object = this;
	window.sleep_delay = setTimeout(function_object, millisecond_delay);
};

// onDOMReady
$(function() {
	
	$("form.search input.search").focus(searchFocus);
	$("form.search input.search").blur(searchBlur);
	
	
	// HTML Fallback search
	// Search within the li (general text) and hide nodes that do not have any matches
	$('input#fallback_search').keyup(function () {
		var search_term = new RegExp(this.value.replace(/\\/g, ''), "i");
		var perform_search = function () {
			// Hide all elements
			$("#mapreplacement ul.items li").hide();
			
			// Show all elements that match the search string
			$("#mapreplacement ul.items li").filter(function () {
				return $(this).text().match(search_term);
			}).show();
		}.sleep(200);
		
		// Reset user focus
		this.focus();
	});
	
	// Load entity data from remote 
	
	// Can't do this! Its crossdomain!
	//$.get('http://services.mirvac.com/locations.js', function(xhr) {
//		console.debug(xhr)
//	});
});