function Hub() {
	this.gameOptions = ['fill', 'trace', 'dodge'];
	this.selectedGame;
	this.fingerStartButton;
	this.instructionText;
  this.muteButton;
}

Hub.prototype = {
  preload: function() {

  },
  create: function() {

    //start of a new round means start of new music
    if(FingerPuppets.numRounds == 0) {

      //if there's old music, stop it
      if(FingerPuppets.music) {
        FingerPuppets.music.stop();
      }

      //get a random musical thing
      var randomTrackNumber = Math.floor( Math.random() * FingerPuppets.musicOptions.length);
      FingerPuppets.music = this.add.audio(FingerPuppets.musicOptions[randomTrackNumber], 1, true);
      FingerPuppets.music.play();
    }

    if(FingerPuppets.numRounds >= FingerPuppets.totalRounds) {
      // Go to the "switch partner!" state
      this.game.state.start("switch");
      return;
    }

    //background for game
    this.add.sprite(0,0, "bg");

    this.fingerStartButton = this.add.sprite(this.game.width / 2, this.game.height / 2 , 'btnBlank');
    this.fingerStartButton.anchor.setTo(.5, .5);
    this.fingerStartButton.inputEnabled = true;
    this.fingerStartButton.events.onInputDown.addOnce(this.nextGame, this);

    //because NO ONE tweens scale, right?
    this.add.tween(this.fingerStartButton).from({alpha: 0}, 400, Phaser.Easing.Quartic.Out, true);
    this.add.tween(this.fingerStartButton.scale).from({x: .5, y: .5}, 400, Phaser.Easing.Exponential.Out, true);

  	//instructions
  	var style = { font: "65px LightUpTheWorld", fill: "#222", align: "center" };
    this.instructionText = this.add.text(this.world.centerX, this.world.centerY + 25, "Turn phone around\n\n\n\nTap here when ready\n", style);
    this.instructionText.anchor.setTo(.5, .5);

    style = { font: "30px LightUpTheWorld", fill: "#222", align: "center" };
    this.scoreText = this.add.text(this.world.centerX, this.world.centerY + 210, "Score: " + FingerPuppets.score, style);
    this.scoreText.anchor.setTo(.5, .5);

    style = { font: "40px LightUpTheWorld", fill: "#222", align: "center" };
    this.scoreText = this.add.text(this.world.centerX, this.world.centerY, "Round " + (FingerPuppets.numRounds + 1) + "/" + FingerPuppets.totalRounds, style);
    this.scoreText.anchor.setTo(.5, .5);

    this.add.tween(this.scoreText).from({alpha: 0}, 600, Phaser.Easing.Quartic.Out, true, 150);
    this.add.tween(this.scoreText.scale).from({x: .5, y: .5}, 600, Phaser.Easing.Exponential.Out, true, 150);

    //mute button
    if(this.sound.mute) {
      this.muteButton = this.add.sprite(610, 530, 'mute_active');
    } else {
      this.muteButton = this.add.sprite(610, 530, 'mute');
    }
    this.muteButton.inputEnabled = true;
    this.muteButton.events.onInputDown.add(this.toggleMute, this);

    //back ... button
    this.backButton = this.add.sprite(10, 530, 'btnBack');
    this.backButton.inputEnabled = true;
    this.backButton.events.onInputDown.add(this.goBack, this);
  },
  update: function() {

  },
  goBack: function() {
    FingerPuppets.score = 0;
    FingerPuppets.numRounds = 0;
    FingerPuppets.music.stop();
    this.game.state.start('menu');
  },
  toggleMute: function() {
    console.log("hi")
    if(this.sound.mute) {
      this.sound.mute = false;
      this.muteButton.loadTexture("mute");
    } else {
      this.sound.mute = true;
      this.muteButton.loadTexture("mute_active");
    }
  },
  nextGame: function() {
  		//get a random game to play next
  		var randomGameIndex = Math.floor(Math.random() * this.gameOptions.length);
  		this.selectedGame = this.gameOptions[randomGameIndex];
  		FingerPuppets.nextGame = this.selectedGame;
      FingerPuppets.numRounds++;
  		this.game.state.start("instructionsInterlude");
  }

};

module.exports = Hub;