
/**
 *	MAPS AND DIRECTIONS RESULT PAGE - MAP RESIZE
 * REQUIRES common.js TO BE LOADED FIRST
 */

var mapData = new function()
{
    this.minWidth               = 574;//this.width;542
    this.minHeight              = 542;//
    this.maxWidth               = 1400;

    this.resize                 = new function()
    {
        monitorDelay            = 250; // wait between checks for timer resizing
        sizeChanged             = false;
    }

    //browser data
    this.browser                = getBrowserInfo();
    this.browser.resizeLock     = true; // false if resize in progress
    this.browser.drawerWidth    = 208;

    // try to match offers height with map widget
    this.browser.matchHeight    = true;
    if(
        ((this.browser.name == "msie") && (this.browser.version < 6)) ||
        ((this.browser.name == "netscape") && (this.browser.version <= 7.0))
      )
    {
        this.browser.matchHeight    = false;
    }

    this.browser.bodyMargin = 60;  //i4 = 40
    if((this.browser.name == "msie") && (this.browser.version >= 5))
    {
        this.browser.bodyMargin = 30; //i4 = 20
    }

}   // mapData

/**
 * =PAGE INIT
 * @set page defaults after page load
 */
function pageInit()
{
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    
    // check for rightcolumn and sizing
    var rightColObj                     = document.getElementById("ad-div");
    mapData.browser.rightColumnWidth    = (document.getElementById("ad-div")) ? rightColObj.offsetWidth : 0;

    //set browser resize monitor
    //start resizing monitor for browsers with itchy window.resize event handling
    var resizeType =    ((mapData.browser.name == "msie" && mapData.browser.version >= 6) ||
                            (mapData.browser.name == "safari")) ? 1 : 0;// 1 = timer, 0 = resize
    resizeBrowserCheck(resizeType);
    
}//pageInit()

//addEvent(window, "load", pageInit);

/**
 * =RESIZE BROWSER CHECK
 * @checks for changes in browser size. ie and safari keep firing during window.resize
 */
function resizeBrowserCheck(fType)
{

    var browserSize = getBrowserSize();
    if((mapData.browser.previousHeight != browserSize.height) || (mapData.browser.previousWidth != browserSize.width))
    {   //set flag that size changed
        mapData.browser.previousHeight  = browserSize.height;
        mapData.browser.previousWidth   = browserSize.width;
        mapData.resize.sizeChanged      = true;
    }
    else if(mapData.resize.sizeChanged  == true)
    {   // values didn't match on previous lap, resize
        mapData.resize.sizeChanged  = false;
        resizeMapWidget();
    }

    if(fType == 1)
    {   // safari and ie have to loop this fn
        mapData.loop = setTimeout("resizeBrowserCheck(1)", mapData.resize.monitorDelay);
    }
    else if(fType == 0)
    {   //smart browsers get the resize event handler
         addEvent(window, "resize", resizeMapWidget);
         resizeMapWidget();
    }
} //resizeBrowserCheck()


/**
 * =RESIZE MAP WIDGET
 * @dynamically adjust map control graphics to remain bound to map when resizing
 * @make request for new map image
 */
function resizeMapWidget()
{
    var wrapperWidth;
    var wrapperHeight;
    var browserSize     = getBrowserSize();
    var mapWellWidth;
    if((this.browser.name == "msie") && (this.browser.version >= 5)){
    	mapWellWidth    = browserSize.width - mapData.browser.bodyMargin - mapData.browser.rightColumnWidth + 10 ;
    } else {
        mapWellWidth    = browserSize.width - mapData.browser.bodyMargin - mapData.browser.rightColumnWidth - 15;
    }
   // var mapWellWidth    = browserSize.width - mapData.browser.bodyMargin;

    if(mapWellWidth < mapData.minWidth)
    {   //too small, lock page and map at min
        wrapperWidth        = mapData.minWidth;
    }
    else if(mapWellWidth > mapData.maxWidth)
    {   //too big, lock at max
        wrapperWidth        = mapData.maxWidth;
    }
    else
    {   // flex
        wrapperWidth = mapWellWidth;
    }
    //space between mapwell and right column paid lists is more in all browsers except IE. Hence tightening it up for rest of the browsers
    if(mapData.browser.name != 'msie') wrapperWidth +=10;
    var newMapWidth = wrapperWidth;

    // request new map
    newMapData      = new function()
    {
        this.action = "resize";
        this.width  = Math.round(newMapWidth);
        //this.height = Math.round((this.width / 4.63) * 3.53); //get new height
        this.height = browserSize.height - mapData.browser.bodyMargin;
        if(this.height < mapData.minHeight)
        	this.height = mapData.minHeight;
    }
    
    setMap(newMapData.width, newMapData.height);
    showMapWidget();

    
} //resizeMapWidget()


/**
 * =GET NEW MAP
 * @make request for new map image
 */
function setMap(width, height)
{  
    	document.getElementById("panel").style.width = String(width)+"px";
    	document.getElementById("panel").style.height = String(height)+"px";

	mqSize = new MQSize(width, height);
	myMap.setSize(mqSize);
}


/**
 * =SHOW MAP WIDGET
 * @manually display the map widget
 */
function showMapWidget()
{
    document.getElementById("panel").style.visibility = "visible";
}// showMapWidget()

