$(document).ready(function() {
    clearField(".container-home");
    $("#search_field").autocomplete({
        source: function(request, response) {
            $.ajax({
                //                url: "http://google.com/complete/search?output=toolbar&q=" + request.term,
                url: "http://suggestqueries.google.com/complete/search?qu=" + request.term,
                dataType: "jsonp",
                //                dataType: "xml",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 7,
                    name_startsWith: request.term
                },
                success: function(data) {
                    //                    alert(data[1][6][0]);

                    response($.map(data[1], function(item) {
                        return {
                            label: item[0],
                            value: item[0]
                        }
                    }));
                }
            });
        },
        minLength: 2,
        position:{my:"left bottom",at:"left top",collision:"none"}
    });

});

function clearField(form) {
    $(form).find("input").each(function() {
        this.defaultValue = this.value;
        $(this).click(function() {
            if (this.value == this.defaultValue) {
                $(this).val("");
            }
            return false;
        });
        $(this).blur(function() {
            if (this.value == "") {
                $(this).val(this.defaultValue);
            }
        });
    });
}
