﻿// ******************************************************
//                   RESIZE FUNCTIONS 
// ******************************************************

var reloadTimer = null;

// Init function
function init(){
  // Init the mapminx,mapminy,mapmaxx,mapmaxy
  getMapExtent();
  
  // set window resize event handler
  window.setTimeout('$addHandler(window, "resize", AdjustMapSizeHandler);', 1000); 
  
  // because the toolbar is listed before the map control,
  //  make sure toolbar will be listening to changes in map extent
  var toolbar = $find('Toolbar1');
  if (map == null) map = $find('Map1');
  if (map != null && toolbar!=null) {
    toolbar.add_onToolSelected(OnToolSelectHandler);
    window.setTimeout("resetMapHistory();", 1500);
  }  
  
  // Show the schools by address panel
  setPanel('Panel_SchoolsByAddress');  
  
}
  

function resetMapHistory() {
  map = $find('Map1');
  var toolbar = $find('Toolbar1'); 
  map._currentExtentHistory = 0;
  var tbElem = Toolbars[toolbar._uniqueID];
  var backButton = tbElem.items[tbElem.btnMapBack];
  if (backButton) { backButton.disabled = true; }
  var forwardButton = tbElem.items[tbElem.btnMapForward];
  if (forwardButton) { forwardButton.disabled = true; }
  tbElem.refreshCommands();
} 

function OnToolSelectHandler(sender, args) {
  if (args.name) {
    var mode = args.name;
    if (mode!="Measure") closeMeasureToolbarTool();
//    if (mode!="MapIdentify") {
//      if (closeIdentifyPanel)
//        closeIdentifyPanel();
//    }
  }
}

// handler for window resize
function AdjustMapSizeHandler(e) {
  window.clearTimeout(reloadTimer);
  reloadTimer = window.setTimeout("AdjustMapSize();", 1000);
}

// adjust map size - when browser is resized
function AdjustMapSize() { 
  // refresh the map 
  if (this.map != null) {
    if (this.LastMapWidth != this.CurrentMapWidth || this.LastMapHeight != this.CurrentMapHeight) {
      this.map.checkMapsize();
    }
  } else {
    window.setTimeout("AdjustMapSize();", 1000); 	  
  }
  return false;
}
