UI.moduleBuilder['Alexa']['listTemplate'] = function(){
    var listTemplate1Data = {
        bodyTemplate1Bg:"Alexa/card_bg.png",
        skillIcon:"",
        logoIcon:"Alexa/avs_logo_template.png"
    };
    var template = Util.readJson("module/Alexa/listTemplate.json");
    var listTemplate =  SubModule.create(listTemplate1Data, template);


    var mainTitle = UI.getItem(listTemplate, "mainTitle");
    var subTitle = UI.getItem(listTemplate, "subTitle");
    var skillIcon = UI.getItem(listTemplate, "skillIcon");
    var tiles = UI.getItem(listTemplate, "tiles");
    var backgroundImg = UI.getItem(listTemplate, "backgroundImg");

    listTemplate.leftTextFieldList = [];//["1、","2、","3、","4、","5、"/*"6、","7、","8","9","10","11","12","13","14"*/];
    listTemplate.rightTextFieldList = [];//["aaa","ccc","ccc","fff","eee"/*,"rrr","ttt","hhh"*/];
    var createTable = function (leftData, rightData) {
        var disLayer = $("#divLayer");
        disLayer.html("");
        disLayer.html(getFile("module/Alexa/listContentDiv.html"));
        var tableHtml = "";
        for (var i=0;i<leftData.length;i++){
            tableHtml += "<tr><td valign=\"top\" class='leftStyle'>"+leftData[i]+"</td>";
            tableHtml += "<td valign=\"top\" class='rightStyle'>"+rightData[i]+"</td><tr>"
        }
        var listTable = $("#listTable");
        listTable.html(tableHtml);
        $("#divLayer").css("visibility", "visible");
        tiles = document.getElementById("listContent");
        if(tiles.scrollHeight>tiles.clientHeight||tiles.offsetHeight>tiles.clientHeight){
            tiles.hasScrollBar = true;
        } else {
            tiles.hasScrollBar = false;
        }
    };
    var removeTable = function () {
        var disLayer = $("#divLayer");
        disLayer.html("");
        $("#divLayer").css("visibility", "hidden");
    };
    // creatList(listTemplate.leftTextFieldList,listTemplate.rightTextFieldList);
    createTable(listTemplate.leftTextFieldList,listTemplate.rightTextFieldList);

    function creatList(leftTextFieldList,rightTextFieldList){
        tiles.removeAllChildren();
        var listTemp = [];
        for (var i=0; i < leftTextFieldList.length; i++) {
            listTemp.push({});
            listTemp[i].name = "listTemp" + i;
            listTemp[i].leftTextField = leftTextFieldList[i];
            listTemp[i].rightTextField = rightTextFieldList[i];
        }
        var info = {
            template: "alexa_list_item",
            direction: CONST.GIRD_DIRECTION.H,
            breakNum: 1,
            distanceX: 0,
            distanceY: 31,
            container: tiles
        };
        Gird.create(listTemp, info);
        UI.addMask(tiles, 544, 700, 50, 3);
        UI.setView(tiles, 544, 700);
        UI.addScrollbar(tiles,-16);
    }



    listTemplate.currFocus = mainTitle;
    listTemplate.currHeight = 0;
    listTemplate.step = 80;
    listTemplate.maskHeight = 700;
    listTemplate.scrollStep = 0;

    listTemplate.onPush = function(){
        var graphics = new PIXI.Graphics()
            .beginFill(0x000000, 0.85)
            .drawRect(0, 0, 1920, 1080)
            .endFill();
        UI.setImage(backgroundImg,graphics);
    }
    listTemplate.onShow = function(){
        if(!tv){
            listTemplate.leftTextFieldList = ["1、","2、","3、","4、","5、","6、","7、","8","9","10","11","12","13","14","7、","8","9","10","11","12","13","14"];
            listTemplate.rightTextFieldList = ["aaa","ccc","ccc","fff","eee","rrr dsad dasd dasd dada dasda dada dasd ss","ttt","hhh","ccc","fff","eee","rrr","ccc","fff","eee","rrr"];
            // creatList(listTemplate.leftTextFieldList,listTemplate.rightTextFieldList);
            createTable(listTemplate.leftTextFieldList,listTemplate.rightTextFieldList);
            return;
        }
        if (!listTemplate.param) {
            DBG_ERROR("template is null");
            return;
        }
        if(listTemplate.param.skillIcon != null && listTemplate.param.skillIcon.length != 0){
            mainTitle.originWidth = 380;
            subTitle.originWidth = 380
        }else{
            mainTitle.originWidth = 600;
            subTitle.originWidth = 600
        }
        UI.setText(mainTitle,listTemplate.param.mainTitle);
        UI.setText(subTitle,listTemplate.param.subTitle);
        if (!!listTemplate.param.leftTextField || !!listTemplate.param.rightTextField) {
            // creatList(listTemplate.param.leftTextField, listTemplate.param.rightTextField);
            createTable(listTemplate.param.leftTextField, listTemplate.param.rightTextField);
        }
    }

   listTemplate.afterPush = function(){
       listTemplate.currFocus = mainTitle;
   }

    listTemplate.onPop = function(){
        removeTable();
    }
    listTemplate.onFocus = function(focus){
        UI.moveCursor(UI.adjustView());
        UI.getTween(focus.scale).wait(100).to({x:1, y:1}, 500, UI.ease.quartOut);
        UI.getTween(UI.base.cursor).wait(100).to({alpha:0}, 500, UI.ease.quartOut);
        UI.moveTop(focus);
        UI.base.runText(focus);
        return false;

    }
    listTemplate.onNormal = function(focus){
        UI.getTween(focus.scale).to({x:1, y:1}, 200);
        UI.base.stopText(focus);
        return false;
    }

    listTemplate.onkey = function(focus,evt){
        DBG_ERROR("listTemplate evt.keyCode=" + evt.keyCode);

        if (evt.value == "DOWN") {
            // if(tiles.height - listTemplate.currHeight > listTemplate.maskHeight){
            //     listTemplate.currHeight += listTemplate.step;
            //     tiles.y -=  listTemplate.step;
            //     listTemplate.scrollStep = parseInt(720/tiles.height *listTemplate.step);//bounds 800
            //     tiles.scroll.y += listTemplate.scrollStep;
            //     UI.updateStage();
            //     return ;
            // }
            if (tiles.hasScrollBar) {
                tiles.scrollTop += 150;
                return;
            }
        } else if (evt.value == "UP") {
            // if(listTemplate.currHeight > 0){
            //     if(listTemplate.currHeight > listTemplate.step){
            //         listTemplate.currHeight -= listTemplate.step;
            //     }else{
            //         listTemplate.currHeight = 0;
            //     }
            //     tiles.y += listTemplate.step;
            //     listTemplate.scrollStep = parseInt(720/tiles.height *listTemplate.step);
            //     tiles.scroll.y -= listTemplate.scrollStep;
            //     UI.updateStage();
            //     return
            // }

            if (tiles.hasScrollBar) {
                tiles.scrollTop -= 150;
                return;
            }
        } else if (evt.value == "VOICE" || evt.value == "VOICE_DOWN" || evt.value == "VOICE_UP") {
            return true;
        } else {
            UI.popSubModule();
            return (Alexa_globalKeys.indexOf(evt.keyCode) >= 0);
        }
    }

}