$(document).ready(function() {
  firstThings();
  navigate();
  machineGallery();
  playerGallery();
  picGallery();
  });

function firstThings() {
  $('#about').hide();
  $('#msPinball').hide();
  $('#machines').hide();
  $('#players').hide();
  $('#gallery').hide();
  $('#machines ul:not(.showMe)').hide();
  $('#pinFall li:not(:first)').hide();
  $('#playerStats ul:not(:first)').hide();
  $('#gallery li:not(.galCurShow)').hide();
  }

function navigate() {
  $('#nav a').click(function(e) {
    var selected = $(this).attr('href');
    var selectMinus = selected.replace('#', '');
    var newLeft = 'images/bumper' + selectMinus + '.png';
    $('#trigger').stop(true).animate({marginTop: '+=260px'}, 2000, 'easeInCubic', function() {
      $('.curSect').fadeOut('slow', function() {
	$(selected).fadeIn('slow').addClass('curSect');
	$('#trigger').animate({marginTop: '0'}, 1000, 'easeOutElastic');
	$('#leftSide img').hide();
	$('#leftSide img').attr('src', newLeft).show();
        }).removeClass('curSect');
      });
    e.preventDefault();
    });
  $('#footer a:not(:first)').click(function(e) {
    var selected = $(this).attr('href');
    var selectMinus = selected.replace('#', '');
    var newLeft = 'images/bumper' + selectMinus + '.png';
    $('#trigger').stop(true).animate({marginTop: '+=260px'}, 2000, 'easeInCubic', function() {
      $('.curSect').fadeOut('slow', function() {
	$(selected).fadeIn('slow').addClass('curSect');
	$('#trigger').animate({marginTop: '0'}, 1000, 'easeOutElastic');
	$('#leftSide img').hide();
	$('#leftSide img').attr('src', newLeft).show();
        }).removeClass('curSect');
      });
    e.preventDefault();
    });
  }

function machineGallery() {
  $('#arrowRight').click(function(e) {
    var current = $('ul.showMe');
    var next = current.next('ul').length ? current.next('ul') : current.parent().children('ul:first');

    current.fadeOut('slow', function() {
      next.fadeIn('slow').addClass('showMe');
      }).removeClass('showMe');
    e.preventDefault();
    });
  $('#arrowLeft').click(function(e) {
    var current = $('ul.showMe');
    var prev = current.prev('ul').length ? current.prev('ul') : current.parent().children('ul:last');

    current.fadeOut('slow', function() {
      prev.fadeIn('slow').addClass('showMe');
      }).removeClass('showMe');
    e.preventDefault();
    });
  $('#arrowRight').hover(function() {
    $('#arrowRight img').attr('src', 'images/arrowRight01.png');
    },function() {
      $('#arrowRight img').attr('src', 'images/arrowRight.png');
      });
  $('#arrowLeft').hover(function() {
    $('#arrowLeft img').attr('src', 'images/arrowLeft01.png');
    },function() {
      $('#arrowLeft img').attr('src', 'images/arrowLeft.png');
      });
  }

function playerGallery() {
  $('#playersNav a').click(function(e) {
    var next = $(this).attr('class');
    $('#pin, #pinFall ul').animate({marginTop: '+=150px'}, 800, 'easeOutSine', function() {
      $('#playerStats ul').hide();
      $('#playerStats ul.' +next).show();
      $('#pinFall li').hide();
      $('#pinFall li.' + next).show();
      $('#pin').animate({marginTop: '0'}, 800, 'easeInSine');
      $('#pinFall ul').animate({marginTop: '30px'}, 800, 'easeInSine');
      });
    e.preventDefault();
    });
  }

function picGallery() {
  $('#picArrRight').click(function(e) {
    var current = $('li.galCurShow');
    var next = current.next().length ? current.next() : current.parent().children(':first');

    current.fadeOut('slow', function() {
      next.fadeIn('slow').addClass('galCurShow');
      }).removeClass('galCurShow');
    e.preventDefault();
    });
  $('#picArrLeft').click(function(e) {
    var current = $('li.galCurShow');
    var prev = current.prev().length ? current.prev() : current.parent().children(':last');

    current.fadeOut('slow', function() {
      prev.fadeIn('slow').addClass('galCurShow');
      }).removeClass('galCurShow');
    e.preventDefault();
    });
  $('#picArrRight').hover(function() {
    $('#picArrRight img').attr('src', 'images/arrowRight03.png');
    },function() {
      $('#picArrRight img').attr('src', 'images/arrowRight02.png');
      });
  $('#picArrLeft').hover(function() {
    $('#picArrLeft img').attr('src', 'images/arrowLeft03.png');
    },function() {
      $('#picArrLeft img').attr('src', 'images/arrowLeft02.png');
      });
  }
