if(typeof FoodPrints=="undefined"||!FoodPrints){
	var FoodPrints={};
}
function boldify(m){
    return '<b>'+m+'<\/b>';
}

function stringToRegExp(pattern, flags){
    return new RegExp(
        pattern.replace(/[\[\]\\{}()+*?.$^|]/gi, function(m){return '\\'+m;}),
        flags);
}

FoodPrints.autoComplete = function() {
    // Use an XHRDataSource
    var oDS = new YAHOO.util.XHRDataSource("/get");
    // Set the responseType
    oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
    // Define the schema of the delimited results
    oDS.responseSchema = {
        recordDelim: "\n",
        fieldDelim: "\t"
    };
    // Enable caching
    oDS.maxCacheEntries = 5;
    // Instantiate the AutoComplete
    var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);
    oAC.formatResult = function(oResultItem, sQuery) { 
    	
    	var result = oResultItem[0].replace(stringToRegExp(sQuery, 'i'), boldify)
        return result;//'<a href="/facts/'+result+'">'+result+"</a>";
    };     
    oAC.itemSelectEvent.subscribe(function(sType, aArgs){ 
    	window.location = "/facts/"+aArgs[2]
    });     
    return {
        oDS: oDS,
        oAC: oAC
    };
};
