var map = null;
		  
var mapZoom = 4;                 //Zoom level on the map : 1 to 19/21
var mapStyle = "r";              //Style of the map : a=aerial; h=hybrid; r=route
var latitude = 46.9202;          //Point to set center on France
var longitude = 2.1094;          //
var mapFixed = false;	           //True=display only; false=complete control
var mapMode = VEMapMode.Mode2D;  //Display mode : Mode2d; Mode3d
var mapDashboard = true;         //True=display the switch mode in dashboard;
                               //False=hide
							   
var feedPath = "http://boonaert.net/pages/articles/VE/ve_georss/shapefeed.xml";
							   
							   
//--- Virtual Earth functions

function GetMap()
{
  //Instanciate the MapControl
  map = new VEMap('myMap');
 
  //Set the onload event
  map.onLoadMap = onMapLoaded; 
  
  //Load the map
  map.LoadMap(new VELatLong(latitude,longitude), 
              mapZoom, mapStyle, mapFixed, mapMode, mapDashboard);
  
  //Set infos and properties 
  map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
     
  //Events
  map.AttachEvent("onobliqueenter", showBirdMode);
  map.AttachEvent("onobliqueleave", hideBirdMode);
}

function ChangeMapStyle(sMapStyle) 
{
  if(mapStyle != sMapStyle) {
    mapStyle = sMapStyle;
    map.SetMapStyle(mapStyle);
	if(mapStyle == 'VEMapStyle.BirdseyeHybrid')
	  changeVisibility('birdOrientation','visible');
	else 
	  changeVisibility('birdOrientation','hidden');
  }             
}

function ChangeMapMode(sMapMode) 
{
  if(mapMode != sMapMode) {	  
	mapMode = sMapMode;
	
    ChangeMapStyle('h');		
    map.SetMapMode(sMapMode);
	
	if(mapMode == VEMapMode.Mode3D) 
	  changeVisibility('mode3d_option','visible');
	else 
	  changeVisibility('mode3d_option','hidden');
  }
}

function SetBirdseyeOrientation(sOrientation)
{
    map.SetBirdseyeOrientation(sOrientation);
	changeBack('bird_arrow', 'images/toolbox/bird_' + sOrientation + '_f.png');
}


//--- event functions
function onGeoRSSFeedLoad(feed)
{
	document.getElementById("ve_info").innerHTML = "Flux GeoRSS charge - ";
	document.getElementById("ve_info").innerHTML += feed.GetShapeCount(); 
	document.getElementById("ve_info").innerHTML += " elements ajoutes";
	document.getElementById("ve_info").style.visibility = "visible";
}

function onMapLoaded()
{
	map.HideDashboard();
    //Adding the geoRss informations
    var layer = new VEShapeLayer();    
    var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, feedPath, layer);  
    map.ImportShapeLayerData(veLayerSpec, onGeoRSSFeedLoad, true);
}

function showBirdMode(e) 
{
	changeVisibility('modeBird', 'visible');
}

function hideBirdMode(e) 
{
	changeVisibility('modeBird', 'hidden');
}


//--- CSS tips functions
function changeBack(sIdElement, sUrl) 
{
  document.getElementById(sIdElement).style.background= "url('" + sUrl + "')" ;
}

function changeVisibility(sIdElement, sState) 
{
  document.getElementById(sIdElement).style.visibility = sState ;	
}