datepicker, onChangeMonthYear, beforeShowDay and ajax refresh problem

datepicker, onChangeMonthYear, beforeShowDay and ajax refresh problem


Hi.
First I post the code, than I'll explain what should do but it
doesn't.
var specialDays = [1,2];
function onBeforeShowDay(thedate)
{
    var theday = thedate.getDate();
    if( $.inArray(theday,specialDays) == -1 ) return [false,""];
    return [true, "specialDate", "tooltip"];
}
function onOnChangeMonthYear(year, month, inst)
{
    $.get("http://www.example.org/ajax/get-news/"+year+"/"+month, { },
function(json) {
        // alert(json.specialDays.length); test...ok
        specialDays = json.specialDays;
        $(inst).datepicker("refresh");
    },"json");
}
$(document).ready(function() {
    $.datepicker.setDefaults($.extend({showMonthAfterYear: false},
$.datepicker.regional['it']));
    $("#calendar").datepicker({
        onChangeMonthYear: onOnChangeMonthYear,
        beforeShowDay: onBeforeShowDay
     });
});
What I want to do is that when I change the month of the datepicker,
an ajax call is fired to get events for that month and returned in a
json fashion way. In the same way an array with a list of days to be
highlighted is returned.
What it doesn't work is that since the ajax callback may be fired a
bit later of the end of onChangeMonthYear, and so the new list of the
special days is not arrived yet, I need to refresh the datepicker when
it happens to reflect the new beforeShowDay, and I use:
$(inst).datepicker("refresh");
I found it here, undocumented feature to refresh/redraw the
datepicker, but id doesn't work, the month changes but the new special
days are not highlighted.
Any help? Thank you very much.