function initMWMHeader() {
  theCanvas = document.getElementById('mwmBanner');
  theContext = theCanvas.getContext('2d');
  theHeaderBackground = new Image;
  theHeaderBackground.src = "/sites/all/themes/mumauwebmarketing/images/mwm-header-background.jpg";
  theAirplaneX = 1000;
  theAirplaneY = 1;
  theRotation = -.1;
  theScale = .001;
  theTimeScale = 1;
  x = theAirplaneX;
  y = theAirplaneY;
  width = theAirplane.width;
  height = theAirplane.height;
  theLoopCounter = 0;
  return true;
}

function drawAirplaneAnimation() {
  theLoopCounter++;
  theRotation = theRotation + .003;
  theContext.drawImage(theHeaderBackground, 0, 0);
  theContext.translate(x, y);
  theContext.rotate(theRotation);
  theContext.drawImage(theAirplane, -width / 2, -height / 2, width *theScale, height * theScale);
  theContext.rotate(-theRotation);
  theContext.translate(-x, -y);
  x = x - (8 * theTimeScale); 
  y = y + (.9 * theTimeScale);
  theScale = theScale + 0.01;
  theTimeScale = theTimeScale - 0.005;
  if (theLoopCounter < 300) { 
    setTimeout(function() {drawAirplaneAnimation();}, 30); 
  }
  return true;
}

function playSound() {
  theSound = document.getElementById('cessnaSound');
  theSound.play();
  return true;
}


$(document).ready(function(){   
  theAirplane = new Image;
  theAirplane.onload = function() {
    
    initMWMHeader();
    drawAirplaneAnimation();
    setTimeout(function() {playSound()}, 500);
    
  };
  theAirplane.src="/sites/all/themes/mumauwebmarketing/images/airplane.png";
});  



