var bannerOffset = 360;

$(document).ready(function(){
  
  var hand = $('#hand');
  var banner = $('#banner');
  var stage = $('#stage');
  
  $(document).mousemove(function(e){
    hand.css({ left: (e.clientX > 418 ? ((e.clientX > 480) ? (418 * (1 - ((e.clientX - 480) / (stage.width() - 480)))) - 428 : -10) : e.clientX - 433) + 'px' });
    banner.css({ top: (e.clientY > bannerOffset ? ((e.clientY > bannerOffset + 8) ? (bannerOffset * (1 - ((e.clientY - bannerOffset) / (stage.height() - bannerOffset)))) - 71 : bannerOffset - 80) : e.clientY - 80) + 'px' });
    return false;
  });
  
  $('#button').click(function(){
    $('#button').unbind('click');
    $(document).unbind('mousemove');
    $('#beam').css({ opacity: 0, width: 0 });
    banner.fadeOut();
    hand.animate({ left: 0 }, function(){
      $('#beam').animate({ opacity: 1, width: 1079 }, function(){
        $('.textfield').focus();
        $('#button img').attr('src', 'images/button_beam.png');
      });
    });
    return false;
  });
  
  $('form').submit(function(){
    $('#submit').hide();
    $.post('index.php', $(this).serializeArray(), function(data){
      if (data == '1')
      {
        $('#form').fadeOut();
        $('#logo').animate({ bottom: 20 }, {duration: 1500, easing: 'easeOutBounce'});
        $('#done').fadeIn();
      }
      else
      {
        $('#submit').show();
        $('.textfield').val('');
      }
    });
    return false;
  });
  
  $(window).resize(function(){
    h = $('#stage').height();
    if (h > 730)
      d = (h / 2);
    else
      d = h - 365;
      
    $('#button').css({ top: d - 86 });
    hand.css({ top: d - 100 });
    $('#beam').css({ top: d - 334 });
    bannerOffset = d - 30;
  });
  
  $(window).resize();
  setTimeout('$(window).resize();', 100);
});