var div = null;
var layerList = null;
var activeOverlay;

function SetActiveOverviewOverlay(name)
{
    if(activeOverlay != name)
    {
        ToggleLayer(activeOverlay, false);
        ToggleLayer(name, true);
        activeOverlay = name;
    }
}

function ToggleLayer(name, active)
{
    if (active == true)
    {
            MSR.CVE.ActivateAlphaLayer(map, layerList, name);
    }
    else
    {
            MSR.CVE.DeactivateAlphaLayer(map, name);
    }
}


function GetSize()
{
    var myWidth = 0, myHeight = 0;

    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    if (myWidth > 0)
    {
            var result = new Array();
            result[0] = myWidth;
            result[1] = myHeight;
            return result;
    }
    else
    {
            return null;
    }
}

function SetMapSize()
{
    var browserSize = GetSize();

    var div = document.getElementById("myMap");

    if (browserSize != null)
    {
        div.style.width = (browserSize[0] - 25) + "px";
        div.style.height = (browserSize[1] * 0.75) + "px";
    }
    else
    {
        div.style.width = "800px";
        div.style.height = "600px";
    }
    div.style.overflow = "hidden";
    div.style.position = "relative";
}


function LoadOverlay()
{
    //SetMapSize();
    //window.onresize = SetMapSize;

    //map = new VEMap('myMap');
    //map.LoadMap();
    //map.SetMapStyle('h');

    layerList = MSR.CVE.ImportLayersFromAnchorHRef("CrunchedLayers");
    MSR.CVE.StartAutomaticLegends(map, layerList);
    var permalinkProvided = MSR.CVE.ApplyPermalink(map, document.layerCheckboxForm);
    /*
    if (!permalinkProvided) {
        MSR.CVE.ActivateAlphaLayer(map, layerList, 'BL');
        MSR.CVE.SetCenterAndZoomForLayer(map, layerList, 'BL');
    }
    */
}

