document.observe('dom:loaded', function(){

	if ($(document.body).classNames().toString().indexOf('search-index-index') >= 0) {
		Event.observe($('site-search'), 'submit', function(e){
			Event.stop(e);
			document.location.href = SEARCH_INDEX + this['q'].value;
		});
	
	}

	$('search').autocomplete = 'off';


	Event.observe($('search'), 'keyup', function(e){
			window.clearTimeout(Pod1.Search.id);
			Pod1.Search.autocomplete(this);
	});
	
	Event.observe($('search'), 'blur', function(e){
		window.setTimeout('Pod1.Search.remove()', 500);
	});
	
});

if (typeof(Pod1) != 'object') { var Pod1 = new Object(); }

Pod1.Search 				= new Object();
Pod1.Search.id 				= null;
Pod1.Search.timeout 		= 0;
Pod1.Search.input			= null;
Pod1.Search.url				= SEARCH_AJAX;
Pod1.Search.query			= '';
Pod1.Search.busy			= false;
Pod1.Search.result_id       = 'smart-search'
Pod1.Search.result			= '<div id="'+Pod1.Search.result_id+'" class="smart-search result"></div>';
Pod1.Search.remove			= function() {
								if ($(Pod1.Search.result_id)) {
									$(Pod1.Search.result_id).remove();									
								}
							}
Pod1.Search.autocomplete 	= function(obj){
								Pod1.Search.input = obj;
								Pod1.Search.query = Pod1.Search.url + escape(obj.value);
								Pod1.Search.id = window.setTimeout(function(){
									if (Pod1.Search.busy) { return; }
									Pod1.Search.busy = true;
									if ($(Pod1.Search.result_id)) {
										$(Pod1.Search.result_id).remove();									
									}
									$('site-search').insert(Pod1.Search.result);
									$(Pod1.Search.result_id).hide();
									
									$(Pod1.Search.result_id).innerHTML = '';
									var ajax = new Ajax.Request(
										Pod1.Search.query, 
										{
											method: 'post',
											onSuccess: function(transport) {
												
												Pod1.Search.busy = false;
												
												if (transport.responseText.replace(/^\s+|\s+$/g, '') != '') {
													$(Pod1.Search.result_id).show();
													$(Pod1.Search.result_id).insert(transport.responseText);
												}
											}
										}
									);
								
								}, Pod1.Search.timeout);
							}	


