﻿var _showingMap = false;

function showPopupMask()
{
    var mask = document.getElementById('popupMask');
    if (mask != null) {

        var pageContainer = document.getElementById('pageContainer');
    
        mask.style.height = Math.max(pageContainer.clientHeight, getViewportHeight()) + "px";
        mask.style.width = Math.min(pageContainer.clientWidth, getViewportWidth()) + "px";
        
        mask.style.display = 'block';
    }
}

function hidePopupMask()
{
    var mask = document.getElementById('popupMask');
    
    if (mask != null)
    {
        mask.style.display = 'none';
    }
}

function getDetailDiv(divId) {
    return document.getElementById(divId);
}

function hideDetailWindow(divId) {
    if (_showingMap) {
        _showingMap = false;
        GUnload();
        hideDetailWindow("mapContainer");
    }
    else 
    {
        var detailDiv = getDetailDiv(divId);

        if (detailDiv != null) {
            $("#" + divId).hide('fold', null, 300, null);
            hidePopupMask();
        }
    }
}

function showDetailsWindow(divId, theFunc) {
    var detailDiv = getDetailDiv(divId);

    if (detailDiv != null) {
        
        var viewportHeight = getViewportHeight();
        var viewportWidth = getViewportWidth();

        var xPos = ((viewportWidth / 2) - (stripPXFromString(detailDiv.style.width) / 2));
        var yPos = ((viewportHeight / 2) - (stripPXFromString(detailDiv.style.height) / 2));

        var scrollTop = f_scrollTop();

        if (scrollTop != 0) {
            yPos += scrollTop; 
        }

        detailDiv.style.left = xPos + 'px';
        detailDiv.style.top = yPos + 'px';

        $("#" + divId).show('fold', null, 500, theFunc);     
    }
}
function showMap() {
    showPopupMask();
    
    _showingMap = true;
    showDetailsWindow("mapContainer", function() { mapInitialize(); });
}
function hideMap() {
    _showingMap = true;
    hideDetailWindow("mapContainer");
}