﻿var _wwt_map = null;

function _wwt_Start() {
    _panels_expanded_h = document.getElementById("Washington");      
}

function _wwt_SwitchPanel(next_expanded_h, cityName) {        
    panels_switchPanel(next_expanded_h);            
    $get('myMap').style.height = $get('dataRow').offsetHeight + 'px'; 
    
    _wwt_CenterMap(cityName);
    _wwt_map.Resize();
}

function _wwt_GetMap() {

    if (_wwt_map != null) {
        _wwt_map.Dispose();
    }
    
    var NY = new VELatLong(40.726676,-73.995304);
    
    _wwt_map = new VEMap('myMap');
    _wwt_map.SetDashboardSize(VEDashboardSize.Small);
    _wwt_map.LoadMap(NY, 12, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1) ;

    _wwt_PlotAddresses(); 
    _wwt_SwitchPanel(
        document.getElementById('New York')
    );
}

function _wwt_PlotAddresses() {
    var locations = PageVariables.MapLocations;
    if (locations && (locations.length > 0)) {
        for (var i = 0; i < locations.length; i++) {
            var location = locations[i]; 
            var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(location.Location.Latitude,location.Location.Longitude));
            shape.SetTitle(location.Name); 
            shape.SetDescription(location.Description); 
            shape.SetCustomIcon(Master.ImagePath + "flashingbolt_marker.gif"); 
            _wwt_map.AddShape(shape);
        }
    }
}

function _wwt_CenterMap(cityName) {
    var cities = PageVariables.MapCities;
    if (cities && (cities.length > 0)) {
        for (var i = 0; i < cities.length; i++) {
            if (cities[i].Name == cityName) {
                if (cities[i].Points && (cities[i].Points.length > 0)) {
                    var points = new Array();
                    for (var j = 0; j < cities[i].Points.length; j++) {
                        points.push(new VELatLong(cities[i].Points[j].Latitude, cities[i].Points[j].Longitude))
                    }             
                    if (points.length == 1) {
                        _wwt_map.SetCenterAndZoom(points[0],16);
                    } else {
                        _wwt_map.SetMapView(points); 
                    }
                }                
                break;
            }
        }
    }
}
 
if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
if(typeof(Sys) !== "undefined") Sys.Application.add_load(_wwt_GetMap);