LiveSearch = Class.create();
LiveSearch.prototype = {
	initialize: function(searchItem,resultsItem,activityItem) {
		this.searchItem		= searchItem;
		this.resultsItem	= resultsItem;
		this.activityItem	= activityItem;
		
		this.injectBehavior();
		this.updateSearchResults();
	},
	
	injectBehavior: function() {
		//add key-up event observer to this.searchItem
		Event.observe(
					  this.searchItem,
					  'keyup',
					  this.updateSearchResults.bindAsEventListener(this));
					  
	},
	
	updateSearchResults: function() {
		//only make the request if we're not in the middle of searching
		if(Ajax.activeRequestCount == 0) {
			var pars = 'searchFor=' + $F(this.searchItem);
			var url = '/livesearch.php';
			
			//show the activity indicator
			$(this.activityItem).style.display = '';
			
			//make the ajax request
			var myAjax = new Ajax.Request(url,{method: 'post',parameters: pars,onComplete: this.handleSearch.bind(this)});
		}
	},
	
	handleSearch: function(originalRequest) {
		//parse the results
		$(this.resultsItem).innerHTML = originalRequest.responseText;
		
		//hide the activity indicator
		$(this.activityItem).style.display = 'none';
	}
}
