function MapManager(idMapContainer, idMiniMapContainer) {
this.idMapContainer = idMapContainer;//id for html container of veMap
this.idMiniMapContainer = idMiniMapContainer;

this.objMapContainer = getById(this.idMapContainer);//Html obj reference for map container
this.objMiniMapContainer = getById(this.idMiniMapContainer);

this.veMap = new VEMap(this.idMapContainer);//Real Ve Map object   
this.veMiniMap = new VEMap(this.idMiniMapContainer);

this.scaleBarDistanceUnit = VEDistanceUnit.Kilometers;//ScaleBarDistanceUnit unit (kilometers or miles)
this.routeDistanceUnit    = VERouteDistanceUnit.Kilometer;

this.veShapeLayerCollections = new Array();
this.veShapeLayerCollectionsLatLong = new Array();
this.veShapeCollections = new Array();
this.veShapeCollectionsById = new Array();

this.defaultZoomLevelToShowShape = 16;
this.addressIcon = 'images/pushpins/pushpin.png';
this.departure="";
this.arrival="";

//### Methods ################

// -- GetMap -------------------------------
this.GetMap=function(){return this.veMap;}

// -- Get/Set scaleBarDistanceUnit -------------------------------
this.GetScaleBarDistanceUnit=function(){return this.scaleBarDistanceUnit;}

this.SetScaleBarDistanceUnit = function(distanceUnit){ 
this.scaleBarDistanceUnit = distanceUnit;
this.veMap.SetScaleBarDistanceUnit(this.scaleBarDistanceUnit);
}

// -- Get/Set departure and arrival-------------------------------
this.GetDeparture = function(){return this.departure;}
this.SetDeparture = function(departure){this.departure = departure;}
this.GetArrival = function(){return this.arrival;}
this.SetArrival = function(arrival){this.arrival = arrival;}  
// -- Get/Set routeDistanceUnit -------------------------------
this.GetRouteDistanceUnit = function(){return this.routeDistanceUnit;}
this.SetRouteDistanceUnit = function(distanceUnit){this.routeDistanceUnit = distanceUnit;}

/*
this.ShowHideTraffic=function(showTraffic){
if(showTraffic){ 
this.veMap.LoadTraffic(true);     
this.veMap.ShowTrafficLegend(50, 50);//x-coordinate and y-coordinate of the top-left corner      
this.veMap.SetTrafficLegendText("The traffic legend");//Specifies the text shown with the traffic legend, if visible.
}
else
this.veMap.HideTrafficLegend();
}

this.ClearTraffic=function(){this.veMap.ClearTraffic();}//Clears the traffic map
*/

// -- ResizeTo ----------------------------
this.ResizeTo = function(width, height){
this.objMapContainer.style.width = (width - 5) + "px"
this.objMapContainer.style.height = height + "px";
this.veMap.Resize(width, height); 
}

// -- LoadMap ----------------------------
// lat: MANDATORY, value of latitude
// lon: MANDATORY, value of longitude
// zoom: OPTIONAL, The zoom level to display. Valid values range from 1 through 19. Optional. Default is 4.
// style: OPTIONAL, A VEMapStyle Enumeration value specifying the map style. Optional. Default is VEMapStyle.Road.
// fixed: OPTIONAL, A Boolean value that specifies whether the map view is displayed as a fixed map that the user cannot change. Optional. Default is false.
// mode: OPTIONAL, A VEMapMode Enumeration value that specifies whether to load the map in 2D or 3D mode. Optional. Default is VEMapMode.Mode2D.
// showSwitch: OPTIONAL, A Boolean value that specifies whether to show the map mode switch on the dashboard control. Optional. Default is true (the switch is displayed).
// tileBuffer: How much tile buffer to use when loading map. Default is 1 (load an extra boundary of one tile). This parameter is ignored in 3D mode.
this.LoadMap = function( lat, lon, zoom, style, fixed, mode, showSwitch, tileBuffer) {
this.veMap.LoadMap(new VELatLong(lat,lon), zoom, style, fixed, mode, showSwitch, tileBuffer);
this.veMap.SetScaleBarDistanceUnit(this.scaleBarDistanceUnit);
this.InitializeDashboard();
} 

this.LoadMiniMap=function(lat, lon, zoom, style, fixed, mode, showSwitch, tileBuffer) {
this.veMiniMap.LoadMap(new VELatLong(lat, lon), zoom, style, fixed, mode, showSwitch, tileBuffer);
this.veMiniMap.HideDashboard();     
} 

// -- GetItinerary ----------------------------
// locations: An array of objects specifying the points through which the route must pass. The points can be either VELatLong Class objects or String objects.
// distanceUnit: A VERouteDistanceUnit Enumeration value specifying the units used for the route. Optional.
this.GetItinerary = function( locations, distanceUnit, routeOptimize ) {
mapManager.SetRouteDistanceUnit(distanceUnit=="k" ? VERouteDistanceUnit.Kilometer : VERouteDistanceUnit.Mile);        
var options = new VERouteOptions;
options.DrawRoute = true;
options.UseMWS = true;   
options.RouteColor = new VEColor(100, 100, 100, 0.7);
options.DistanceUnit = mapManager.GetRouteDistanceUnit();
options.SetBestMapView = true;
options.RouteWeight = 5;
options.RouteCallback = ShowTurns;
options.ShowDisambiguation = false;
options.RouteOptimize = routeOptimize;
options.ShowErrorMessages = false;

try{
this.veMap.GetDirections(locations, options);
}catch(VEException) {}   
this.InitializeDashboard();      
} 

this.LoadAddress = function( infoBoxTitle, infoBoxContent, lat, lon, zoomLevel, style, orientation) {      
this.ClearAll();
var latLon = new VELatLong(lat, lon);

zoomLevel=(zoomLevel==null?this.defaultZoomLevelToShowShape:zoomLevel);
style=(style==null? VEMapStyle.Shaded : style);
if(style!=VEMapStyle.Birdseye) {
this.veMap.SetMapStyle(style);
this.veMap.SetCenterAndZoom(latLon, zoomLevel);
}  
else { 
orientation=(orientation==null ? "North" : orientation);  
mapManager.GetMap().SetBirdseyeScene(latLon, orientation);
} 

var shapeLayer = this.veShapeLayerCollections['addressLayerKey'];
if(shapeLayer==null) {
shapeLayer = new VEShapeLayer();
this.veShapeLayerCollections['addressLayerKey'] = shapeLayer;
this.veMap.AddShapeLayer(shapeLayer);
}

var shapeAddress = new VEShape(VEShapeType.Pushpin, latLon);
shapeAddress.SetTitle(infoBoxTitle);  
shapeAddress.SetDescription(infoBoxContent);
shapeAddress.SetCustomIcon(this.addressIcon);  

shapeLayer.AddShape(shapeAddress);
this.veShapeCollections['addressKey'] = shapeAddress.GetID();
this.veMap.ShowInfoBox(shapeAddress);
}

this.GetAddressLat = function(){
var shape = this._getShape('addressKey');
if(shape==null)return;
return shape.GetPoints()[0].Latitude;
}

this.GetAddressLong = function(){
var shape = this._getShape('addressKey');
if(shape==null)return;
return shape.GetPoints()[0].Longitude;
}

this.HasAddressSet = function(){return this._getShape('addressKey') != null;}

this.ClearAll = function() {
if(this.veMap != null){
this.veMap.Clear();
this.veMap.DeleteRoute();
} 
this.veShapeLayerCollections = new Array();
this.veShapeLayerCollectionsLatLong = new Array();
this.veShapeCollections = new Array();
this.veShapeCollectionsById = new Array();
this.departure = "";
this.arrival = "";
}

this.Dispose = function(){if(this.veMap!=null)this.veMap.Dispose();}
this.GetLat = function(){return this.GetCenter().Latitude;}
this.GetLong = function(){return this.GetCenter().Longitude;}
this.GetLatTop = function(){return this.veMap.GetMapView().TopLeftLatLong.Latitude;}
this.GetLongLeft = function(){return this.veMap.GetMapView().TopLeftLatLong.Longitude;}
this.GetTopLeftLatLong = function(){return this.veMap.GetMapView().TopLeftLatLong;}
this.GetMiniMapZoomLevel = function(){return this.veMiniMap.GetZoomLevel();}
this.GetZoomLevel = function(){return this.veMap.GetZoomLevel();}
this.SetZoomLevel = function(zoomLevel){return this.veMap.SetZoomLevel(zoomLevel);}
this.GetMapStyle = function(){return this.veMap.GetMapStyle();}
this.SetMapStyle = function(style){this.veMap.SetMapStyle(style);}

this.GetCenter = function(){
var latLong = null;
if(this.GetMapStyle() == VEMapStyle.Birdseye) {
var birdEyeImage = this.veMap.GetBirdseyeScene();
latLong = this._getLatLongBirdEyeImage(birdEyeImage);
}        
return (latLong != null ? latLong : this.veMap.GetCenter());
}

this.GetOrientation = function(){
var imageOrientation = null;
if (this.GetMapStyle()==VEMapStyle.Birdseye) {
var birdEyeImage = this.veMap.GetBirdseyeScene();
imageOrientation = birdEyeImage.GetOrientation();
}
return imageOrientation;
}

this.AddShape = function(shapeLayerKey, shapeKey, shape){
var shapeLayer = this.veShapeLayerCollections[shapeLayerKey];
if(shapeLayer==null) {
shapeLayer = new VEShapeLayer();
this.veShapeLayerCollections[shapeLayerKey] = shapeLayer;
this.veMap.AddShapeLayer(shapeLayer);
}
if( shapeLayer.GetShapeCount()==0)
this.veShapeLayerCollectionsLatLong[shapeLayerKey] = this._buildShapeLayerLatLongInfo();
shapeLayer.AddShape(shape);
this.veShapeCollections[shapeKey] = shape.GetID();
this.veShapeCollectionsById[shape.GetID()] = shapeKey;
}

this.ShowShape = function(shapeKey, openInfo, zoomLevel){
var shape = this._getShape(shapeKey);
if(shape==null)return;
if(openInfo==null)openInfo=true;
if(zoomLevel==null)zoomLevel=this.defaultZoomLevelToShowShape;
if(zoomLevel==-1)zoomLevel=this.veMap.GetZoomLevel();
this.veMap.SetCenterAndZoom(shape.GetIconAnchor(), zoomLevel);
if(openInfo)this.ShowInfoBox(shapeKey, 1000);  
}

this.ShowShapeByID = function(shapeID){
var currentShape = this.veMap.GetShapeByID(shapeID);
this.veMap.SetCenterAndZoom(currentShape.GetIconAnchor(), 17);
// if( openInfo )
//     this.ShowInfoBox(shapeKey, 1000);
}    

this.HideShape = function(shapeKey){
var shape = this._getShape(shapeKey);
if(shape==null)return;
this.veMap.HideInfoBox();
shape.Hide();
}

this.GetShapeKeyById = function(shapeId){return this.veShapeCollectionsById[shapeId];}

this.ChangeVisibility = function(shapeKey){    
var shape = this._getShape(shapeKey);
if(shape==null)return;
if(shape.GetVisibility()) {
this.veMap.HideInfoBox();
shape.Hide();
}
else
shape.Show();
}

this.ShowInfoBox = function(shapeKey, delay){   
var shape = this._getShape(shapeKey);
if(shape==null)return;
//if not visible showInfo is an error.....
if(!shape.GetVisibility())return;  
if(delay==null||delay==0)
this.veMap.ShowInfoBox(shape);
else{
var doDelayed = 'eval("mapManager.ShowInfoBox(\'' + shapeKey + '\');");';
window.setTimeout(doDelayed, delay);
}
}

this.HideInfoBox = function(){this.veMap.HideInfoBox();}
this.GetShapeLayer = function(shapeLayerKey){return this.veShapeLayerCollections[shapeLayerKey];}

// -- ClearShapeLayer --------------------------
this.ClearShapeLayer = function(shapeLayerKey){
var shapeLayer = this.veShapeLayerCollections[shapeLayerKey];
if( shapeLayer != null ) {
shapeLayer.DeleteAllShapes();
this.veShapeLayerCollectionsLatLong[shapeLayerKey] = '';
}
}

// -- ShowShapeLayer --------------------------
this.ShowShapeLayer = function(shapeLayerKey){
var shapeLayer = this.veShapeLayerCollections[shapeLayerKey];
if(shapeLayer!=null)shapeLayer.Show();
}

this.ShapeLayerLatLongInfoWasChanged = function(shapeLayerKey) {
var latLongInfo = this.veShapeLayerCollectionsLatLong[shapeLayerKey];
if(latLongInfo!=null)return latLongInfo!=this._buildShapeLayerLatLongInfo();
return true;
}

// -- HideShapeLayer --------------------------
this.HideShapeLayer = function(shapeLayerKey){
var shapeLayer = this.veShapeLayerCollections[shapeLayerKey];
if(shapeLayer!=null)
shapeLayer.Hide();
}

// -- InitializeDashboard --------------------------
this.InitializeDashboard = function(){
  /*
setTitleAttr('Compass',MESSAGES_DASHBOARD['Compass']);  
setTitleAttr('MSVE_navAction_tinyZoomBar_plus',MESSAGES_DASHBOARD['MSVE_navAction_tinyZoomBar_plus']);
setTitleAttr('MSVE_navAction_tinyZoomBar_minus',MESSAGES_DASHBOARD['MSVE_navAction_tinyZoomBar_minus']);
setTitleAttr('MSVE_navAction_toggleGlyphWrapper',MESSAGES_DASHBOARD['MSVE_navAction_toggleGlyphWrapper']);       
setTitleAttr('MSVE_navAction_HybridMapStyle',MESSAGES_DASHBOARD['MSVE_navAction_HybridMapStyle_title']);
//setTitleAttr('MSVE_obliqueCompassContainer', MESSAGES_DASHBOARD['MSVE_obliqueCompassContainer']);
setTitleAttr('MSVE_navAction_ccw',MESSAGES_DASHBOARD['MSVE_navAction_ccw']);
setTitleAttr('MSVE_navAction_cw',MESSAGES_DASHBOARD['MSVE_navAction_cw']);
//setInnerHTML("MSVE_obliqueNotifyText", MESSAGES_DASHBOARD['MSVE_obliqueNotifyText']);
setInnerHTML("MSVE_navAction_HybridMapStyle",MESSAGES_DASHBOARD['MSVE_navAction_HybridMapStyle']);
getById("MSVE_navAction_HybridMapStyle").onclick = function(){showScratchPad();}
*/
  
getById("MSVE_navAction_AerialMapStyle").onclick = function(){showScratchPad();}
setTitleAttr('MSVE_navAction_AerialMapStyle',MESSAGES_DASHBOARD['MSVE_navAction_AerialMapStyle_title']);
setInnerHTML("MSVE_navAction_AerialMapStyle",MESSAGES_DASHBOARD['MSVE_navAction_AerialMapStyle']);  
  
getById("MSVE_navAction_RoadMapStyle").onclick = function(){mapManager.SetMapStyle('s');showScratchPad();}
setInnerHTML("MSVE_navAction_RoadMapStyle",MESSAGES_DASHBOARD['MSVE_navAction_RoadMapStyle']);
setTitleAttr('MSVE_navAction_RoadMapStyle',MESSAGES_DASHBOARD['MSVE_navAction_RoadMapStyle_title']);

getById("MSVE_navAction_ObliqueMapView").onclick = function(){if(getById('MSVE_navAction_ObliqueMapView').className != "MSVE_MapStyle_disabled")setDisplayNone("scratchPad");}
setInnerHTML("MSVE_navAction_ObliqueMapView", 'Vista Aerea');

setInnerHTML("MSVE_navAction_showLabels",'Nomi'); 
}

// -- Utility methods  ----------- 
this._getShape = function(shapeKey) {
if(shapeKey==null)return null;
var shapeID = this.veShapeCollections[shapeKey];
if(shapeID==null)return null;
return this.veMap.GetShapeByID(shapeID);
}

this._buildShapeLayerLatLongInfo = function(){return this.GetLat() + '|' + this.GetLong() + '|' + this.veMap.GetZoomLevel();}  
this._getLatLongBirdEyeImage = function(birdEyeImageObj){
var pixel = birdEyeImageObj.LatLongToPixel(this.veMap.GetCenter(), this.veMap.GetZoomLevel());
var latLong = birdEyeImageObj.PixelToLatLong(pixel, this.veMap.GetZoomLevel());
var shape = new VEShape(VEShapeType.Pushpin, latLong);
shape.Hide();
this.veMap.AddShape(shape);
return shape.GetIconAnchor();
}    
}