//(function () {

//  Create your Phaser game and inject it into the gameContainer div.
//  We did it in a window.onload event, but you can do it anywhere (requireJS load, 
//anonymous function, jQuery dom ready, - whatever floats your boat)
if (typeof require !== 'undefined') {
    var gui = require('nw.gui');        
}
var game;

function initPhaser(renderer) {
    game = new Phaser.Game(960,960, renderer || Phaser.AUTO, window, undefined,undefined,false);

    //TODO: Also check saveversion
    var newSave = Pichon.SaveManager.convertSave( localStorage['savedData'] );
    game.persistent = Pichon.SaveManager.getSave();

    //set language
    game.persistent.language = navigator.language && navigator.language.substring(0,2);
    if (game.persistent.language !== 'ja' && game.persistent.language !=='es') {
    	game.persistent.language = 'en';
    }

    //  You don't have to do this in the html, it could be done in your Boot state too, but for simplicity I'll keep it here.
    game.state.add('Boot', Pichon.Boot);
    game.state.add('Preloader', Pichon.Preloader);
    game.state.add('MainMenu', Pichon.MainMenu);
    game.state.add('LevelSelection', Pichon.LevelSelection);
    game.state.add('Game', Pichon.Game);
    game.state.add('Win', Pichon.Win);
    game.state.add('Credits', Pichon.Credits);
    game.state.add('EndCredits', Pichon.EndCredits);

    //  Now start the Boot state.
    game.state.start('Boot');
}

initPhaser(Phaser.AUTO);
//}());
