﻿
var webMapAppDefaultMinBottomHeight = 50;
var webMapAppMinBottomHeight = webMapAppDefaultMinBottomHeight;
var webMapAppDefaultMinBottomTop = 125;
var webMapAppMinBottomTop = webMapAppDefaultMinBottomTop;

var webMapAppBottomTBCellDiv_DS = null;
var webMapAppBottomTBCellDiv_AL = null;

var webMapAppPanelDisplayCell_Bottom = null;
var webMapAppPanelDisplay_Bottom = null;
var webMapAppPanelScrollDiv_Bottom = null;
var webMapAppBottomPanelHeight = 202 + webMapAppToggleHeight;
var webMapAppToggleDisplay2 = null;
var webMapAppTableContainer = null;
var webMapAppDefaultMaxDockWidth = 825;
var webMapAppMaxDockWidth = webMapAppDefaultMaxDockWidth;

var webMapAppToggleHeight = 10;
var webMapAppWindowHeight = 200;
var webMapAppMapLeft = 0;
var webMapAppHeight = 0;

var bottomDocked = false;


function initElements() {

    webMapAppPanelDisplay_Bottom = document.getElementById("BottomPanelCellDiv");
    webMapAppPanelDisplayCell_Bottom = document.getElementById("BottomPanelCell");
    webMapAppPanelScrollDiv_Bottom = document.getElementById("BottomPanelScrollDiv");
    webMapAppToggleDisplay2 = document.getElementById("ToggleCell2");
    webMapAppPanelSlider2 = document.getElementById("PanelSlider2");
    webMapAppPanelBottomSlider2 = document.getElementById("PanelSliderBottom2");
    webMapAppTableContainer = document.getElementById("TableContainer");
    
    webMapAppBottomTBCellDiv_DS = document.getElementById("BottomTBCellDiv_DS");
    webMapAppBottomTBCellDiv_AL = document.getElementById("BottomTBCellDiv_AL");
    
    webMapAppBottomPanelHeight = 10;
}

function setPageElementSizes2() {

    // get browser window dimensions
    var sWidth = getWinWidth();
    var sHeight = getWinHeight();
    
    // set map display dimensions
    var mWidth = sWidth - webMapAppLeftPanelWidth - webMapAppToggleWidth;
    var bWidth = sWidth - 2;
    var mHeight = sHeight - webMapAppTopBannerHeight - webMapAppToggleWidth;

    // set heights of bottom panel and toggle bar
    webMapAppPanelDisplayCell_Bottom.style.display = "none";
    webMapAppToggleDisplay2.style.width = bWidth + "px";
    webMapAppPanelScrollDiv_Bottom.style.width = bWidth + "px";
    webMapAppPanelDisplayCell_Bottom.style.top = mHeight + "px";
    webMapAppPanelDisplayCell_Bottom.style.display = "block"; 

    webMapAppBottomTBCellDiv_DS.style.top = mHeight + "px";
    webMapAppBottomTBCellDiv_DS.style.left = "393px"; 
    webMapAppBottomTBCellDiv_DS.style.display = "none";
    
    webMapAppBottomTBCellDiv_AL.style.top = mHeight + "px";
    webMapAppBottomTBCellDiv_AL.style.left = "524px"; 
    webMapAppBottomTBCellDiv_AL.style.display = "none";    
    
    var pTop = webMapAppWindowHeight - webMapAppTopBannerHeight - 202 - webMapAppToggleHeight;
    var pHeight = webMapAppWindowHeight - pTop;
    
    if (webMapAppTableContainer != null) {

        if ((pHeight - 120) > 0) {
            webMapAppTableContainer.style.height = (pHeight - 125) + "px";
        }
    } 
     
    resetAllTitleBarBackgroundImages();
}


function toggleBottomDock() {
    if (webMapAppPanelDisplay_Bottom.style.display=="none") {
        expandBottomDock();
    } else {
        collapseBottomDock();
    }     
}

function expandBottomDock() {

    webMapAppBottomPanelHeight = 202 + webMapAppToggleHeight;

    var image = document.images["CollapseImage2"];
    webMapAppPanelDisplay_Bottom.style.display = "block";
    image.src = "images/collapse_down.gif";
    image.alt = "Collapse";
    webMapAppPanelSlider2.style.cursor = "n-resize";
    webMapAppPanelBottomSlider2.style.cursor = "n-resize";
    
    var sHeight = getWinHeight();
    var mHeight = sHeight - webMapAppTopBannerHeight - webMapAppBottomPanelHeight;
    // set heights on elements 
    webMapAppMapDisplay.style.height = mHeight  + "px";
    webMapAppToggleDisplay.style.height = mHeight  + "px";
    webMapAppPanelScrollDiv.style.height = mHeight  + "px";

    webMapAppPanelDisplayCell_Bottom.style.top = mHeight  + "px";
   
    webMapAppBottomTBCellDiv_DS.style.top = (sHeight - 202 + 3) + "px";
    webMapAppBottomTBCellDiv_DS.style.display = "block";
    
    webMapAppBottomTBCellDiv_AL.style.top = (sHeight - 202 + 3) + "px";
    webMapAppBottomTBCellDiv_AL.style.display = "block";
    
    window.setTimeout("showFloatingPanel_Custom('DLoadSelected_Panel')", 250);
    window.setTimeout("showFloatingPanel_Custom('AbuttersList_Panel')", 250);
    
    bottomDocked = true;
    
    AdjustMapSize();
}

function collapseBottomDock(newLoad) {

    webMapAppBottomPanelHeight = 10;

    var image = document.images["CollapseImage2"];

    webMapAppPanelDisplay_Bottom.style.display = "none";
    image.src = "images/expand_up.gif";
    image.alt = "Expand";
    webMapAppPanelSlider2.style.cursor = "default"; 
    webMapAppPanelBottomSlider2.style.cursor = "default"; 

    var sHeight = getWinHeight();
    var mHeight = sHeight - webMapAppTopBannerHeight - webMapAppToggleWidth - 3;

    webMapAppMapDisplay.style.height = mHeight  + "px";
    webMapAppToggleDisplay.style.height = mHeight  + "px";
    webMapAppPanelScrollDiv.style.height = mHeight  + "px";

    webMapAppPanelDisplayCell_Bottom.style.top = mHeight  + "px";
   
    webMapAppBottomTBCellDiv_DS.style.top = mHeight + "px";
    webMapAppBottomTBCellDiv_DS.style.display = "none";
    
    webMapAppBottomTBCellDiv_AL.style.top = mHeight + "px";
    webMapAppBottomTBCellDiv_AL.style.display = "none";
    
    hideFloatingPanel('DLoadSelected_Panel', false);
    hideFloatingPanel('AbuttersList_Panel', false);
    
    bottomDocked = true;
    
    AdjustMapSize(); 
} 

//function startWebMapAppBottomDrag(e) {

//    webMapAppMoveFunction = document.onmousemove;
//    document.onmouseup = stopWebMapAppBottomDrag; 
//     
//    if (webMapAppPanelDisplay_Bottom.style.display!="none") {
//        webMapAppWindowHeight = getWinHeight();
//        getXY(e); 
//        
//        var mHeight;
//        if (webMapAppPanelDisplay_Bottom.clientHeight == 0) {
//            mHeight = 202;
//        } else {
//            mHeight = webMapAppPanelDisplay_Bottom.clientHeight
//        } 
//        webMapAppBottomOffsetY = webMapAppWindowHeight - mouseY - mHeight;
//        
//        //webMapAppBottomOffsetY = webMapAppWindowHeight - mouseY - webMapAppPanelDisplay_Bottom.clientHeight + 7;
//        window.status = webMapAppPanelDisplay_Bottom.clientHeight;
//        document.onmousemove = moveWebMapAppBottomDrag;
//    }
//    return false;  
//}

//function moveWebMapAppBottomDrag(e) {
//    getXY(e);
//    
//    window.status = mouseY + ":" + (webMapAppWindowHeight - webMapAppMinBottomHeight) + ":" + webMapAppDefaultMinBottomTop;
//    
//    if ((mouseY < webMapAppWindowHeight - webMapAppMinBottomHeight) &
//        (mouseY > webMapAppDefaultMinBottomTop)) {
//        webMapAppBottomPanelHeight = webMapAppWindowHeight - mouseY - webMapAppBottomOffsetY;

//        if (webMapAppBottomPanelHeight < webMapAppMinBottomHeight) { 
//            webMapAppBottomPanelHeight = webMapAppMinBottomHeight; 
//        }

//        var pTop = webMapAppWindowHeight - webMapAppTopBannerHeight - webMapAppBottomPanelHeight - webMapAppToggleHeight;
//        var mHeight = pTop;
//        var pHeight = webMapAppWindowHeight - pTop;
//        
//        //window.status = pTop + ":" + mHeight + ":" + webMapAppWindowHeight + ":" + pHeight;

//        webMapAppPanelDisplayCell_Bottom.style.top = pTop  + "px";
//        webMapAppPanelDisplay_Bottom.style.height = pHeight + "px";
//        
//        webMapAppBottomTBCellDiv_DS.style.top = (pTop + webMapAppTopBannerHeight + 10 + 3) + "px";
//        webMapAppBottomTBCellDiv_AL.style.top = (pTop + webMapAppTopBannerHeight + 10 + 3) + "px";
//        
//        if (webMapAppTableContainer != null) {
//            if ((pHeight - 120) > 0) {
//                webMapAppTableContainer.style.height = (pHeight - 125) + "px";
//            }
//        } 
//        
//        //window.status = (pHeight - 125) + "px";

//        webMapAppMapDisplay.style.height = mHeight  + "px";
//        
//        webMapAppToggleDisplay.style.height = mHeight  + "px";
//        webMapAppPanelScrollDiv.style.height = mHeight  + "px";
//    } else {
//        stopWebMapAppBottomDrag();
//    }
//    
//    return false;
//}

//function stopWebMapAppBottomDrag(e) {

//    document.onmousemove = webMapAppMoveFunction;
//    document.onmouseup = null;   
//    webMapAppCheckPanelHeights();
//    AdjustMapSize2();  
//    return false;
//}

function startUp2() {
    window.onrefresh = ClearGraphics();
} 

function adjustBottomPanelElements() {

    webMapAppPanelDisplay_Bottom.style.height =  webMapAppBottomPanelHeight + "px";
    webMapAppToggleDisplay2.style.height = webMapAppToggleHeight + "px";
    
    var sWidth = getWinWidth();
    var bWidth = sWidth - 2;
    var sHeight = getWinHeight()-5;

    var mWidth = sWidth - webMapAppPanelDisplayCell.clientWidth;
    
    webMapAppPanelDisplayCell_Bottom.style.display = "none";
    webMapAppPanelDisplayCell_Bottom.style.width = bWidth + "px";
    webMapAppToggleDisplay2.style.width = bWidth + "px";
    webMapAppPanelScrollDiv_Bottom.style.width = bWidth + "px";
    webMapAppPanelDisplayCell_Bottom.style.display = "block"; 
    
    webMapAppBottomTBCellDiv_DS.style.left = "393px";
    webMapAppBottomTBCellDiv_AL.style.left = "524px";
    
    var mHeight;
    if (!bottomDocked) {
        mHeight = sHeight - webMapAppTopBannerHeight - webMapAppPanelDisplayCell_Bottom.clientHeight+5;
        webMapAppPanelDisplayCell_Bottom.style.top = mHeight  + "px";
        webMapAppBottomTBCellDiv_DS.style.top = (mHeight + webMapAppTopBannerHeight + 10 + 3) + "px";
        webMapAppBottomTBCellDiv_AL.style.top = (mHeight + webMapAppTopBannerHeight + 10 + 3) + "px";
    } else {
        bottomDocked = false;
    }
}


//function webMapAppCheckPanelHeights() {
//    var maxHeight = 0;
//    var node; 
//    for (var i=0; i< webMapAppPanelDisplay_Bottom.childNodes.length; i++) {
//        if (webMapAppPanelDisplay_Bottom.childNodes[i].tagName=="TABLE") {
//            node = webMapAppPanelDisplay_Bottom.childNodes[i];
//            if (node.clientHeight>maxHeight) maxHeight = node.clientHeight; 
//        }
//    }  
//     webMapAppPanelDisplay_Bottom.style.height = maxHeight + "px";
//    return false;
//}


// function for adjusting element sizes when brower is resized
//function AdjustMapSize2() {

//    window.setTimeout("map.resizeToParent()", 500);
//    //window.setTimeout("resizeTheMap(" + mWidth + ", " + mHeight + ", false);", 500);

//    resetAllTitleBarBackgroundImages();
//    //webMapAppBottomPanelHeight = 0;
//    
//    return false;
//}





