virtualEarthMap = {
	map : "",
	propertiesDataArray : new Array,
	locs : new Array,
	init : function(){	
	},

	addLoadEvent : function(func) {
		var oldonload = window.onload;
  		if (typeof window.onload != 'function') {
    		window.onload = func;
  		} else {
    			window.onload = function() {
      				oldonload();
      				func();
    			}
  		}
	},
	
	pushpinObj : function(){
		this.number;
		this.lat;
		this.longitude;
		this.type;
	},
	
	
	generatePushpinData : function(){
		//initiate hidden field objects
		var pushPinNumberObj = document.getElementsByName("pushpin-number");
		var pushPinLatObj = document.getElementsByName("pushpin-lat");
		var pushPinLongObj = document.getElementsByName("pushpin-long");
		var pushPinTypeObj = document.getElementsByName("pushpin-type");
		
		//populate propertiesDataArray with pushpin data
		for(i=0; i < pushPinNumberObj.length; i++){ 
			var propertyData = new virtualEarthMap.pushpinObj;
			propertyData.number = Number(pushPinNumberObj[i].value);
			propertyData.lat = pushPinLatObj[i].value;
			propertyData.longitude = pushPinLongObj[i].value;
			propertyData.type = pushPinTypeObj[i].value;
			
			virtualEarthMap.propertiesDataArray.push(propertyData);
		}		
		
	},

//renders VEMap to myMap div	
	getMap : function(mapObj){
		try{
			virtualEarthMap.map = new VEMap('map');

			virtualEarthMap.map.SetDashboardSize(virtualEarthMap.getDashboardObj());
	
			//LoadMap(VELatLong, zoom, style, fixed, mode, showSwitch)
			virtualEarthMap.map.LoadMap(null, null, document.getElementById("defaultView").value, null, null, false);
			
			//suppress birds eye pop-up for VE 6.1
			if(document.getElementById("MSVE_obliqueNotification"))
			{
				document.getElementById("MSVE_obliqueNotification").style.visibility = "hidden";
			}

			//clear flyout box styles
			virtualEarthMap.map.ClearInfoBoxStyles();
			
			//set the tile buffer to the map
			virtualEarthMap.map.SetTileBuffer(Number(document.getElementById("tileBuffer").value));
			
			//Get units from the hidden filed and set to the map
			var units = document.getElementById("units").value;
			if (units == 'miles')
			{
				virtualEarthMap.map.SetScaleBarDistanceUnit(VEDistanceUnit.Miles);
			}
			else
			{
				virtualEarthMap.map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
			}
			
			//populate pushpins to VEmap			
			for(var x=0; x < virtualEarthMap.propertiesDataArray.length; x++){
				
				var propertyData = virtualEarthMap.propertiesDataArray[x];
				
				//Create an object of VELatLong by passing latitude & longitude
				var loc = new VELatLong(Number(propertyData.lat),Number(propertyData.longitude));
				virtualEarthMap.locs.push(loc);

				//Create an object of VEShape specifying that we are adding puspin and the also pass pushpin obj
				var pushpin = new VEShape(VEShapeType.Pushpin, loc);
								
				//set title to pushpin obj
				var title = "";
				pushpin.SetTitle(title);

				//set description to pushpin obj	
				var flyoutId = virtualEarthMap.getFlyoutId(propertyData.lat,propertyData.longitude);	
				var desc = document.getElementById(flyoutId).innerHTML;
				pushpin.SetDescription(desc);
				
				//retrieve the map type object
				var icon = mapObj.getCustomIcon(propertyData.number, propertyData.type, false);
				
				//set custom icon to the pushpin obj
				pushpin.SetCustomIcon(icon);

				//Add pushpin to the map
				virtualEarthMap.map.AddShape(pushpin);
			}  
			
			//set map view
				mapObj.setMapView();

        	}catch(e){
				mapObj.displayMapError();
			}
		},

//returns flyout info id		
	getFlyoutId : function(lat, longitude){
				try{
        			var flyoutId = "flyout[" + lat + "][" + longitude + "]";
        			return flyoutId
        		}catch(e){}
	},

//get dashboard object
	getDashboardObj : function(){
			var dashboardSize = document.getElementById("dashboardSize").value;
			if (dashboardSize == 'Normal')
			{
				dashboardObj = VEDashboardSize.Normal;
			}
			else if (dashboardSize == 'Small')
			{
				dashboardObj = VEDashboardSize.Small;
			}
			else if (dashboardSize == 'Tiny')
			{
				dashboardObj = VEDashboardSize.Tiny;
			}
			else
			{
				dashboardObj = VEDashboardSize.Normal;	
			}
			return dashboardObj;
	}
}//End virtualEarthMap

 
