title: using datepicker('refresh') on ajax success and inline datepicker's beforeShowDay?
body: <p>I'm using jquery and jquery ui 1.8.7.  I'm creating an inline datepicker when the page loads, then in my ajax success function, I'm calling $('#mydiv').datepicker('refresh'); (I'll post code below).  </p>
  
  <p>If the data has been returned from ajax (eg. on the refresh), beforeShowDay calls the highlightDays() function.  I know that I'm hitting highlightDays with the correct data twice before everything crashes to a halt and I get an error "TypeError: Cannot read property 0 of undefined".</p>
  
  <p>It seems like the events array is being destroyed after a certain amount of time, but I don't know enough about ajax to really say what's happening.  Can anyone point me in the right direction to fix this?</p>
  
  <pre><code>        function highlightDays(date) {
                  var day = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
                  console.log(typeof(events)); // This will return as an object twice before throwing an the above mentioned error
                  if($.inArray(day, events) !== -1) {
                      return new Array(true, '');
                  } else {
                      return new Array(false, '');
                  }   
          }    
          function getEventData() {
                  return $.ajax({
                      url: Drupal.settings.basePath + 'correct_path', 
                      data: search+'&amp;path='+window.location.pathname,
                      dataType: 'json',
                      type: 'POST',
                      success: function(data, textStatus, jqXHR) {        
                          // save our returned data
                          events = new Object();
                          events = data;
                          $('#mydiv').datepicker("refresh");
                      }
                  });
              }   
  
          function createDatepicker() {
  
              // Attach datepicker to the parent div so it returns as 
              // inline.
              $('#mydiv').datepicker({
                  dateFormat: 'yy-mm-dd',
                  speed: 'immediate',
                  altField: '#edit-date-filter-value-datepicker-popup-1',
                  beforeShowDay: function(date) {
                        if(typeof (_event_days) === 'undefined') {
                          return new Array(true, '');
                        } else {
                              highlightDays(date);
                          }
                      },
              });
              $('#myinput').hide();
          }   
  getEventData();
  createDatepicker();
  </code></pre>