// Run the following code when the DOM has been fully loaded.
$(document).ready(function () {
  // Attach some code to the click event for the
  // link with class "lib-schedule-tool-previous".
  $('a.lib-schedule-tool-previous').click(function () {
    // When clicked, first define an anonymous function
    // to the variable voteSaved.
    var showSchedule = function (data) {
      // Update the number of votes.
      $('div#lib-class-schedule-data').html(data.schedule);
      // Update the previous button to point to the week prior.
      $('a.lib-schedule-tool-previous').attr('href', data.previous);
      // Update the next button to point to the next week.
      $('a.lib-schedule-tool-next').attr('href', data.next);
      // Update the showing dates to match the new dates being used
      $('span#schedule_range').html(data.range);
    }
    // Make the AJAX call; if successful the
    // anonymous function in voteSaved is run.
    $.ajax({
      type: 'POST',       // Use the POST method.
      url: this.href,
      dataType: 'json',
      success: showSchedule,
      data: 'js=1'        // Pass a key/value pair.
    });
    // Prevent the browser from handling the click.
    return false;
  });
  $('a.lib-schedule-tool-next').click(function () {
    // When clicked, first define an anonymous function
    // to the variable voteSaved.
    var showSchedule = function (data) {
      // Update the number of votes.
      $('div#lib-class-schedule-data').html(data.schedule);
      // Update the previous button to point to the week prior.
      $('a.lib-schedule-tool-previous').attr('href', data.previous);
      // Update the next button to point to the next week.
      $('a.lib-schedule-tool-next').attr('href', data.next);
      // Update the showing dates to match the new dates being used
      $('span#schedule_range').html(data.range);
    }
    // Make the AJAX call; if successful the
    // anonymous function is run.
    $.ajax({
      type: 'POST',       // Use the POST method.
      url: this.href,
      dataType: 'json',
      success: showSchedule,
      data: 'js=1'        // Pass a key/value pair.
    });
    // Prevent the browser from handling the click.
    return false;
  });
  $('#calendarFooter a').click(function() {
    //select today
    $('#datepicker').datepicker('setDate','+0');
    //then click it
    DP_jQuery.datepicker._selectDay('#datepicker', $.datepicker.formatDate('m',$('#datepicker').datepicker('getDate')),$.datepicker.formatDate('yy',$('#datepicker').datepicker('getDate')),$('.ui-datepicker-today'));
    return false;
  });
});
