var GGm_ScrollTop = 0;

function Game_Init (){
    var _HtmStr = '';
    
    var _ilen = G_JDB_gamelist.length;
    for(var _i = 0; _i<_ilen; _i++){
        if(_HtmStr == ''){
            _HtmStr += '<Table border="0px" cellpadding="0px" cellspacing="0px" style=\'width:100%;\'>';
        }else{
            _HtmStr += C_tag_trst;
                _HtmStr += C_tag_tdst('100%','1px','','4');
                    _HtmStr += '<DIV class=\'D_TableSpace\'>　</DIV>';
                _HtmStr += C_tag_tded;
            _HtmStr += C_tag_tred;
        }
        
        var _NowName = G_JDB_gamelist[_i].Name;
        var _NowNo = G_JDB_gamelist[_i].No;
        var _NowNico = G_JDB_gamelist[_i].Nico;
        var _NowYtub = G_JDB_gamelist[_i].Ytub;
        var _NowData = G_JDB_gamelist[_i].Data;
        
        var _GameDivName = 'D_Game_';
        _GameDivName += _NowNo;
        _GameDivName += _NowNico;
        
        var _GameOnMouseOverEvent = 'style.cursor = "pointer"; Main_SetS("';
        _GameOnMouseOverEvent += _GameDivName;
        _GameOnMouseOverEvent += '","background-color","#';
        _GameOnMouseOverEvent += C_Color_Pink;
        _GameOnMouseOverEvent += '");';
        
        var _GameOnMouseOutEvent = 'style.cursor = "auto"; Main_SetS("';
        _GameOnMouseOutEvent += _GameDivName;
        _GameOnMouseOutEvent += '","background-color","Transparent");';
        
        var _GameOnClickEvent = 'G_NewLoad = 2; Game_GameStart("';
        _GameOnClickEvent += _NowName;
        _GameOnClickEvent += '","';
        _GameOnClickEvent += _NowNo;
        _GameOnClickEvent += '","';
        _GameOnClickEvent += _NowNico;
        _GameOnClickEvent += '","';
        _GameOnClickEvent += _NowYtub;
        _GameOnClickEvent += '");';
        
        var _OnEventStr = ' OnMouseOver=\'';
        _OnEventStr += _GameOnMouseOverEvent;
        _OnEventStr += '\' OnMouseOut=\'';
        _OnEventStr += _GameOnMouseOutEvent;
        _OnEventStr += '\' OnClick=\'';
        _OnEventStr += _GameOnClickEvent;
        _OnEventStr += '\'';
        
        _HtmStr += C_tag_trst;
            _HtmStr += C_tag_tdst('100%','2px');
                _HtmStr += '<DIV style=\'width:100%; height:2px;\ overflow:hidden;\'>　</DIV>';
            _HtmStr += C_tag_tded;
        _HtmStr += C_tag_tred;
        
        _HtmStr += C_tag_trst;
            _HtmStr += C_tag_tdst('100%','20px');
                _HtmStr += '<DIV id=\'';
                _HtmStr += _GameDivName;
                _HtmStr += '\'>';
                    _HtmStr += '<Table border="0px" cellpadding="0px" cellspacing="0px" style=\'width:100%;\'>';
                        
                        _HtmStr += C_tag_trst;
                            _HtmStr += C_tag_tdst('2px','20px');
                                _HtmStr += '<DIV style=\'width:2px; height:20px;\ overflow:hidden;\'>　</DIV>';
                            _HtmStr += C_tag_tded;
                            
                            _HtmStr += C_tag_tdst('270px','20px');
                                _HtmStr += '<DIV style=\'width:270px; height:20px;\ overflow:hidden;\'';
                                _HtmStr += _OnEventStr;
                                _HtmStr += '>';
                                    _HtmStr += G_JDB_gamelist[_i].Name;
                                _HtmStr += '</DIV>';
                            _HtmStr += C_tag_tded;
                            
                            _HtmStr += C_tag_tdst('5px','20px');
                                _HtmStr += '<DIV style=\'width:5px; height:20px;\ overflow:hidden;\'';
                                _HtmStr += _OnEventStr;
                                _HtmStr += '>　</DIV>';
                            _HtmStr += C_tag_tded;
                            
                            _HtmStr += C_tag_tdst('100%','20px');
                                _HtmStr += '<DIV style=\'width:100%; height:20px;\ overflow:hidden;\'';
                                _HtmStr += _OnEventStr;
                                _HtmStr += '>';
                                    _HtmStr += G_JDB_gamelist[_i].Data;
                                _HtmStr += '</DIV>';
                            _HtmStr += C_tag_tded;
                        _HtmStr += C_tag_tred;
                        
                    _HtmStr += '</Table>';
                _HtmStr += '</DIV>';
            _HtmStr += C_tag_tded;
        _HtmStr += C_tag_tred;
        
        _HtmStr += C_tag_trst;
            _HtmStr += C_tag_tdst('100%','2px');
                _HtmStr += '<DIV style=\'width:100%; height:2px;\ overflow:hidden;\'>　</DIV>';
            _HtmStr += C_tag_tded;
        _HtmStr += C_tag_tred;
    }
    
    _HtmStr += '</Table>';
    
    Main_SetH('D_GameTitleList',_HtmStr);
}

//----------------------------------------------
//function Game_GameStart(_Name,_No){
function Game_GameStart(_Name,_No,_Nico,_Ytub){
    //グッズ情報を停止
    Aff_AutoTimerStop('1');
    //Aff_AutoTimerStop('2');
    Aff_AutoTimerStop('3');
    
    Main_SetS('D_GameTitleList','display','none');
    
    Main_SetH('D_GameTitle',_Name);
    
    var _HtmStrU = '';
    var _NoLen = _No.length;
    if(_NoLen > 6){
        var _MouseOverEvent = 'style.cursor = "pointer";  style.backgroundColor = "';
        _MouseOverEvent += C_Color_Pink;
        _MouseOverEvent += '"';
        
        var _MouseOutEvent = 'style.cursor = "auto"; style.backgroundColor = "Transparent"';
        
        var _ClickEvent = 'Act_SetUrl(\"game';
        _ClickEvent += _No;
        _ClickEvent += '\");';
        
        _HtmStrU += '<DIV class=\'D_URLButton\' style=\'width:35px; height:18px; overflow:hidden;\' OnMouseOver=\'';
        _HtmStrU += _MouseOverEvent;
        _HtmStrU += '\' OnMouseOut=\'';
        _HtmStrU += _MouseOutEvent;
        _HtmStrU += '\' OnClick=\'';
        _HtmStrU += _ClickEvent;
        _HtmStrU += '\'>URL</DIV>';
    }else{
        _HtmStrU += '　';
    }
    Main_SetH('D_GameURL',_HtmStrU);
    
    var _HtmStr = '';
    
    _HtmStr += '<Table border="0px" cellpadding="0px" cellspacing="0px" style=\'width:100%;\'>';
        _HtmStr += C_tag_trst;
            _HtmStr += C_tag_tdst('100%','5px','','3');
                _HtmStr += '<DIV style=\'width:100%; height:5px; overflow:hidden;\'>　</DIV>';
            _HtmStr += C_tag_tded;
        _HtmStr += C_tag_tred;
        
        if(_Nico != '-'){
            if(_Nico == 'Rmake'){
                
                
                
            }else{
                _HtmStr += C_tag_trst;
                    _HtmStr += C_tag_tdst('100%','12px','','3');
                        _HtmStr += '<DIV style=\'width:100%; height:12px; text-align:center; font-size:10px; overflow:hidden;\'>';
                        _HtmStr += 'ニコゲーの終了に伴い、プレイ動画のみご覧いただけます。';
                        _HtmStr += '</DIV>';
                    _HtmStr += C_tag_tded;
                _HtmStr += C_tag_tred;
            }
            
            _HtmStr += C_tag_trst;
                _HtmStr += C_tag_tdst('100%','2px','','3');
                    _HtmStr += '<DIV style=\'width:100%; height:2px; overflow:hidden;\'>　</DIV>';
                _HtmStr += C_tag_tded;
            _HtmStr += C_tag_tred;
            
            _HtmStr += C_tag_trst;
                _HtmStr += C_tag_tdst('100%','12px','','3');
                    _HtmStr += '<DIV style=\'width:100%; height:12px; text-align:center; font-size:10px; overflow:hidden;\'>';
                    _HtmStr += '＜ サウンドが流れますのでご注意ください ＞';
                    _HtmStr += '</DIV>';
                _HtmStr += C_tag_tded;
            _HtmStr += C_tag_tred;
        }
        
        _HtmStr += C_tag_trst;
            _HtmStr += C_tag_tdst('100%','5px','','3');
                _HtmStr += '<DIV style=\'width:100%; height:5px; overflow:hidden;\'>　</DIV>';
            _HtmStr += C_tag_tded;
        _HtmStr += C_tag_tred;
        
        _HtmStr += C_tag_trst;
            _HtmStr += C_tag_tdst('30px','25px');
                _HtmStr += '<DIV style=\'width:30px; height:25px; overflow:hidden;\'>　</DIV>';
            _HtmStr += C_tag_tded;
            _HtmStr += C_tag_tdst('35px','25px');
                //戻るボタン
                var _MouseOverEvent = 'style.cursor = "pointer";  style.backgroundColor = "';
                _MouseOverEvent += C_Color_Pink;
                _MouseOverEvent += '"';
                
                var _MouseOutEvent = 'style.cursor = "auto"; style.backgroundColor = "Transparent"';
                
                var _ClickEvent = 'Game_GameClose(';
                _ClickEvent += ');';
                
                _HtmStr += '<DIV class=\'D_CommentButton\' style=\'width:35px; height:18px; overflow:hidden;\' OnMouseOver=\'';
                _HtmStr += _MouseOverEvent;
                _HtmStr += '\' OnMouseOut=\'';
                _HtmStr += _MouseOutEvent;
                _HtmStr += '\' OnClick=\'';
                _HtmStr += _ClickEvent;
                _HtmStr += '\'>戻る</DIV>';
            _HtmStr += C_tag_tded;
            _HtmStr += C_tag_tdst('100%','25px');
                _HtmStr += '<DIV style=\'width:100%; height:25px; overflow:hidden;\'>　</DIV>';
            _HtmStr += C_tag_tded;
        _HtmStr += C_tag_tred;
    _HtmStr += '<Table>';
    
    Main_SetH('D_GameBack',_HtmStr);
    
    //スクロール位置の保存
    GGm_ScrollTop=document.body.scrollTop;
    
    Main_SetS('D_GameTitle','display','block');
    Main_SetS('D_GameL','display','block');
    Main_SetS('D_GameURL','display','block');
    Main_SetS('D_Page_NicoGa1','display','block');
    Main_SetS('D_GameBack','display','block');
    
    //スクロールをリセット
    document.body.scrollTop=0;
    
    //var _GetTest = Main_GetTextFile2('http://game.nicoga.jp/gameplay/ext/js/blog_player.js');
    
    //if(_GetTest != 'Error'){
    //if(NICOGAME_ROOT_URL){
    //    //ゲームのスタート
    //    Main_CopyH('D_Page_NicoGa1','D_Page_NicoGa2');
    //    
    //    _ng_gameId = _No;
    //    _ng_runPlayer();
    //}else{
    //    var _HtmStr2 = '';
    //    var _ImgMente = 'http://www.nicoga.com/mainwait.gif';
    //    
    //    _HtmStr2 += C_tag_Btn('',_ImgMente,_ImgMente,'ニコゲー');
    //    _HtmStr2 = _HtmStr2.replace(/img\/parts\//g,'');
    //    
    //    Main_SetH('D_Page_NicoGa1',_HtmStr2);
    //}
    
    if(_Nico != '-'){
        var _HtmStr2 = '';
        
        if(_Nico == 'Rmake'){
            //プレイヤーの表示
            _HtmStr2 += '<Table border="0px" cellpadding="0px" cellspacing="0px" style=\'width:100%;\'>';
                _HtmStr2 += C_tag_trst;
                    _HtmStr2 += C_tag_tdst('100%','10px');
                        _HtmStr += '<DIV style=\'width:100%; height:10px; overflow:hidden;\'>　</DIV>';
                    _HtmStr2 += C_tag_tded;
                _HtmStr2 += C_tag_tred;
                
                _HtmStr2 += C_tag_trst;
                    _HtmStr2 += C_tag_tdst('100%','176px');
                        _HtmStr += '<DIV style=\'width:100%; height:176px; overflow:hidden;\'>';
                            
                            _HtmStr2 += '<iframe width="800px" height="600px" align="center" src="http://rmake.jp/games/';
                            _HtmStr2 += _No;
                            _HtmStr2 += '/iframe" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe>';
                            
                        _HtmStr += '</DIV>';
                    _HtmStr2 += C_tag_tded;
                _HtmStr2 += C_tag_tred;
            _HtmStr2 += '</Table>';
            
        }else{
            //プレイ動画の表示
            _HtmStr2 += '<Table border="0px" cellpadding="0px" cellspacing="0px" style=\'width:100%;\'>';
                _HtmStr2 += C_tag_trst;
                    _HtmStr2 += C_tag_tdst('100%','10px');
                        _HtmStr += '<DIV style=\'width:100%; height:10px; overflow:hidden;\'>　</DIV>';
                    _HtmStr2 += C_tag_tded;
                _HtmStr2 += C_tag_tred;
                
                _HtmStr2 += C_tag_trst;
                    _HtmStr2 += C_tag_tdst('100%','176px');
                        _HtmStr += '<DIV style=\'width:100%; height:176px; overflow:hidden;\'>';
                            
                            //ニコニコ動画
                            _HtmStr2 += '<iframe width="312px" height="176px" align="center" src="http://ext.nicovideo.jp/thumb/';
                            _HtmStr2 += _Nico;
                            _HtmStr2 += '" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe>';
                            
                        _HtmStr += '</DIV>';
                    _HtmStr2 += C_tag_tded;
                _HtmStr2 += C_tag_tred;
                
                _HtmStr2 += C_tag_trst;
                    _HtmStr2 += C_tag_tdst('100%','5px');
                        _HtmStr += '<DIV style=\'width:100%; height:5px; overflow:hidden;\'>　</DIV>';
                    _HtmStr2 += C_tag_tded;
                _HtmStr2 += C_tag_tred;
                
                _HtmStr2 += C_tag_trst;
                    _HtmStr2 += C_tag_tdst('100%','390px');
                        _HtmStr += '<DIV style=\'width:100%; height:390px; overflow:hidden;\'>';
                            
                            //YouTube
                            _HtmStr2 += '<iframe title="YouTube video player" width="480" height="390" align="center" src="http://www.youtube.com/embed/';
                            _HtmStr2 += _Ytub;
                            _HtmStr2 += '" scrolling="no" style="border:solid 1px #CCC;" frameborder="0" allowfullscreen></iframe>';
                            
                        _HtmStr += '</DIV>';
                    _HtmStr2 += C_tag_tded;
                _HtmStr2 += C_tag_tred;
            _HtmStr2 += '</Table>';
        }
        
        Main_SetH('D_Page_NicoGa1',_HtmStr2);
        
    }else{
        //HTML5ゲームの実行
        GamePlayer_Init(_No);
    }
}

function Game_GameClose(){
    //ゲームのリセット
    Main_SetH('D_Page_NicoGa1','');
    
    Main_SetS('D_GameTitle','display','none');
    Main_SetS('D_GameL','display','none');
    Main_SetS('D_GameURL','display','none');
    Main_SetS('D_Page_NicoGa1','display','none');
    Main_SetS('D_GameBack','display','none');
    Main_SetS('D_GameTitleList','display','block');
    
    //HTML5用
    //if(GGmp_MainTimer != ''){
        clearInterval(GGmp_MainTimer);
        GGmp_MainTimer = '';
        
        GGmp_GameNo = '';
        
        GGmp_GameVPadOpen = 0
    //}
    
    //グッズ情報を再開
    Aff_AutoTimer('1');
    //Aff_AutoTimer('2');
    Aff_AutoTimer('3');
    
    //スクロールを復帰
    document.body.scrollTop=GGm_ScrollTop;
    GGm_ScrollTop=0;
}

