'use strict';
// JavaScript Document

/*
    Stage : TITLE

    @param game ... Game Object
    @return scene ... Scene Object
*/
function SceneTitle(game) {

    var FONT_SCORE = "bold 24px 'ＭＳ 明朝', 'ＭＳ ゴシック', 'Times New Roman', serif, sans-serif";

    var scene = new Scene();
    // BGM
    var bgmTitle = CreateFadeBGM(game, 'pz_title.mp3');
    bgmTitle.fadePlay();

    gameResult = GAMERESULT_TITLE;

    var WIDTH = SCREEN_WIDTH;
    var HEIGHT = SCREEN_HEIGHT;

    var logo = new Label();
    logo.font = FONT_SCORE;
    logo.color = 'rgb(255, 255, 100)';
    logo.width = 800;
    logo.text = GAME_TITLE;
    logo.textAlign = "center";
    logo.moveTo((game.width - logo.width) / 2, 100);
    scene.addChild(logo);

    // 権利表記：SESAME GAMES
    var right = new Label();
    right.font = FONT_SCORE;
    right.color = 'rgb(255, 255, 100)';
    right.width = 800;
    right.text = "Copyright (c) 2015 SESAME GAMES by SquashSesame";
    right.textAlign = "center";
    right.moveTo((game.width - right.width) / 2, game.height - 80);
    scene.addChild(right);

    // 権利表記：音素材
    var label2 = new Label();
    label2.font = FONT_SCORE;
    label2.color = 'rgb(255, 255, 100)';
    label2.text = "音素材：魔王魂";
    label2.textAlign = "center";
    label2.moveTo((game.width - label2.width) / 2, game.height - 40);
    scene.addChild(label2);

    var click = new Sprite(256, 64);
    click.count = 0;
    click.image = GetImageAsset(game, 'tl_clickToStart.png');
    click.moveTo((game.width - click.width) / 2, game.height / 2 + 140);
    click.addEventListener('enterframe', function () {
        var self = this;
        self.opacity = (Math.sin(self.count) + 1.0) / 2.0 + 0.5;
        self.count += 10 / game.fps;
    });
    scene.addChild(click);

    // Fade screen
    scene.phase = 0;
    scene.fade = CreateFadeScreen(game);
    scene.fade.fadeStart(scene, 20, 1.0, 0.0);

    // タッチされたら、ゲーム開始
    scene.addEventListener('touchstart', function (e) {
        if (scene.phase == 2) {
            scene.phase = 3;
        }
    });

    // Title Main
    scene.addEventListener('enterframe', function () {
        var self = this;
        bgmTitle.update();
        switch (self.phase) {
        case 0:
            self.phase = 1;
            break;

        case 1:
            // wait fade in
            if (self.fade.isEnd == true) {
                self.phase = 2;
            }
            break;

        case 2:
            // wait touch
            break;

        case 3:
            // BGMー＞フェードアウト
            bgmTitle.fadeOut();
            self.fade.fadeStart(scene, 20, 0.0, 1.0);
            self.phase = 4;
            break;

        case 4:
            if (self.fade.isEnd == true) {
                // フェードアウト　ー＞　ゲームへ
                bgmTitle.bgmStop();
                game.popScene();
            }
            break;
        }
    });

    return scene;
};