$(document).ready(function () {
    
  var calendar = new Calendar();
  
  calendar.init();

  
});

function Calendar() {

  object = this;

  this.events = null;
  this.interval = null;
  this.delay = 1;

  this.init = function() {       
    
    // Get list of events
    this.events = $('.calendar-div .event');
    
    // Hide events
    // Set default image + active link
    $(this.events).each(function(i, val) {
        
        // How many cells are in the row before this one?
        var cellNum = $(val).prevAll().length;        
        
        // Hide event info
        $(val).children('.cal-txt').css("display", "none");
        
        // Mouse over
        $(val).mouseover( function() {
          clearTimeout(object.interval);
          
          // Change pop-up position if necessary
          if (cellNum >= 4) {
            $(this).children('.cal-txt').css('margin-left','-100px');
          }
          
          $(this).addClass('hover');
          $(this).children('.cal-txt').fadeIn('fast');
        });
        
        // Mouse out
        $(val).mouseout( function() {
          object.interval = setTimeout(function() {
              $(val).children('.cal-txt').fadeOut('fast', function() {
                $(val).removeClass('hover');
              });
            }, 1000);
        });
          
    });
    
  };
  
}


