$(function() {
  $('a[rel=external]').click(function() {
    var newWindow = window.open($(this).attr('href'), '_blank');
    if(newWindow) { if(newWindow.focus) { newWindow.focus(); return false; } }
    newWindow = null;
  });


  var emailAddress = $('#email_address').text().replace(' [at] ', '@').replace(' [dot] ', '.');
  var emailLink    = '<a href="mailto:' + emailAddress + '">' + emailAddress + '</a>';

  $('#email_address').html(emailLink).parents('div:first').find('h2').html(emailLink);
  $('#contact h2 a').text('Email');

  
  var animating = false;

  function setupBike() {
    var bike = $('#bike');

    // bike.click(function() {
    //   if(animating) { return; }
    //   animating = true;
    //   $(this).animate({
    //     left: $(window).width() + "px"
    //   }, 600, 'swing', repositionBike);
    // });
    
    // bike.animate({ left: '-155px' });
    animating = false;
  }

  function repositionBike() {
    var bike = $('#bike').remove();
    var sections = $('.section');
    var randomNumber = Math.floor(sections.length*Math.random());
     
    $(sections[randomNumber]).append('<div id="bike"></div>');
    //setupBike();
  }

  setupBike();
});
