var map;
var icon;
function mapInit()
{
	map = new VEMap('GeoRSSMap');
 	map.SetDashboardSize(VEDashboardSize.Small);
 	map.LoadMap();       

 	var l1 = new VEShapeLayer();
 	var veLayerSpec1 = new VEShapeSourceSpecification(VEDataType.GeoRSS, '/data/rss/BlueAshHotels.xml', l1);
 	veLayerSpec1.ID = 'BlueAshHotels';
	veLayerSpec1.Method = 'get';
 	icon = '/data/poiIcons/hotel.gif';
	map.ImportShapeLayerData(veLayerSpec1, onFeed1Load, true);

 	var l2 = new VEShapeLayer();
	var veLayerSpec2 = new VEShapeSourceSpecification(VEDataType.GeoRSS, '/data/rss/PostOfficesBlueAsh.xml', l2);
 	veLayerSpec2.ID = 'PostOfficesBlueAsh';
	veLayerSpec2.Method = 'get';
 	icon = '/data/poiIcons/usps.gif';
	map.ImportShapeLayerData(veLayerSpec2, onFeed2Load, true);

 	var l3 = new VEShapeLayer();
	var veLayerSpec3 = new VEShapeSourceSpecification(VEDataType.GeoRSS, '/data/rss/Library.xml', l3);
 	veLayerSpec3.ID = 'Library';
	veLayerSpec3.Method = 'get';
 	icon = '/data/poiIcons/library.gif';
	map.ImportShapeLayerData(veLayerSpec3, onFeed3Load, true);

 	var l4 = new VEShapeLayer();
	var veLayerSpec4 = new VEShapeSourceSpecification(VEDataType.GeoRSS, '/data/rss/ReligiousInstitutionsBlueAsh.xml', l4);
 	veLayerSpec4.ID = 'ReligiousInstitutionsBlueAsh';
	veLayerSpec4.Method = 'get';
 	icon = '/data/poiIcons/church.gif';
	map.ImportShapeLayerData(veLayerSpec4, onFeed4Load, true);

 	var l5 = new VEShapeLayer();
	var veLayerSpec5 = new VEShapeSourceSpecification(VEDataType.GeoRSS, '/data/rss/VotingLocationsBlueAsh.xml', l5);
 	veLayerSpec5.ID = 'VotingLocationsBlueAsh';
	veLayerSpec5.Method = 'get';
 	icon = '/data/poiIcons/vote.gif';
	map.ImportShapeLayerData(veLayerSpec5, onFeed5Load, true);

	var l6 = new VEShapeLayer();
	var veLayerSpec6 = new VEShapeSourceSpecification(VEDataType.GeoRSS, '/data/rss/BlueAshParks.xml', l6);
 	veLayerSpec6.ID = 'BlueAshParks';
	veLayerSpec6.Method = 'get';
 	icon = '/data/poiIcons/park.bmp';
	map.ImportShapeLayerData(veLayerSpec6, onFeed6Load, true);
	
	var l7 = new VEShapeLayer();
	var veLayerSpec7 = new VEShapeSourceSpecification(VEDataType.GeoRSS, '/data/rss/BlueAshSchools.xml', l7);
 	veLayerSpec7.ID = 'BlueAshSchools';
	veLayerSpec7.Method = 'get';
 	icon = '/data/poiIcons/school.png';
	map.ImportShapeLayerData(veLayerSpec7, onFeed7Load, true);
}
function onFeed1Load(layer){
	var numShapes = layer.GetShapeCount();
	var icon1 = '/data/poiIcons/hotel.gif';
	for(var i=0; i < numShapes; ++i){
		var s = layer.GetShapeByIndex(i);
		s.SetCustomIcon("<img src='" + icon1 + "'/>");
	}
}
function onFeed2Load(layer){
	var numShapes = layer.GetShapeCount();
	var icon2 = '/data/poiIcons/usps.gif';
	for(var i=0; i < numShapes; ++i){
		var s = layer.GetShapeByIndex(i);
		s.SetCustomIcon("<img src='" + icon2 + "'/>");
	}
}
function onFeed3Load(layer){
	var numShapes = layer.GetShapeCount();
	var icon3 = '/data/poiIcons/library.gif';
	for(var i=0; i < numShapes; ++i){
		var s = layer.GetShapeByIndex(i);
		s.SetCustomIcon("<img src='" + icon3 + "'/>");
	}
}
function onFeed4Load(layer){
	var numShapes = layer.GetShapeCount();
	var icon4 = '/data/poiIcons/church.gif';
	for(var i=0; i < numShapes; ++i){
		var s = layer.GetShapeByIndex(i);
		s.SetCustomIcon("<img src='" + icon4 + "'/>");
	}
}
function onFeed5Load(layer){
	var numShapes = layer.GetShapeCount();
	var icon5 = '/data/poiIcons/vote.gif';
	for(var i=0; i < numShapes; ++i){
		var s = layer.GetShapeByIndex(i);
		s.SetCustomIcon("<img src='" + icon5 + "'/>");
	}
}
function onFeed6Load(layer){
	var numShapes = layer.GetShapeCount();
	var icon6 = '/data/poiIcons/park.bmp';
	for(var i=0; i < numShapes; ++i){
		var s = layer.GetShapeByIndex(i);
		s.SetCustomIcon("<img src='" + icon6 + "'/>");
	}
}
function onFeed7Load(layer){
	var numShapes = layer.GetShapeCount();
	var icon7 = '/data/poiIcons/school.png';
	for(var i=0; i < numShapes; ++i){
		var s = layer.GetShapeByIndex(i);
		s.SetCustomIcon("<img src='" + icon7 + "'/>");
	}
}
function onFeedLoadFinal(layer){onFeedLoad(layer);findBestView()}

function showLayer(index) { 
   layer = map.GetShapeLayerByIndex(index);
   layer.Show();
}
function hideLayer(index) { 
   layer = map.GetShapeLayerByIndex(index);
   layer.Hide();
}
function findBestView(){
	var rect;
	var layer;
	var idx;
	var maxLat; // this is represented by the latitude values
	var minLat;
	var maxLong; // this is calculated from the longitude vaues
	var minLong;
	var topLeftLat, topLeftLong, bottomRightLat, bottomRightLong;
	var Center = map.GetCenter();
   maxLat = Center.Latitude;
   minLat = Center.Latitude;
   maxLong = Center.Longitude;
   minLong = Center.Longitude;
   var layerCount = map.GetShapeLayerCount();
	for (idx = 0;idx <= layerCount - 1; idx++){
			rect = map.GetShapeLayerByIndex(idx).GetBoundingRectangle();
			//find the higest and widest points. here we assume the nothern hemisphere west of the prime meridian.
			if (rect.TopLeftLatLong.Latitude > maxLat) { maxLat = rect.TopLeftLatLong.Latitude }
			if (rect.BottomRightLatLong.Latitude < minLat){ minLat = rect.BottomRightLatLong.Latitude }
			if (rect.TopLeftLatLong.Longitude < minLong){ minLong = rect.TopLeftLatLong.Longitude }
			if (rect.BottomRightLatLong.Longitude > maxLong){ maxLong = rect.BottomRightLatLong.Longitude }
	}
	//now set a new rectangle with the points we found
   var topLeft =new VELatLong(maxLat,minLong)
   var bottomRight =new VELatLong(minLat,maxLong)
	var bestView = new VELatLongRectangle(topLeft, bottomRight);
	map.SetMapView(bestView);
}
