var aqua = {

  init: function() {
    this.fixHalfdotHeight();
    this.resizeHandler();
    this.preloadImages();
    this.attachLightbox();
    this.galleryHoverPreview();
    this.eventHoverPreview();
    this.facebookShare();
    this.quickFixes();
    this.ieCalendarHoverFix();
  },

  fixHalfdotHeight: function() {
    var docHeight = $(document).height();
    $('#halfdot').height(docHeight);
  },

  resizeHandler: function() {
    $(window).resize(function() {
      aqua.fixHalfdotHeight();
    });
  },

  preloadImages: function() {
    if (typeof preloads !== 'undefined') {
      var images = [];
      preloads = eval(preloads);
      $.each(preloads, function(i, val) {
        var image = $('<img />');
        image.attr('src', val);
        images.push(image);
      });
    }
  },

  attachLightbox: function() {
    $('#gallery ul a.lightbox').lightBox();
  },

  galleryHoverPreview: function() {
    $('#gallery_listing li a').each(function() {
      $(this).mouseenter(function() {

        $('#gallery_listing li a').parent().removeClass('active');
        $(this).parent().addClass('active');

        var rel = $(this).attr('rel');
        var href = $(this).attr('href');
        $('#latest_gallery .media_placeholder img').attr('src', rel);
        $('#latest_gallery .media_placeholder a').attr('href', href);
      });
    });
  },

  eventHoverPreview: function() {
    $('#body_event_homepage #upcoming_events td a').each(function() {
  
      $(this).mouseenter(function() {
        var rel = $(this).attr('rel');
        var rev = $(this).attr('rev');
        var href = $(this).attr('href');
        $('#featured_event').css('backgroundImage', 'url('+rel+')');
        $('#text_overlay').css('backgroundImage', 'url('+rev+')');
        $('#text_overlay h3 a').attr('href', href);
      });
  
    });
  },

  facebookShare: function() {
    $('#fb_share').click(function() {
      var u = location.href;
      var t = document.title;
      window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
      return false;
    });
  },

  quickFixes: function() {
    $('#event_more_info p:last-child, #program_info p:last-child, #location_more_info p:last-child').css('paddingBottom', '0');
  },

  ieCalendarHoverFix: function() {
    if (typeof ie6 !== 'undefined' && ie6 === true) {
      $('#calendar td').mouseenter(function(){
        $(this).addClass('hover');
      });

      $('#calendar td').mouseleave(function(){
        $(this).removeClass('hover');
      });
    }
  }

};

$(document).ready(function() {
  aqua.init();
});

