	var keyPressDelay = null;
	
	function delay(){
		if (keyPressDelay){
			window.clearTimeout(keyPressDelay);
		}
		keyPressDelay = window.setTimeout('doSearch()', 800);
	}
	
	function activateSearch() {
		if ($('searchform')) {
			$('word').value = ''; // Default text in the search box
			var o = document.createElement('div'); // Old search results div
			var n = document.createElement('div'); // New search results div
			$('searchform').onsubmit = function() { delay();return false; };
			$('word').onkeyup = function() { delay();return false; };
			$('word').onfocus = focusS; // Function to clear the default search box text on focus
			var s = $('search-results');
			var f = $('searchform');
			o.id = 'old-search-results';
			n.id = 'current-search-results';
			s.appendChild(n);
			s.appendChild(o);
			o.style.display = 'none';
			n.style.display = 'none';
			is_searching = false;
		}
	}
	
	function doSearch() {
		// If we're already loading, don't do anything
		if (is_searching) return false; 
		s = $F('word');
		// Same if the search is blank
		if (s == '' || s == '') return false; 
		is_searching = true;
		c = $('current-search-results');
		o = $('old-search-results');
		$('flagSearch').innerHTML = "Searching..";
		o.innerHTML = c.innerHTML;
		c.style.display = 'none';
		o.style.display = 'block';
		// Setup the parameters and make the ajax call
		pars = '&word=' + escape(s);
		var myAjax = new Ajax.Request($('searchform').action, 
			  {method: 'get', parameters: pars, onComplete:doSearchResponse});
	}
	
	function doSearchResponse(response) {
		$('current-search-results').innerHTML = response.responseText;
//		new Effect.BlindUp('old-search-results',{duration:.8});
//		new Effect.BlindDown('current-search-results',{duration:.8, afterFinish:resetForm});
		$('old-search-results').style.display = 'none';
		new Effect.Appear('current-search-results',{duration:.8, afterFinish:resetForm});

	}
	
	function resetForm() {
		$('flagSearch').innerHTML = "Search";
		is_searching = false;
	}
	
	function focusS() {
		if ($F('word') == '') $('word').value = '';
	}
	
	Event.observe(window, 'load', activateSearch, false);