Searcher = Class.create({

	initialize: function() {
		this.input	= $("searchText");
		this.button	= $("searchButton");
		if (this.input && this.button)
		{
			this.url = this.input.readAttribute("url");
			this.hookEvents();
		}
	},
	
	hookEvents: function() {
		this.button.observe("click",	this.clickHandler.bindAsEventListener(this));
		this.input.observe("keypress",	this.keyPressHandler.bindAsEventListener(this));
	},
	
	clickHandler: function(e) {
		this.startSearch();
	},
	
	keyPressHandler: function(e) {
		var keyCode = e.keyCode;
		if (keyCode == Event.KEY_RETURN)
		{
			this.startSearch();
		}
	},
	
	startSearch: function() {
		var key = this.input.value.trim();
		if (key && key.length > 0)
		{
			top.location.href = this.url + "?q=" + key.replace(" ", "+");
		}
	}
	
});

function windowLoadedSearcher()
{
	new Searcher();
}

(function() {
	Event.observe(window, "load", windowLoadedSearcher);
})();

