$(function(){
  $('.overlay-right a').click(function(e){
    e.preventDefault();
    $('.overlay-left').fadeIn();
    $('#content').animate({
      scrollLeft: $('#content').scrollLeft() + 308
    });
  });
  
  $('.overlay-left a').click(function(e){
    e.preventDefault();
    if(($('#content').scrollLeft() - 308) <= 0) {
      $('.overlay-left').fadeOut();
    }
    $('#content').animate({
      scrollLeft: $('#content').scrollLeft() - 308
    });
  });
  
  $('.scroll a').click(function(e){
    e.preventDefault();
    if($(new RegExp('(#.+)$').exec(this.href)[1]).position().left <= 0) {
      $('.overlay-left').fadeOut();
    } else {
      $('.overlay-left').fadeIn();
    }
    $('#content').animate({
      scrollLeft: $(new RegExp('(#.+)$').exec(this.href)[1]).position().left
    });
  });
});
