var M = {
  ver : 1,
  os : 5,
  channel : "web",
  domain : "http://ms-api.duowan.com",
  gameList : [],
  getDetailByPn : function(packageName){
    var url = M.domain+"/mobileGame/byPackageName.do";
        var data = {
          channel: M.channel,
          ver: M.ver,
          os: M.os,
          packageName: packageName
        };

        $.ajax({
          url: url,
          dataType: 'jsonp',
          data: data,
          success: function(ret){
            M.gameList.push(ret.data.list[0]);
            if (M.gameList.length == M.installList.length) {
              V.initDom(3,M.gameList);
            }
          },
          error: function(ret){
          }
        });
  }
}
var V = {
  init : function(){
    M.os = commonUtil.checkPlatform();
    var info = $.parseJSON(window.installInfo);

    if (info) {
      if (info.data) {
        M.installList = info.data.list;
        for (var i=0; i<M.installList.length; i++) {
          M.getDetailByPn(M.installList[i]["packageName"]);
        }
      } else {
        V.initDom(2);
      }
    } else {
      V.initDom(1);
    }
  },
  //type:1无模拟器无游戏,2有模拟器无游戏,3有模拟器有游戏
  initDom : function(type,data){
    var bannerTpl = __inline('../../tpl/simulatorMyGame.tmpl');
    var dom = bannerTpl({
      type : type,
      data : data
    });
    $("#gameWrap").html(dom);

    var PageTurn = new commonUtil.PageTurn({
      showNum : 18
    });
  }
}

function initData() {
  var timeout = setTimeout(function(){
    if(window.doneFlag) {
      V.init();
    } else {
      initData();
    }
  },200);
}

initData();

