﻿jQuery(document).ready(function () {

    jQuery("input.search-phrase").focus(function () {
        if (jQuery(this).val() == "Hledat na procyklo.cz") {
            jQuery(this).val("");
        }
    });

    jQuery("input.search-phrase").blur(function () {
        if (jQuery(this).val().length == 0) {
            jQuery("input.search-phrase").val("Hledat na procyklo.cz");
        }
    });

    jQuery("input.search-phrase").autocomplete({
        source: function (request, response) {
            // Call webservice to get suggestions
            SearchService.GetSearchSuggestions(request.term, function (result) {
                //alert("Vysledky");
                response(jQuery.map(result, function (item) { return { Type: item.Type, Name: item.Name, value: item.Name, Url: item.Url} }))
            });
        },
        minLength: 3,
        change: function (event, ui) { }
    }).data("autocomplete")._renderItem = function (ul, item) {
        return jQuery("<li></li>")
				.data("item.autocomplete", item)
				.append("<a href=\"" + item.Url + "\"><span style=\"font-size:0.8em; font-weight:bold;\">" + item.Type + "</span><br>" + item.Name + "</a>")
				.appendTo(ul);
    };
});
