﻿var MapResizeDirection = 3;
var control = null;

var pspage_MapWidthModifier = 215;
var pspage_MapHeightModifier = 358;
var pspage_MapMinWidth = 400;
var pspage_MapMinHeight = 300;


function AddMyControl() {
    var veMap = MDNGetVEMap();
    if (control == null && veMap != null) {
        control = document.getElementById('myControl');
        if (control != null) {
            control.style.display = '';

            veMap.AddControl(control);
            if (whichBrs() == 'Mozilla' || whichBrs() == 'Firefox') {

                control.style.marginLeft = '3px';
                control.style.marginTop = '2px';
                control.style.width = '16px';

            }
            if (whichBrs() == 'Safari') {

                control.style.marginLeft = '3px';
                control.style.marginTop = '2px';
                control.style.width = '16px';

            }
            document.getElementById('MSVE_navAction_container').style.left = '16px';
        }
    }
    $('#theMapTop').append('<img class="scaleBg" style="right: 0px; bottom: 15px; position:absolute; height:40px; width: 160px; z-index:25;" src="Images/whitepixel.gif" />');
}


function ResizeVEMap() {

    //     $('#debugPanel').append('<p>' + document.getElementById('mapWrapper').clientWidth + '</p>');
    //     
    //document.getElementById('divPadTool').style.width = '100%';
    w = document.getElementById('mapWrapper').clientWidth;
    if (whichBrs() == 'Mozilla' || whichBrs() == 'Firefox') {

        if (w < 500) {
            w = w - 1;
        }
        else {
            w = w + 5; //this doesn't work for some reason
        }

    }
    //todo: this is undefined but still works.
    try {
        MDNGetVEMap().Resize(w, 300);
    }
    catch (ex) {

    }
    // document.getElementById('divPadTool').style.width = w + 'px';

}



function ResizeMapNew() {

    //todo: this is undefined but still works.
    try {
	 //need to use theLayout.panes.east to fixe a bug in ie6.
        MDNGetVEMap().Resize(theLayout.panes.east.width(), theLayout.panes.east.height() - 15);
    }
    catch (ex) {

    }
    

}


function resizeOnLoad() {
    var x = readCookie('rpcMapCookie')
    if (x) {
        //found cookie, use its value
        resizeMapBase(x);
    } else {
        //no cookie, monster not happy
        resizeMapBase(1);
    }
}
function resizeBase() {
    resizeMapBase(MapResizeDirection);
}
function resizeMapBase(typeId) {
    var spnResize = document.getElementById('spnResize')
    control = document.getElementById('myControl');
    if (control != null) {
        control.style.display = 'none';
    }
    eraseCookie('rpcMapCookie');
    createCookie('rpcMapCookie', typeId, 0);
    var w = (MDNGetClientWidth()) - pspage_MapWidthModifier;
    var h = MDNGetClientHeight() - pspage_MapHeightModifier;
    if (w < pspage_MapMinHeight) { w = pspage_MapMinHeight; }
    if (h < pspage_MapMinHeight) { h = pspage_MapMinHeight; }
    if (typeId == 1) {
        shrunkMap(h, w);
        if (spnResize != null) {
            spnResize.style.backgroundImage = "url(Images/rpcBtnExpandTop.gif)";
            spnResize.title = "Expand the Map Control";
        }
        MapResizeDirection = 3;
    } else if (typeId == 2) {
        widenMap(h, w);
        if (spnResize != null) {
            spnResize.style.backgroundImage = "url(Images/rpcBtnShrinkTop.gif)";
            spnResize.title = "Collapse the Map Control";
        }
        MapResizeDirection = 1;
    } else if (typeId == 3) {
        widenMap2(h, w);

        if (spnResize != null) {
            spnResize.style.backgroundImage = "url(Images/rpcBtnShrinkTop.gif)";
            spnResize.title = "Collapse the Map Control";
        }
        MapResizeDirection = 1;
    }

    var veMap = MDNGetVEMap();

    var elem = document.getElementById("shapeEditDiv");
    elem.style.top = (veMap.GetTop() + 60) + 'px';
    elem.style.left = (veMap.GetLeft() + 60) + 'px';

    if (control != null) {
        control.style.display = '';
    }

}
function shrunkMap(h, w) {
    h = 300;
    document.getElementById('mapWrapper').className = 'shrunk';
    document.getElementById('mapSpacer').className = 'spacer_shrunk';
    document.getElementById(MDNGetVEMapContainerID()).style.height = h + 'px';
    document.getElementById(MDNGetVEMapContainerID()).style.width = '100%';
    ResizeVEMap();
    //document.getElementById('divPadTool').style.marginLeft = '-2px';
    document.getElementById('theMapTop').style.marginLeft = '-2px';
    setTimeout("MDNEnvelopeChangeReady();", 2000);
}
function widenMap(h, w) {
    h = h - 50;
    document.getElementById('mapWrapper').className = 'expanded';
    document.getElementById('mapSpacer').className = 'spacer_expanded';
    document.getElementById(MDNGetVEMapContainerID()).style.height = h + 'px';
    document.getElementById(MDNGetVEMapContainerID()).style.width = '100%';
    ResizeVEMap();
    //document.getElementById('divPadTool').style.marginLeft = '0px';
    document.getElementById('theMapTop').style.marginLeft = '0px';
    setTimeout("MDNEnvelopeChangeReady();", 2000);
}
function widenMap2(h, w) {
    document.getElementById('mapWrapper').className = 'expanded';
    document.getElementById('mapSpacer').className = 'spacer_expanded';
    document.getElementById(MDNGetVEMapContainerID()).style.height = h + 'px';
    document.getElementById(MDNGetVEMapContainerID()).style.width = '100%';
    ResizeVEMap();
    //document.getElementById('divPadTool').style.marginLeft = '0px';
    document.getElementById('theMapTop').style.marginLeft = '0px';

    setTimeout("MDNEnvelopeChangeReady();", 2000);
}




//setTimeout("AddMyControl();",1500);
//setTimeout("resizeOnLoad();",1500);

/*******************Currently not used*************************
function DeleteControl(contrId){
var myControl = document.getElementById(contrId);
if (myControl!=null)
{
var myControlID = myControl.id;
MDNGetVEMap().DeleteControl(myControl);
RemoveShim('myShim');
alert("Control " + myControlID + " has been deleted.");
}
else
{
alert("No control with ID " + myControlID + " was found.");
return;
}    
}
function addShim(el){
var shim = document.createElement("iframe");
shim.id = "myShim";
shim.frameBorder = "0";
shim.style.position = "absolute";
shim.style.zIndex = "1";
shim.style.overflow = "hidden";
shim.style.top  = el.offsetTop;
shim.style.left = el.offsetLeft;
shim.width  = el.offsetWidth;
shim.height = el.offsetHeight;
el.shimElement = shim;
el.parentNode.insertBefore(shim, el);
}
function RemoveShim(sid) //remove iframe shim      
{             
var msh = document.getElementById(sid);     
if (msh!=null) msh.parentNode.removeChild(msh);      
msh = null;     
} 

*/