function eventsCalInit(){
  $("#events-calendar-body a").hover(function(){
    //get hidden events for the day and display them
    var showEvents = $(this).next("div.events-calendar-hide").html();
    $("div#events-calendar-display").html(showEvents);
  },
  function(){
    //doesn't need to do anything on mouse out
  });
  
  $("td.events-calendar-eventday a").click(function(){
    return false;
  });
  
  $("a.events-calendar-move").click(function(){    
    //get target month
    var getTarget = $(this).attr("href");
    var goYearMonth = getTarget.substr(getTarget.indexOf("#")+1);
    
    //use loading graphic
    var loadingGif = $("<img id='events-calendar-loading' src='/images/sd6-loading.gif' height='30' width='30' alt='Loading...'/>");
    $("div#events-calendar").replaceWith(loadingGif);
    

    $.post("calendar.php",{calGoTo: goYearMonth},
      function(data){
        //put new cal div after old cal
        var newCal = $(data);
        loadingGif.after(newCal);
        newCal.hide();
        
        //fade out current cal, replace with new one
        loadingGif.fadeOut("slow",function(){
          loadingGif.remove();
          newCal.fadeIn("slow",function(){
            //bind events to new cal links
            eventsCalInit();
          });
        });
      });
    return false;
  });  
}

$(document).ready(function(){
  eventsCalInit();
});