// 0: 3DView    1:  Geometry    2: Esitamte 3: Next 4: pillar   5: balcony  6: roof  7: zoom scale
var btn3D, btn3DText;
var btnGeometry, btnGeometryText;
var btnEsitamte, btnEsitamteText;
var btnPillar, btnPillarText;
var btnBalcony, btnBalconyText;
var btnRoof, btnRoofText;
var btnScaleZoom, btnScaleZoomText;
var aroundRect, objectLine;
var btnzoomIn, btnzoomOut;
var M_TOP = 15;
var M_LEFT = 50;


var btnPosList =    [   [ 0, 0, 200, 50 ],
                        [ 200, 0, 200, 50   ],
                        [ 400, 0, 200, 50   ],
                        [ 600, 0, 200, 50   ],
                        [ 0, 50, 100, 100   ],
                        [ 0, 150, 100, 95   ],
                        [ 0, 245, 100, 110  ],
                        [ 1019.45, 727.2, 259.6, 102.6  ]
                    ];

// object to control
    // 0: 3DView    1:  Geometry    2: Esitamte 3: Next 4: pillar   5: balcony  6: roof  7: zoom scale
    // x; y; widht; heigth


function drawHomepage(){
    drawLineAround();
    draw3DViewMenu();
    drawGeometryMenu();
    drawEsitamteMenu();
    drawPillarMenu();
    drawBalconyMenu();
    drawRoofMenu();
    drawScaleZoomMenu();
}
function drawLineAround(){
    // Draw 3DView button
    if(aroundRect) stage.removeChild(aroundRect);
        
    aroundRect = new createjs.Shape();
    aroundRect.graphics.setStrokeStyle(padding).beginStroke('#FF7117').drawRect(0, 0, 1279, 959);
    aroundRect.x = 0;
    aroundRect.y = 0;
    stage.addChild(aroundRect);

    // Draw object line
    if(objectLine) stage.removeChild(objectLine);
    objectLine = new createjs.Shape();
    objectLine.graphics.setStrokeStyle(2).beginStroke('#FF7117').moveTo(0, 830).lineTo(1280, 830).endStroke();
    stage.addChild(objectLine);
}
function draw3DViewMenu(){
    // Draw 3DView button
    if(btn3D) stage.removeChild(btn3D);
        
    btn3D = new createjs.Shape();
    btn3D.graphics.setStrokeStyle(padding).beginStroke('#FF7117').beginFill('#FFA500').drawRect(0, 0, btnPosList[0][2], btnPosList[0][3]);
    btn3D.x = btnPosList[0][0];
    btn3D.y = btnPosList[0][1];
    btn3D.addEventListener("click", view3d);
    //btn3D.on('click', incTransitionState );
    stage.addChild(btn3D);
    
    if (btn3DText) stage.removeChild(btn3DText);
    btn3DText = new createjs.Text("3DVIEW", "20px Arial", "#FFFFFF");
    btn3DText.x = btnPosList[0][0] + M_LEFT;
    btn3DText.y = btnPosList[0][1] + M_TOP;
    btn3DText.addEventListener("click", view3d);
    stage.addChild(btn3DText);
            
}

function drawGeometryMenu(){
    // Draw 3DView button
    if(btnGeometry) stage.removeChild(btnGeometry);
        
    btnGeometry = new createjs.Shape();
    btnGeometry.graphics.setStrokeStyle(padding).beginStroke('#FF7117').beginFill('#FFA500').drawRect(0, 0, btnPosList[1][2], btnPosList[1][3]);
    btnGeometry.x = btnPosList[1][0];
    btnGeometry.y = btnPosList[1][1];
    stage.addChild(btnGeometry);
    
    if (btnGeometryText) stage.removeChild(btnGeometryText);
    btnGeometryText = new createjs.Text("図形作成", "20px Arial", "#FFFFFF");
    btnGeometryText.x = btnPosList[1][0] + M_LEFT;
    btnGeometryText.y = btnPosList[1][1] + M_TOP;
    stage.addChild(btnGeometryText);
            
}

function drawEsitamteMenu(){
    // Draw 3DView button
    if(btnEsitamte) stage.removeChild(btnEsitamte);
        
    btnEsitamte = new createjs.Shape();
    btnEsitamte.graphics.setStrokeStyle(padding).beginStroke('#FF7117').beginFill('#FFA500').drawRect(0, 0, btnPosList[2][2], btnPosList[2][3]);
    btnEsitamte.x = btnPosList[2][0];
    btnEsitamte.y = btnPosList[2][1];
    btnEsitamte.addEventListener("click", estimate);
    stage.addChild(btnEsitamte);
    
    if (btnEsitamteText) stage.removeChild(btnEsitamteText);
    btnEsitamteText = new createjs.Text("データ保存", "20px Arial", "#FFFFFF");
    btnEsitamteText.x = btnPosList[2][0] + M_LEFT;
    btnEsitamteText.y = btnPosList[2][1] + M_TOP;
    btnEsitamteText.addEventListener("click", estimate);
    stage.addChild(btnEsitamteText);
            
}

function drawPillarMenu(){
    // Draw 3DView button
    if(btnPillar) stage.removeChild(btnPillar);
        
    btnPillar = new createjs.Shape();
    btnPillar.graphics.setStrokeStyle(padding).beginStroke('#FF7117').beginFill('#FFA500').drawRect(0, 0, btnPosList[4][2], btnPosList[4][3]);
    btnPillar.x = btnPosList[4][0];
    btnPillar.y = btnPosList[4][1];
    stage.addChild(btnPillar);
    
    if (btnPillarText) stage.removeChild(btnPillarText);
    btnPillarText = new createjs.Text("柱", "20px Arial", "#FFFFFF");
    btnPillarText.x = btnPosList[4][0] + 40;
    btnPillarText.y = btnPosList[4][1] + 40;
    stage.addChild(btnPillarText);
            
}


function drawBalconyMenu(){
    // Draw 3DView button
    if(btnBalcony) stage.removeChild(btnBalcony);
        
    btnBalcony = new createjs.Shape();
    btnBalcony.graphics.setStrokeStyle(padding).beginStroke('#FF7117').beginFill('#FFA500').drawRect(0, 0, btnPosList[5][2], btnPosList[5][3]);
    btnBalcony.x = btnPosList[5][0];
    btnBalcony.y = btnPosList[5][1];
    stage.addChild(btnBalcony);
    
    if (btnBalconyText) stage.removeChild(btnBalconyText);
    btnBalconyText = new createjs.Text("ベランダ", "20px Arial", "#FFFFFF");
    btnBalconyText.x = btnPosList[5][0] + 10;
    btnBalconyText.y = btnPosList[5][1] + 40;
    stage.addChild(btnBalconyText);
            
}

function drawRoofMenu(){
    // Draw 3DView button
    if(btnRoof) stage.removeChild(btnRoof);
        
    btnRoof = new createjs.Shape();
    btnRoof.graphics.setStrokeStyle(padding).beginStroke('#FF7117').beginFill('#FFA500').drawRect(0, 0, btnPosList[6][2], btnPosList[6][3]);
    btnRoof.x = btnPosList[6][0];
    btnRoof.y = btnPosList[6][1];
    btnRoof.addEventListener("click", roof);
    stage.addChild(btnRoof);
    
    if (btnRoofText) stage.removeChild(btnRoofText);
    btnRoofText = new createjs.Text("屋根", "20px Arial", "#FFFFFF");
    btnRoofText.x = btnPosList[6][0] + 30;
    btnRoofText.y = btnPosList[6][1] + 40;
    btnRoofText.addEventListener("click", roof);
    stage.addChild(btnRoofText);
            
}

function drawScaleZoomMenu(){
    // Draw 3DView button
    if(btnScaleZoom) stage.removeChild(btnScaleZoom);
        
    btnScaleZoom = new createjs.Shape();
    btnScaleZoom.graphics.setStrokeStyle(padding).beginStroke('#994c1b').beginFill('#994c1b').drawRect(0, 0, btnPosList[7][2], btnPosList[7][3]);
    btnScaleZoom.x = btnPosList[7][0];
    btnScaleZoom.y = btnPosList[7][1];
    //btnScaleZoom.addEventListener("click", viewScaleZoom);
    //btnScaleZoom.on('click', incTransitionState );
    stage.addChild(btnScaleZoom);
    
    if (btnScaleZoomText) stage.removeChild(btnScaleZoomText);
    btnScaleZoomText = new createjs.Text("拡大縮小", "20px Arial", "#FFFFFF");
    btnScaleZoomText.x = btnPosList[7][0] + 80;
    btnScaleZoomText.y = btnPosList[7][1] + 10;
    stage.addChild(btnScaleZoomText);


    
    // Draw zoom in button +
    if(btnzoomIn) stage.removeChild(btnzoomIn);
    btnzoomIn = new createjs.Shape();
    btnzoomIn.graphics.beginStroke("#ffffff").beginFill("#ffffff").drawCircle(0, 0, 20);
    btnzoomIn.graphics.setStrokeStyle(2).beginStroke("#9b4a24").moveTo(btnzoomIn.x - 17, btnzoomIn.y).lineTo(btnzoomIn.x + 17, btnzoomIn.y).moveTo(btnzoomIn.x, btnzoomIn.y - 10).lineTo(btnzoomIn.x, btnzoomIn.y + 10).endStroke; 
    btnzoomIn.x = 1115.25;
    btnzoomIn.y = 788;
    btnzoomIn.cursor = "pointer";
    stage.addChild(btnzoomIn);
    


    // Draw zoom out button -
    if(btnzoomOut) stage.removeChild(btnzoomOut);
    btnzoomOut = new createjs.Shape();
    btnzoomOut.graphics.beginStroke("#ffffff").beginFill("#ffffff").drawCircle(0, 0, 20);
    btnzoomOut.graphics.setStrokeStyle(2).beginStroke("#9b4a24").moveTo(btnzoomOut.x - 17, btnzoomOut.y).lineTo(btnzoomOut.x + 17, btnzoomOut.y).endStroke; 
    btnzoomOut.x = 1175;
    btnzoomOut.y = 788;
    btnzoomOut.cursor = "pointer";
    stage.addChild(btnzoomOut);
}

