var doAjax = function() {

	var searchFormActive = function() {
		if (this.value.length > 2) {
			var myHTMLRequest = new Request.HTML({url:'/form_search', update: $('search_results'), onComplete: function(){
				$('search_results').addClass('results');
				theHeight = 0;
				$('search_results').getChildren().each(function(el){
					theHeight = el.getSize().y + theHeight;
				});
				$('search_results').morph({width : [150, 400], height : [0, theHeight], borderColor : '#9be0ef'});	
			} }).get({'search_value' : this.value});		
		} else {
			$('search_results').morph({width : 150, height : 0, borderColor : '#FFFFFF'});
			if ($('search_results').getFirst()) {
				$('search_results').getFirst().fade('out');
			}		
		}	
	}
	
	var searchFormFocus = function() {
		if (this.value == 'Search...') {
			this.value = '';
		}
	}
	
	var searchFormBlur = function() {
		if (this.value == '') {
			this.value = 'Search...';
		}
		$('search_results').morph({top : 70, right : 30, width : 150, height : 0, borderColor : '#FFFFFF'});
		$('search_results').getFirst().fade('out');	
	}	
	
	$('search_value').addEvent('keyup', searchFormActive);
	$('search_value').addEvent('focus', searchFormFocus);
	$('search_value').addEvent('blur', searchFormBlur);
	

}

window.addEvent('domready', doAjax);
