var game;

window.FingerPuppets = {
  score: 0,
  numRounds: 0,
  totalRounds: 5,
  nextGame: "",
  music: {},
  musicOptions: [ "dodgeMusic", "drawingMusic", "somethingMusic" ],
  gameOptions: {
    dodge: {
      instructions: "DODGE!",
      state: "dodge"
    },
    trace: {
      instructions: "TRACE!",
      state: "drawings"
    },
    fill: {
      instructions: "FILL!",
      state: "drawings"
    }
  }
};

window.TARGET_WIDTH = 800;
window.TARGET_HEIGHT = 600;


window.onload = function () {
  game = new Phaser.Game(TARGET_WIDTH, TARGET_HEIGHT, Phaser.AUTO, 'game');
  game.state.add('boot', require("./states/Boot.js"));
  game.state.add('preload', require("./states/Preload.js"));
  game.state.add('menu', require("./states/Menu.js"));
  game.state.add('drawings', require("./states/Drawings.js"));
  game.state.add('dodge', require("./states/Dodge.js"));
  game.state.add('picker', require("./states/Picker.js"));
  game.state.add('hub', require("./states/Hub.js"));
  game.state.add('howto', require("./states/Howto.js"));
  game.state.add('about', require("./states/About.js"));
  game.state.add('switch', require("./states/Switch.js"));
  game.state.add('instructionsInterlude', require("./states/InstructionsInterlude.js"));
  game.state.start('boot');


  document.body.addEventListener('touchmove', function(e){ e.preventDefault(); }, false);
};

function resizeGame(nw, nh) {
  game.scale.pageAlignHorizontally = true;
  game.scale.pageAlignVertically = true;

  if (game.renderType === Phaser.WEBGL)
  {
    game.renderer.resize(nw, nh);
  }

  var newScale = Math.min(nw / TARGET_WIDTH, nh / TARGET_HEIGHT);
  game.scale.setUserScale(newScale, newScale);
  game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE;
  game.scale.setGameSize(TARGET_WIDTH, TARGET_HEIGHT);
  game.scale.setScreenSize();
  game.scale.refresh();
}

window.onresize = function() {
  var newWidth = document.documentElement.clientWidth;
  var newHeight = document.documentElement.clientHeight;
  resizeGame(newWidth, newHeight);
}