'use strict';
var play;
var title;
var helper;
var bg;
var sponsors;
Game1.Menu = function() {};
 
  Game1.Menu.prototype = {
   
    create: function() {
    this.strona = new Audio("./sound/page.mp3");
    this.strona.load();     
      var style = { font: '70px Arial', fill: '#0080ca', align: 'center'};
      bg = this.game.add.sprite(0, 0, 'bg');
        this.boo = this.game.add.sprite(0,0,"book");
        //bg.scale.setTo(1/2,1/2);
        sponsors = this.game.add.sprite(0,458*2,'sponsors');
       // sponsors.scale.setTo(1/2,1/2);
      //this.sprite.anchor.setTo(0.5, 0.5);
    //this.sprite.scale.setTo(0.9,0.9);
        
   title = this.game.add.sprite(422, 158, 'title');
        //title.scale.setTo(1/2,1/2);
        helper = this.game.add.sprite(1366, 347, 'pomocnik');
       // helper.scale.setTo(1/2,1/2);
    //this.sprite.anchor.setTo(0.5, 0.5);
            
    //var button = new Phaser.Button(this.game,1302,516,'play_button', this.buttonCallback, this, 1,0,2);
      play = this.game.add.sprite(488,630,'play_button');
        play.inputEnabled =true;
        play.name = "play";
        play.events.onInputOver.add(this.over,this);
        play.events.onInputDown.add(this.down, this);
        play.events.onInputOut.add(this.out,this);
        // play = this.game.add.button(446/2,686/2,'play_button', this.actionOnClick, this,'','','');
        //play.scale.setTo(1/2,1/2);
        // play.onInputOver.add(1, this);
          //  play.onInputOut.add(2,this);
        
    //play =  this.game.add.sprite(446, 686, 'play_button');
   play.inputEnabled = true;
    play.animations.add('off',[0], true);
    play.animations.add('on',[1], true);
        
      
    //this.sprite.anchor.setTo(0.5, 0.5);
    
        //this.sprite = this.game.add.sprite(1302, 516, 'play_select');
    //this.sprite.anchor.setTo(0.5, 0.5);   
        
    //this.titleText = this.game.add.text(this.game.world.centerX, 400, 'Odkrywca świata', style);
    //this.titleText.anchor.setTo(0.5, 0.5);

    //this.instructionsText = this.add.text(this.game.world.centerX+200, 450                                            , 'tytul gry', { font: '40px Arial', fill: '#0080ca', align: 'right'});
    //this.instructionsText.anchor.setTo(0.5, 0.5);

      //this.sprite.angle = -20;
      //this.game.add.tween(this.sprite).to({angle: 20}, 1000, Phaser.Easing.Linear.NONE, true, 0, 1000, true);
    },
    //button.onInputOver.add(over, this);
   // button.onInputOut.add(out, this);  

onInputOver: function(sprite, pointer){
    
},
down: function(sprite, pointer) {
    this.strona.play();
    this.game.state.start('Game');
    //console.log('button down: '+sprite.name);
},      
over: function(sprite, pointer) {
    play.animations.play('on',1,true,false);
    console.log('button over'+sprite.name);
    if (!this.game.device.desktop)
        this.game.state.start('Game');
},

out: function(sprite, pointer) {
     play.animations.play('off',1,true,false);
    console.log('button out'+sprite.name);
},
      update: function() {
     // this.game.debug.text('this.camera.width: '+ this.camera.width+' this.camera.height: '+this.camera.height+ ' bg.width: '+bg.width,  20, 20);
         // if (play.input.pointerDown()){
        //   this.game.state.start('Game');
      // }
         /* if (play.input.pointerOver()){
          
              play.animations.play('on',1,true,false);
          }*/
 /*             else if  (!play.input.pointerOver()){
           play.animations.play('off',1,true,false);
                     }*/
 //  if (play.pointerDown()){actionOnClick()}
    },

actionOnClick: function() {
 this.game.state.start('Game');

}
  };