var scheduleXML = $.ajax({ type: "GET", url: "program.php", async: false }).responseXML;

var months = new Array('january','february','march','april','may','june','july','august','september','october','november','december');
var sections = new Array("brass","dance","gala","honours","piano","speech","strings","vocal");
var noInfoMsg = "No program information available.";

function initHover(section) {
  var elem1 = "#calendars table td."+section, elem2 = "#legend tbody tr."+section;

  $(elem1).hover(
    function () {
      $(this).addClass("highlight");
      $(elem2).addClass("highlight");

//      var dayXML = $(scheduleXML).find("day[month="+(1+jQuery.inArray($(this).closest("table").find("caption").text().toLowerCase(), months))+"][date="+$(this).children().text()+"]");

//      if(dayXML.size() > 0) {
//        $("#tooltip div").html(dayXML.eq(0).text());
//      } else {
//        $("#tooltip div").text(noInfoMsg);
//      }

//      var leftSide = $(this).offset().left+$(this).width()+$("#tooltip").outerWidth() > $(window).width();
//      var posString = leftSide ? "center left" : "center right";
//      $("#tooltip").toggleClass("leftTip", leftSide);

//      $(this).tooltip({ 
//       tip: '#tooltip',
//       opacity: 0.95,
//       position: posString, 
//       delay: 0
//      });

    }, 
    function () {
      $(this).removeClass("highlight");
      $(elem2).removeClass("highlight");
    }
  );

  $(elem2).hover(
    function () {
      $(this).toggleClass("highlight");
      $(elem1).toggleClass("highlight");
    }, 
    function () {
      $(this).toggleClass("highlight");
      $(elem1).toggleClass("highlight");
    }
  );

}

$(document).ready(function () {
  for(var i=0; i<sections.length; i++)
    initHover(sections[i]);
});
