/*
FoodFinder uses Ajax to find a food from the given string/substring.
The returned information is stored as foodInfo and is available to anyone
who is listening for the selection event.
*/
function FoodFinder (inputElemId, dropDownDivId, selectionCB) {
try {
	var thisObj = this;
	this.ffUrl = "find_food_jq.jsp";
	this.ffId = inputElemId;
	this.ffSuggestionsId = dropDownDivId;
	this.selectionCB = selectionCB;
	this.foodInfo = null;
	this.YAC = this.getYAC();
} catch (ex) {
	alert(ex);
}
}

function _getYAC () {
	var thisObj = this;
	var options = { select: this.selectionCB, source: this.ffUrl, minLength: 3, maxHeight: 300, delay: 300 }
	var ac = $("#" + this.ffId).autocomplete(options);

	// change the return type info to what the food finder url will return.
	// i.e, JSON format Results[name][id][ssUnits].
/*
	yac.oDS.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;

	yac.oAC.resultTypeList = false;
	yac.oDS.responseSchema = {
        resultsList : "Results",
		fields : ["fdAliasName", "fdAliasId", "fdUrl", "servingUnits","ssInfo", "ssNi"]  
    };
*/

/*
	To format the results...
	yac.oAC.formatResult = function(oResultData, sQuery, sResultMatch) { 
		alert(sResultMatch);
	    var sMarkup = (sResultMatch) ? sResultMatch : ""; 
	    return sMarkup; 
	}; 
*/

	// Set the itemSelectEvent callback...
	// yac.oAC.itemSelectEvent.subscribe(this.selectionCB);
	return ac;
}

function _getFoodInfo() {
	return this.foodInfo;
}


FoodFinder.prototype.getYAC = _getYAC;
FoodFinder.prototype.getFoodInfo = _getFoodInfo;

	

