var account = 'yquestion';
var host = 'ced02.search.cnb.yahoo.com';
var openresty = null;

$(window).ready(init);

function init () {
    openresty = new OpenResty.Client(
        { server: host, user: account + '.Public' }
    );
}

function lookup(inputString) {
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $('#suggestions').hide();
    } else {
        openresty.callback = renderList;
        openresty.get('/=/view/getquery/spell/' +
                encodeURIComponent(inputString)
        );
    }
} // lookup

function renderList (res) {
    if (openresty.isSuccess(res)) {
        if (res.length >0) {
            $('#suggestions').show();
            var html = '<ul>';
            for (var i = 0; i < res.length; i++)
                html += '<li>' + res[i].query + '</li>';
            html += '</ul>';
            $('#autoSuggestionsList').html(html);
        } else {
            $('#suggestions').hide();
        }
    }
}

function fill (thisValue) {
        $('#inputString').val(thisValue);
        setTimeout("$('#suggestions').hide();", 200);
}

