
var game = new Phaser.Game(1024, 768, Phaser.CANVAS, 'seven-circles', {preload: preload, create: create});

function preload() {

    game.load.image('background', 'assets/images/background-home.png');
    game.load.image('title', 'assets/images/title-home.png');

    game.load.image('popupEasterFight', 'assets/popups/popupEasterFight.png');
    game.load.image('popupNestinarsRun', 'assets/popups/popupNestinarsRun.png');
    game.load.image('popupCrossRun', 'assets/popups/popupCrossRun.png');

    game.load.spritesheet('easterFight', 'assets/buttons/easterFight.png', 204, 206, 2);
    game.load.spritesheet('nestinarsRun', 'assets/buttons/nestinarsRun.png', 204, 206, 2);
    game.load.spritesheet('crossRun', 'assets/buttons/crossRun.png', 204, 206, 2);

    game.load.spritesheet('playButton', 'assets/buttons/play.png', 210, 69, 2);
    game.load.spritesheet('playButtonNestinars', 'assets/buttons/play.png', 210, 69, 2);
    game.load.spritesheet('playButtonCross', 'assets/buttons/play.png', 210, 69, 2);

    game.load.image('locked1', 'assets/buttons/locked.png');
    game.load.image('locked2', 'assets/buttons/locked.png');
    game.load.image('locked3', 'assets/buttons/locked.png');
    game.load.image('locked4', 'assets/buttons/locked.png');

}

function create() {
    game.add.sprite(0, 0, 'background');
    title = game.add.sprite(game.world.centerX, 31, 'title');
    title.anchor.setTo(0.5, 0);

    easterFight = game.add.button(game.world.centerX, game.world.centerY + 42, 'easterFight', actionOnEasterFight, this, 1, 0, 0);
    easterFight.anchor.setTo(0.5, 0.5);
    nestinarsRun = game.add.button(132, 226, 'nestinarsRun', actionOnNestinarsRun, this, 1, 0, 0);
    crossRun = game.add.button(684, 233, 'crossRun', actionOnCrossRun, this, 1, 0, 0);

    game.add.sprite(112, 441, 'locked1');
    game.add.sprite(295, 564, 'locked2');
    game.add.sprite(511, 563, 'locked3');
    game.add.sprite(692, 441, 'locked4');


    popupEasterFight = game.add.sprite(game.world.centerX, game.world.centerY, 'popupEasterFight');
    popupEasterFight.anchor.set(0.5);
    popupEasterFight.alpha = 0;
    popupEasterFight.scale.set(0.1);
    var pw = (popupEasterFight.width / 2) - 135;
    var ph = popupEasterFight.height - 265;
    var playButton = game.make.sprite(pw, -ph, 'playButton');
    playButton.inputEnabled = true;
    playButton.input.priorityID = 1;
    playButton.input.useHandCursor = true;
    playButton.events.onInputDown.add(playEasterFight, this);
    popupEasterFight.addChild(playButton);

    popupNestinarsRun = game.add.sprite(game.world.centerX, game.world.centerY, 'popupNestinarsRun');
    popupNestinarsRun.anchor.set(0.5);
    popupNestinarsRun.alpha = 0;
    popupNestinarsRun.scale.set(0.1);
    var pw = (popupNestinarsRun.width / 2) - 135;
    var ph = popupNestinarsRun.height - 265;
    var playButtonNestinars = game.make.sprite(pw, -ph, 'playButtonNestinars');
    playButtonNestinars.inputEnabled = true;
    playButtonNestinars.input.priorityID = 1;
    playButtonNestinars.input.useHandCursor = true;
    playButtonNestinars.events.onInputDown.add(playNestinarsRun, this);
    popupNestinarsRun.addChild(playButtonNestinars);

    popupCrossRun = game.add.sprite(game.world.centerX, game.world.centerY, 'popupCrossRun');
    popupCrossRun.anchor.set(0.5);
    popupCrossRun.alpha = 0;
    popupCrossRun.scale.set(0.1);
    var pw = (popupCrossRun.width / 2) - 135;
    var ph = popupCrossRun.height - 265;
    var playButtonCross = game.make.sprite(pw, -ph, 'playButtonCross');
    playButtonCross.inputEnabled = true;
    playButtonCross.input.priorityID = 1;
    playButtonCross.input.useHandCursor = true;
    playButtonCross.events.onInputDown.add(playCrossRun, this);
    popupCrossRun.addChild(playButtonCross);

}

function playEasterFight() {
    window.location.href = "./EasterFight/";
}

function playNestinarsRun() {
    window.location.href = "./Runs/";
}

function playCrossRun() {
    window.location.href = "./Runs/?level=water";
}

function actionOnEasterFight() {
    game.add.tween(popupEasterFight).to({alpha: 1}, 500, "Linear", true);
    tween = game.add.tween(popupEasterFight.scale).to({x: 1, y: 1}, 1000, Phaser.Easing.Elastic.Out, true);
}

function actionOnNestinarsRun() {
    game.add.tween(popupNestinarsRun).to({alpha: 1}, 500, "Linear", true);
    tween = game.add.tween(popupNestinarsRun.scale).to({x: 1, y: 1}, 1000, Phaser.Easing.Elastic.Out, true);
}

function actionOnCrossRun() {
    game.add.tween(popupCrossRun).to({alpha: 1}, 500, "Linear", true);
    tween = game.add.tween(popupCrossRun.scale).to({x: 1, y: 1}, 1000, Phaser.Easing.Elastic.Out, true);
}









