// Disabled for now.
//
// $(document).scroll(function() {
//     // 
//     // if($('#books').height() + $('#books').offset().top > $(window).height() + $(document).scrollTop())
//     // -  {
//     // -    count = 0;
//     // -    $('.book').each(function() {
//     // -      if($('#books').offset().top + $(this).offset().top > $(window).height() + $(document).scrollTop())
//     // -      {
//     // -        count++;
//     // -      }
//     // -    });
//   
//   // figure out which book is the top one
//   $('#books > ol > li').each(function(index, book) {
//     if(($(book).offset().top + $(book).height()) > ($(document).scrollTop() + 50))
//     {
//       $('#books > ol > li').removeClass('top');
//       $(book).addClass('top');
//       console.log($(book).find('h1').eq(0).html());
//       return false;
//     }
//   });
//   
// });

$(document).ready(function(){
  
  // User page
  
  $('.book').mouseenter(function() {
    id = $(this).attr('id').split('-')[1];
    $('.book').removeClass('hover');
    $('.book#book-'+id).addClass('hover');
  });
  
  $('.book').click(function(e) {
    
    if(e.target && $(e.target).parents('.peers').length > 0)
      return;
    
    $('.book:not(#book-'+id+')').removeClass('active');
    $('.book:not(#book-'+id+') .annotations').slideUp('fast');
    if($(this).hasClass('active'))
    {
      $('.book#book-'+id+'').removeClass('active');
      $('.book#book-'+id+' .annotations').slideUp('fast');
    }
    else
    {
      $('.book#book-'+id+'').addClass('active');
      $('.book#book-'+id+' .annotations').slideDown('fast');
    }
  });

  $('.book').mouseleave(function() {
    $('.book').removeClass('hover');
  });
  
  $('.bookmap > li').mouseenter(function() {
    id = $(this).attr('id').split('-')[1];
    $('#annotation-'+id).addClass('active');
  });
  
  $('.annotations > li').mouseenter(function() {
    id = $(this).attr('id').split('-')[1];
    $('#marker-'+id).addClass('active');
  });
  
  $('.bookmap > li').mouseleave(function() {
    $('.annotations > li').removeClass('active');
  });
  
  $('.annotations > li').mouseleave(function() {
    $('.bookmap > li').removeClass('active');
  });
  
  $('#peers li, .book .peers li').mouseenter(function() {
    
    $('.bookmap li[data-user-id="'+$(this).attr('data-user-id')+'"]').fadeIn();
  }); 

  $('#peers li, .book .peers li').mouseleave(function() {
    $('.bookmap li[data-user-id="'+$(this).attr('data-user-id')+'"]').fadeOut();
  }); 

  
});
