var Ajax;
if (Ajax && (Ajax != null)) {
	Ajax.Responders.register({
	  onCreate: function() {
        if($('spinner') && Ajax.activeRequestCount>0)
          Effect.Appear('spinner',{duration:0.5,queue:'end'});
	  },
	  onComplete: function() {
        if($('spinner') && Ajax.activeRequestCount==0)
          Effect.Fade('spinner',{duration:0.5,queue:'end'});
	  }
	});
}

 $(document).ready(function() {
    $('.default-value').each(function() {
        var default_value = this.value;
        $(this).css('color', '#666'); // this could be in the style sheet instead
        $(this).focus(function() {
            if(this.value == default_value) {
                this.value = '';
                $(this).css('color', '#333');
            }
        });
        $(this).blur(function() {
            if(this.value == '') {
                $(this).css('color', '#666');
                this.value = default_value;
            }
        });
    });
    $("input#searchFor").autocomplete({
        source: function(request, response) {
            $.ajax({
               // url: "http://localhost:8080/WhereToEat/ajax/predictiveSearch",
               url: "http://www.wheretoeat.ie/ajax/predictiveSearch",
                dataType: "json",
                data: {
                    name_startsWith: request.term
                },
                success: function(data) {
                    response($.map(data, function(item) {
                        return {
                            label: item.name,
                            value: item.name,
                            title: item.id
                        }
                    }))
                }
            })
        }
    });
    $("input#searchLocation").autocomplete({
        source: function(request, response) {
            $.ajax({
                //url: "http://localhost:8080/WhereToEat/ajax/predictiveSearchLocation",
                url: "http://www.wheretoeat.ie/ajax/predictiveSearchLocation",
                dataType: "json",
                data: {
                    name_startsWith: request.term
                },
                success: function(data) {
                    response($.map(data, function(item) {
                        return {
                            label: item,
                            value: item,
                            title: item
                        }
                    }))
                }
            })
        },
        minLength: 2
    });
});

