$(document).ready(function() {
  
  $('.book').each(function() {
    
    var $$ = $(this);
    var kids = $$.children('.book-info');    
    
    $$.hover(
      function() {
        kids.fadeIn(150);
      },
      function() {
        kids.fadeOut(150);
      }
    );
    
    kids.hide();
    
  });
  
  
  $('.event').each(function() {
    
    var $$ = $(this);
    var img = $$.find('.event-images ul li');
    var key = 0;
    
    img
      .css({
        'float': 'left'
      })
      .parent()
      .css({
        'width': 460 * img.length
      })
      .parent()
      .css({
        'overflow': 'hidden'
      });
    
    var prev = $('<a href="#">Previous</a>')
      .click(function() {
        key--;
        key = (key < 0) ? img.length - 1 : key;
        
        img.parent().animate({
          marginLeft: -460 * key + 'px'
        }, 800, 'easeInOutQuad');
        
        return false;
      });
    
    var next = $('<a href="#">Next</a>')
      .click(function() {
        key++;
        key = (key > img.length - 1) ? 0 : key;
        
        img.parent().animate({
          marginLeft: (-460 * key) + 'px'
        }, 800, 'easeInOutQuad');
        
        return false;
      });
    
    var p = $('<p></p>')
      .append(img.length + ' image' + ((img.length > 1) ? 's' : '') + '<br />')
      .append(prev)
      .append(' / ')
      .append(next);
    
    $$.find('.event-info').append(p);
    
  });
  
});
