(function(window,undefined){
  // TODO: livequery not needed below now that we are no longer an SPA.
	$(function(){
//    $('.menu').gmenu();

    $("#loading_message").ajaxStart(
      function() {
        $(this).show();
      }).ajaxStop(function() {
        $(this).hide();
      });

    $("#home_sections").livequery(function() {
      $(this).accordion({
        autoHeight: false
      }).accordion();
    });

    $(".accordion").livequery(function() {
      $(this).accordion({
        autoHeight: false,
        collapsible: true
      }).accordion("activate", false);
    });

    $(".colorbox").livequery(function() {
      $(this).colorbox({
        initialWidth: "800px",
        innerWidth: "800px",
        initialHeight: "600px",
        innerHeight: "600px"
      });
    });

    $(".calendarColorbox").livequery(function() {
      $(this).colorbox({
        initialWidth: "800px",
        innerWidth: "800px",
        initialHeight: "600px",
        innerHeight: "600px",
        onComplete: function() {
          $('#calendar').fullCalendar('render');
        }
      });
    });

    $('#calendar').livequery(function() {
      $(this).fullCalendar({
        theme: true,
        height: 560,
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,basicWeek'
        },
        editable: false,
        events: "/schedule/calendar"//,
//        loading: function(bool) {
//          if (bool) $('#loading').show();
//          else $('#loading').hide();
//        }
      });
    });

    $("#findPerson").livequery(function() {
      $(this).autocomplete({
        source: "/people/list",
        minLength: 3,
        select: function(event, ui) {
          $("#people-list").load('/people/' + ui.item.id + '/results');
        }
      });
    });

    $("body").on("click", "#person_results_years a", function () {
      $("#people-list").load(this.href);
      return false;
    });

    //Open off-site links in a new window/tab.
    $("a").livequery(function() {
      $(this).filter(function() {
        return this.hostname && this.hostname !== location.hostname;
      }).attr('target', '_blank');
    });

	}); // end onDomLoad
})(window); // end closure
