YAHOO.namespace("search");
YAHOO.search.selectEventHandler = function(sType, aArgs) {
    location.href = aArgs[2][1].ClickURL;
}

function ACJson() {
    // Instantiate an XHR DataSource and define schema as an array:
    //     ["Multi-depth.object.notation.to.find.a.single.result.item",
    //     "Query Key",
    //     "Additional Param Name 1",
    //     ...
    //     "Additional Param Name n"]
    this.oACDS = new YAHOO.widget.DS_XHR("/search_json.php", ["ResultSet.Result","Title"]);
    this.oACDS.queryMatchContains = true;
    this.oACDS.scriptQueryAppend = ""; // Needed for YWS

    // Instantiate AutoComplete
    this.oAutoComp = new YAHOO.widget.AutoComplete("search-query","search-container", this.oACDS);
    this.oAutoComp.useShadow = true;
    this.oAutoComp.formatResult = function(oResultItem, sQuery) {
        return "<a href=\"" + oResultItem[1].ClickURL + "\"><strong>" 
            + oResultItem[1].Title + "<\/strong>" 
            + " " + oResultItem[1].Summary + "<\/a>";
    };
    this.oAutoComp.doBeforeExpandContainer = function(oTextbox, oContainer, sQuery, aResults) {
        var pos = YAHOO.util.Dom.getXY(oTextbox);
        pos[1] += YAHOO.util.Dom.get(oTextbox).offsetHeight + 2;
        YAHOO.util.Dom.setXY(oContainer,pos);
        return true;
    };
    this.oAutoComp.itemSelectEvent.subscribe(YAHOO.search.selectEventHandler);
};
function init() {
    var acJson = new ACJson(); 
}
YAHOO.util.Event.onDOMReady(init);

