var pose = {

	init: function() {
		pose.search_form = YAHOO.util.Dom.get('searchform');
		pose.search_input = YAHOO.util.Dom.get('q');
		pose.results = YAHOO.util.Dom.get('xhrresults');
		pose.resultheading = YAHOO.util.Dom.get('resultheading');
		YAHOO.util.Event.addListener(pose.search_input, 'keyup', pose.do_xhr_search);
	},

	do_xhr_search: function(e) {
		if (pose.search_input.value.length > 2) {
			YAHOO.util.Event.preventDefault(e);
			YAHOO.util.Connect.setForm(pose.search_form);
			var cObj = YAHOO.util.Connect.asyncRequest('GET', '/en/europython/search/?xhr=True', pose.search_callback);
		} else {
			pose.results.innerHTML = ''
		}
	},

	search_callback: {
		success: function(o) {
			// This turns the JSON string into a JavaScript object.
			var response_obj = eval('(' + o.responseText + ')');
		
			if(response_obj.empty) { // Errors with query
					// Do something
					pose.results.innerHTML = '<h3 class="resultheading">No results</h3>'
			} else if(response_obj.success) { // The form went through successfully.
				
				// alert('Toimii: ' + o.status + " " + o.statusText );
				pose.results.innerHTML = '<h3 class="resultheading">Livesearch Results</h3><p>' + response_obj.resulthtml + '</p>'
				
			} // elseifsuccess
	  }, // success
	   
		failure: function(o) { // we shouldn't ever go down this path.
			alert('Virhe: ' + o.status + " " + o.statusText );
		}
	} // search_callback

}; // pose

YAHOO.util.Event.addListener(window, 'load', pose.init);
