/**
 * Created with JetBrains WebStorm.
 * User: gravis_ihara
 * Date: 14/09/08
 * Time: 18:02
 * To change this template use File | Settings | File Templates.
 */
enchant();
var gravis = {};
if(window.innerWidth < 480 || window.innerHeight < 640) {
//if(true) {
    gravis.WINDOW_WIDTH = 320;
    gravis.WINDOW_HEIGHT = 427;
    gravis.CHOICE_LEVEL_MAX = 84;
    gravis.CARD_W = 67;
    gravis.CARD_H = 99;
    gravis.CARD_WILD = 53;
    gravis.CARD_EMPTY = 52;
    gravis.CARDMOVE_SET = 8;
    gravis.CARDMOVE_GO = 5;
    gravis.CARDMOVE_BACK = 15;

    gravis.DATA_LIST = [
        'assets/320/back_green.png',
        'assets/320/button_01.png',
        'assets/320/card.png',
        'assets/320/draw.png',
        'assets/320/go.png',
        'assets/320/gradation.png',
        'assets/320/gravis.png',
        'assets/320/lose.png',
        'assets/320/next_quit.png',
        'assets/320/number01.png',
        'assets/320/number02.png',
        'assets/320/ready.png',
        'assets/320/result.png',
        'assets/320/result_02.png',
        'assets/320/title.png',
        'assets/320/volume.png',
        'assets/320/x.png',
        'assets/320/win.png',
        'assets/320/word_01.png',
        'assets/se_00.ogg',
        'assets/se_01.ogg',
        'assets/se_02.ogg',
        'assets/se_03.ogg',
        'assets/se_04.ogg',
        'assets/se_05.ogg',
        'assets/se_06.ogg',
        'assets/se_07.ogg',
        'assets/se_08.ogg'
    ];

    var script_list = [
        'game/320/SliderScene.js',
        'game/320/Card.js',
        'game/320/GameCpu.js',
        'game/320/GameEffect.js',
        'game/320/ResultWindow.js',
        'game/320/SceneTitle.js',
        'game/320/SceneGame.js'
    ];

    for( var i=0; i<script_list.length; i++ ) {
        var script = document.createElement('script');
        script.setAttribute('src', script_list[i]);
        document.getElementsByTagName("head")[0].appendChild(script);
    }

    enchant.widget._env.dialogHeight = 150;
    enchant.widget._env.dialogWidth = 220;
    enchant.widget._env.font = '12px sans-serif';
    enchant.widget._env.buttonFont = '12px sans-serif';

} else {
    gravis.WINDOW_WIDTH = 480;
    gravis.WINDOW_HEIGHT = 640;
    gravis.CHOICE_LEVEL_MAX = 84;
    gravis.CARD_W = 102;
    gravis.CARD_H = 150;
    gravis.CARD_WILD = 53;
    gravis.CARD_EMPTY = 52;
    gravis.CARDMOVE_SET = 8;
    gravis.CARDMOVE_GO = 5;
    gravis.CARDMOVE_BACK = 15;

    gravis.DATA_LIST = [
        'assets/480/back_green.png',
        'assets/480/button_01.png',
        'assets/480/card.png',
        'assets/480/draw.png',
        'assets/480/go.png',
        'assets/480/gradation.png',
        'assets/480/gravis.png',
        'assets/480/lose.png',
        'assets/480/next_quit.png',
        'assets/480/number01.png',
        'assets/480/number02.png',
        'assets/480/ready.png',
        'assets/480/result.png',
        'assets/480/result_02.png',
        'assets/480/title.png',
        'assets/480/volume.png',
        'assets/480/x.png',
        'assets/480/win.png',
        'assets/480/word_01.png',
        'assets/se_00.ogg',
        'assets/se_01.ogg',
        'assets/se_02.ogg',
        'assets/se_03.ogg',
        'assets/se_04.ogg',
        'assets/se_05.ogg',
        'assets/se_06.ogg',
        'assets/se_07.ogg',
        'assets/se_08.ogg'
    ];

    var script_list = [
        'game/480/SliderScene.js',
        'game/480/Card.js',
        'game/480/GameCpu.js',
        'game/480/GameEffect.js',
        'game/480/ResultWindow.js',
        'game/480/SceneTitle.js',
        'game/480/SceneGame.js'
    ];

    for( var i=0; i<script_list.length; i++ ) {
        var script = document.createElement('script');
        script.setAttribute('src', script_list[i]);
        document.getElementsByTagName("head")[0].appendChild(script);
    }

    enchant.widget._env.dialogHeight = 225;
    enchant.widget._env.dialogWidth = 300;
    enchant.widget._env.font = '24px sans-serif';
    enchant.widget._env.buttonFont = '24px sans-serif';
}

//utility
gravis.Utility = {};
gravis.Utility.isTap = function(sprite, event) {
    if( 0 <= event.localX && event.localX <= sprite.width &&
        0 <= event.localY && event.localY <= sprite.height ) return true;
    return false;
}

gravis.Utility.nextInt = function(max) {
    return Math.floor( Math.random() * (max) );
}

gravis.Utility.savedata = { "sound" : true, "cpu" : 0 };
gravis.Utility.save = function() {
    localforage.setItem("save", JSON.stringify(gravis.Utility.savedata));
}

gravis.Utility.savedata.sound = true;
gravis.Utility.playSE = function(filename) {
    if( gravis.Utility.savedata.sound ) {
        game.assets['assets/'+filename].clone().play();
    }
}

gravis.Utility.getImage = function(filename) {
    if( gravis.WINDOW_WIDTH == 320 ) {
        return game.assets['assets/320/'+filename];
    } else {
        return game.assets['assets/480/'+filename];
    }
}