//<![CDATA[

function doLiveSearch( keywords ) {
	$('#search_results').remove();

	if( keywords == '' || keywords.length < 3 ) {
		return false;
	}

	$.ajax({url: 'index.php?route=product/search/ajax&keyword=' + keywords, dataType: 'json', success: function(result) {
		if( result.length > 0 ) {
			var eList = document.createElement('ul');
			eList.id = 'search_results';
			var eListElem;
			var eLink;
			for( var i in result ) {
				eListElem = document.createElement('li');
				eLink = document.createElement('a');
				eLink.appendChild(document.createTextNode(result[i].name));
				eLink.href = 'index.php?route=product/product&product_id=' + result[i].product_id;
				eListElem.appendChild(eLink);
				eList.appendChild(eListElem);
			}
			$('#search').append(eList);
		}
	}});

	return true;
}
$(document).ready(function(){
	$('#filter_keyword').keyup(function(){
		doLiveSearch(this.value);
	}).focus(function(){
		doLiveSearch(this.value);
	}).blur(function(){
		window.setTimeout("$('#search_results').remove()", 1500);
	});
});
//]]>