﻿// ***************** GLOBAL VARIABLES *************** 
// The map and map data service
    var VE_map = null;         // VE Map control
    var VE_dataClient = null;  // VE Data base event fetcher tied to VE_map
    var VE_dataLayer = null;   // Shape layer containing event pins/icons
    
//--------------------------------------------------------------------------// 
// GetMap() -- Initialize the VE map widget here                            // 
//--------------------------------------------------------------------------// 
function GetMap()
  {
  // If the map hasn't been defined...get it
    if(VE_map == null)
      {
      // settings  
        var origin = new VELatLong(parseFloat(const_VEMapOriginLat),parseFloat(const_VEMapOriginLon));	
        var zoom = 2;

      // create it    
        VE_map = new VEMap('div_VEMap');
      //  VE_map.SetClientToken(veClientToken); // veClientToken is setup during server side Page_load
        VE_map.SetDashboardSize(VEDashboardSize.Tiny);
        VE_map.LoadMap(origin, zoom);
        VE_map.SetMapStyle(VEMapStyle.Hybrid);
        VE_map.SetMouseWheelZoomToCenter(false);  // zoom to cursor
      //  VE_map.HideDashboard();

      // set up view options   
      //  document.getElementById("MSVE_navAction_FlatlandMapMode").style.display = "none"; 
      //  document.getElementById("MSVE_navAction_View3DMapMode").style.display = "none"; 
      //  document.getElementById("MSVE_navAction_ObliqueMapView").style.display = "none"; 
     
      // hook up event server to the map          
        VE_dataClient = new ReportStorms.DataClient(VE_map);  

      // disable the native bubbles -- no description text with the pins, so no point in bothering
        VE_map.AttachEvent("onmouseover", function(e){return true;});
      // clicked icon launches to reportstorms.com main site 
        VE_map.AttachEvent("onclick",       JumpToWXC);
      // keyboard (block certain events)
        VE_map.AttachEvent("onkeydown", VE_CatchKeyDown);
      
      // With fluid layout, override window onresize for cross-browser compatibility
        window.onresize = VE_MapDivResize;

      // Now that it's up, get the data and populate it with push pins      
        if(VE_dataClient != null) 
          VE_dataClient.LINQGetEventTypesEnumeration();
      //  VE_dataClient.GetMapData(); called in async cal back from LINQGetEventTypesEnumeration
      }
  } 
//--------------------------------------------------------------------------//
// JumpToWXC -- link to WXC.com website                                     //
//--------------------------------------------------------------------------//
  function JumpToWXC(e)
    {
    if(e.elementID != null)
      {
      // access the pushpin to get the description text (eventID)
        var infoShape = VE_map.GetShapeByID(e.elementID);
        var eventID = infoShape.GetDescription();
        if(eventID != null)
          window.open('http://www.reportstorms.com?eventID=' + eventID , 'newwindow');
        else
          window.open('http://www.reportstorms.com', 'newwindow');
      }
    }    
//--------------------------------------------------------------------------//
// VE_CatchKeyDown() -- VE has shortcut (press "3") to jump to 3D mode      //
//                      which needs to be blocked to prevent 3D mode        //
//--------------------------------------------------------------------------//
function VE_CatchKeyDown(e)
  {
  if(e.keyCode == 51 ||  // 3D
     e.keyCode == 66 ||  // birds eye
     e.keyCode == 79)    // birds eye
    return true;
  }    
  
//--------------------------------------------------------------------------//
// mapDivResize() -- Browser window resize                                  //
//--------------------------------------------------------------------------//
function VE_MapDivResize()
  {
  // make sure there's something to work with!
    if(VE_map == null) return;
    
    var formDiv = document.getElementById('form1');
    if(formDiv == null) return;
    var mapDiv = document.getElementById('div_VEMap');
    if(mapDiv == null) return;
    
    var x = mapDiv.clientWidth;
    var y = mapDiv.clientHeight;    
    VE_map.Resize(x, y); 
  }
//--------------------------------------------------------------------------// 
// pageLoad() -- When the main page has loaded, this method is called.      //
//--------------------------------------------------------------------------// 
  function pageLoad() 
    {
    // set up VE 
      GetMap(); 
    // resize it immediately  
      VE_MapDivResize();
    }

