var deprecated_search	= false;
var latlong_array		= new Array();
var property_array		= new Array();
var cull				= 0;
var jsonObjs			= new Array();
var map;

var	show_schools,
	show_churches,
	show_hospitals,
	show_postoffices,
	show_daycares,
	show_hotels,
	show_cityhall,
	show_utilities,
	show_banks,
	show_libraries,
	show_airports,
	show_movies,
	show_golfcourses,
	show_shopping,
	show_gasstations,
	show_restaurants,
	show_drycleaners,
	show_pharmacies,
	show_policestations,
	show_firestations,
	show_universities,
	show_vets,
	show_healthstores,
	show_parks,
	show_grocerystores;

var search_results_layer = new VEShapeLayer();

var school_layer = new VEShapeLayer();
var church_layer = new VEShapeLayer();
var hospital_layer = new VEShapeLayer();
var postoffice_layer = new VEShapeLayer();
var daycare_layer = new VEShapeLayer();
var hotel_layer = new VEShapeLayer();
var cityhall_layer = new VEShapeLayer();
var utility_layer = new VEShapeLayer();
var bank_layer = new VEShapeLayer();
var library_layer = new VEShapeLayer();
var airport_layer = new VEShapeLayer();
var movie_layer = new VEShapeLayer();
var golfcourse_layer = new VEShapeLayer();
var shopping_layer = new VEShapeLayer();
var gasstation_layer = new VEShapeLayer();
var restaurant_layer = new VEShapeLayer();
var drycleaner_layer = new VEShapeLayer();
var pharmacy_layer = new VEShapeLayer();
var policestation_layer = new VEShapeLayer();
var firestation_layer = new VEShapeLayer();
var university_layer = new VEShapeLayer();
var vet_layer = new VEShapeLayer();
var healthstore_layer = new VEShapeLayer();
var park_layer = new VEShapeLayer();
var grocerystore_layer = new VEShapeLayer();


window.onload = initMap;

function initMap () {
	map = new VEMap('vmap');
	
	map.onLoadMap = function () {
		//if (prop_id.length > 0)
			property_search();
		//else
		//	map.Find(null, default_location);
	}
	
	map.LoadMap();

	// this layer holds the pushpins (VEShapes) for property search results
	map.AddShapeLayer(search_results_layer);
}

function property_search() {
	// remove all property search results from the appropriate layer
	search_results_layer.DeleteAllShapes();
	
	var pSearch = new Ajax.Updater('js_exec', '/property/ajax/', {
			method:'post',
			asynchronous:true,
			evalScripts:true,
			postBody:Form.serialize('search')}
		);
}

function resetArrays() {
	latlong_array = null;
	latlong_array = new Array();
	
	cull = property_array.length - 1;
}
/*
var YGeoCode = {
	getMap : function (d) {
		document.getElementById("hidden_id").value = "";
		
		if ((d.GeoPoint.Lat) && (d.GeoPoint.Lon)) {
			// determining which property this info goes to
			var prop_index = parseInt(d.GeoAddress.split(",")[1]);
			property_array[prop_index].latlong = new VELatLong (d.GeoPoint.Lat, d.GeoPoint.Lon);
			
			// keep track of the latlong object for centering the map
			latlong_array.push(property_array[prop_index].latlong);
			
			// create & add a pushpin using the property's information
			if (property_array[prop_index].preview_img)
				var image_string = '<img src="'+property_array[prop_index].preview_img+'" style="float:left;margin:0px 5px 5px 0px;width:60px;height:55px;border:#cccccc 1px solid;" />';
			else
				var image_string = '';
			
			//var temp_pushpin = new VEShape(VEShapeType.Pushpin, property_array[prop_index].latlong);
			///temp_pushpin.SetCustomIcon(fs_url + 'realestate/img/static/map_icons/HOM.gif');
			//temp_pushpin.SetTitle(property_array[prop_index].title);
			//temp_pushpin.SetDescription(image_string+property_array[prop_index].address+ "<br /><br />" +'<a href="/property/detail/'+property_array[prop_index].pbs_id+'/">Click Here for More...</a>');

			//search_results_layer.AddShape(temp_pushpin);
			map.SetMapView(latlong_array);
		}
		else {
			alert("Address: " + property_array[prop_index].address + " not found!");
		}
	}
};
*/
var YGeoCode = {
	getMap : function (d) {
		if ((d.GeoPoint.Lat) && (d.GeoPoint.Lon)) {
			// determining which property this info goes to
			var prop_index = parseInt(d.GeoAddress.split(",")[1]);
			if (!isNaN(prop_index)) {
				property_array[prop_index].latlong = new VELatLong (d.GeoPoint.Lat, d.GeoPoint.Lon);
				
				// keep track of the latlong object for centering the map
				latlong_array.push(property_array[prop_index].latlong);
				
				// create the pin and add it
				//var pin = null;
				//pin = new VEShape(VEShapeType.Pushpin, property_array[prop_index].latlong);
				//pin.SetDescription('<strong>'+property_array[prop_index].title+'</strong><br />'+property_array[prop_index].address+'<br />'+property_array[prop_index].city+' '+property_array[prop_index].city+' '+property_array[prop_index].state+' '+property_array[prop_index].zip+'<br /><br /><a href="/detail/'+property_array[prop_index].pbs_id+'/">View Details ...</a>');
				//map.AddShape(pin);
				if (property_array[prop_index].preview_img)
					var image_string = '<img src="'+property_array[prop_index].preview_img+'" style="float:left;margin:0px 5px 5px 0px;width:60px;height:55px;border:#cccccc 1px solid;" />';
				else
					var image_string = '';
				try {	
				var pin = null;
				pin = new VEShape(VEShapeType.Pushpin, property_array[prop_index].latlong);
				pin.SetCustomIcon(fs_url + 'realestate/img/static/map_icons/HOM.gif');
				pin.SetTitle(property_array[prop_index].title);
				pin.SetDescription(image_string+property_array[prop_index].address+ "<br /><br />" +'<a href="/property/detail/'+property_array[prop_index].pbs_id+'/">Click Here for More...</a>');
				search_results_layer.AddShape(pin);

				//search_results_layer.AddShape(temp_pushpin);
				}catch(e){}
				// center view
				map.SetMapView(latlong_array);
			}
		}
		else {
			//do nothing
		}
	}
};

///
/// Used as a control to toggle amenity layers.
///
var ToggleAmenities = {
	Schools : function () {
		if (show_schools)
			AmenitiesLayers.HideLayer(school_layer);
		else {
			try {
				map.AddShapeLayer(school_layer);
			} catch (e) {}
			school_layer.Show();
			
			// originally had a check here to see if we already had results,
			// but was too lazy to preserve the bool until a new search was made.
			map.Find("School", null, null, school_layer, null, null, null, null, null, null, AmenitiesLayers.assignSchoolLayer);
		}
		show_schools = !show_schools;
	},
	
	Churches : function () {
		if (show_churches)
			AmenitiesLayers.HideLayer(church_layer);
		else {
			try {
				map.AddShapeLayer(church_layer);
			} catch (e) {}
			church_layer.Show();

			map.Find("Church", null, null, church_layer, null, null, null, null, null, null, AmenitiesLayers.assignChurchLayer);
		}
		show_churches = !show_churches;
	},
	
	Hospitals : function () {
		if (show_hospitals)
			AmenitiesLayers.HideLayer(hospital_layer);
		else {
			try {
				map.AddShapeLayer(hospital_layer);
			} catch (e) {}
			hospital_layer.Show();
			
			map.Find("Hospital", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignHospitalLayer);
		}
		show_hospitals = !show_hospitals;
	},
	
	PostOffices : function () {
		if (show_postoffices)
			AmenitiesLayers.HideLayer(postoffice_layer);
		else {
			try {
				map.AddShapeLayer(postoffice_layer);
			} catch (e) {}
			postoffice_layer.Show();
			map.Find("Post Office", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignPostOfficeLayer);
		}
		show_postoffices = !show_postoffices;
	},
	
	DayCareCenters : function () {
		if (show_daycares)
			AmenitiesLayers.HideLayer(daycare_layer);
		else
			map.Find("Day Care", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignDayCareLayer);
		show_daycares = !show_daycares;
	},
	
	Hotels : function () {
		if (show_hotels)
			AmenitiesLayers.HideLayer(hotel_layer);
		else {
			try {
				map.AddShapeLayer(hotel_layer);
			} catch (e) {}
			hotel_layer.Show();
			map.Find("Hotels", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignHotelLayer);
		}
		show_hotels = !show_hotels;
	},
	
	CityHall : function () {
		if (show_cityhall) 
			AmenitiesLayers.HideLayer(cityhall_layer);
		else {
			try {
				map.AddShapeLayer(cityhall_layer);
			} catch (e) {}
			cityhall_layer.Show();
			map.Find("Court", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignCityHallLayer);
		}
		show_cityhall = !show_cityhall;
	},
	
	Utilities : function () {
		if (show_utilities)
			AmenitiesLayers.HideLayer(utility_layer);
		else {
			try {
				map.AddShapeLayer(utility_layer);
			} catch (e) {}
			utility_layer.Show();
			map.Find("Utility", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignUtilityLayer);
		}
		show_utilities = !show_utilities;
	},
	
	Banks : function () {
		if (show_banks)
			AmenitiesLayers.HideLayer(bank_layer);
		else {
			try {
				map.AddShapeLayer(bank_layer);
			} catch (e) {}
			bank_layer.Show();
			map.Find("Bank", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignBankLayer);
		}
		show_banks = !show_banks;
	},
	
	Libraries : function () {
		if (show_libraries)
			AmenitiesLayers.HideLayer(library_layer);
		else {
			try {
				map.AddShapeLayer(library_layer);
			} catch (e) {}
			library_layer.Show();
			map.Find("Library", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignLibraryLayer);
		}
		show_libraries = !show_libraries;
	},
	
	Airports : function () {
		if (show_airports)
			AmenitiesLayers.HideLayer(airport_layer);
		else {
			try {
				map.AddShapeLayer(airport_layer);
			} catch (e) {}
			airport_layer.Show();
			map.Find("Airport", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignAirportLayer);
		}
		show_airports = !show_airports;
	},
	
	Movies : function () {
		if (show_movies)
			AmenitiesLayers.HideLayer(movie_layer);
		else {
			try {
				map.AddShapeLayer(movie_layer);
			} catch (e) {}
			movie_layer.Show();
			map.Find("Movies", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignMovieLayer);
		}
		show_movies = !show_movies;
	},
	
	GolfCourses : function () {
		if (show_golfcourses)
			AmenitiesLayers.HideLayer(golfcourse_layer);
		else {
			try {
				map.AddShapeLayer(golfcourse_layer);
			} catch (e) {}
			golfcourse_layer.Show();
			map.Find("Golf Courses", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignGolfCourseLayer);
		}
		show_golfcourses = !show_golfcourses;
	},
	
	Shopping : function () {
		if (show_shopping)
			AmenitiesLayers.HideLayer(shopping_layer);
		else {
			try {
				map.AddShapeLayer(shopping_layer);
			} catch (e) {}
			shopping_layer.Show();
			map.Find("Shopping", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignShoppingLayer);
		}
		show_shopping = !show_shopping;
	},
	
	GasStations : function () {
		if (show_gasstations)
			AmenitiesLayers.HideLayer(gasstation_layer);
		else {
			try {
				map.AddShapeLayer(gasstation_layer);
			} catch (e) {}
			gasstation_layer.Show();
			map.Find("Gas Station", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignGasStationLayer);
		}
		show_gasstations = !show_gasstations;
	},
	
	Restaurants : function () {
		if (show_restaurants)
			AmenitiesLayers.HideLayer(restaurant_layer);
		else {
			try {
				map.AddShapeLayer(restaurant_layer);
			} catch (e) {}
			restaurant_layer.Show();
			map.Find("Restaurant", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignRestaurantLayer);
		}
		show_restaurants = !show_restaurants;
	},
	
	DryCleaners : function () {
		if (show_drycleaners)
			AmenitiesLayers.HideLayer(drycleaner_layer);
		else {
			try {
				map.AddShapeLayer(drycleaner_layer);
			} catch (e) {}
			drycleaner_layer.Show();
			map.Find("Dry Cleaner", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignDryCleanerLayer);
		}
		show_drycleaners = !show_drycleaners;
	},
	
	Pharmacies : function () {
		if (show_pharmacies)
			AmenitiesLayers.HideLayer(pharmacy_layer);
		else {
			try {
				map.AddShapeLayer(pharmacy_layer);
			} catch (e) {}
			pharmacy_layer.Show();
			map.Find("Pharmacy", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignPharmacyLayer);
		}
		show_pharmacies = !show_pharmacies;
	},
	
	FireStations : function () {
		if (show_firestations)
			AmenitiesLayers.HideLayer(firestation_layer);
		else {
			try {
				map.AddShapeLayer(firestation_layer);
			} catch (e) {}
			firestation_layer.Show();
			map.Find("Fire Department", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignFireStationLayer);
		}
		show_firestations = !show_firestations;
	},
	
	GroceryStores : function () {
		if (show_grocerystores)
			AmenitiesLayers.HideLayer(grocerystore_layer);
		else {
			try {
				map.AddShapeLayer(grocerystore_layer);
			} catch (e) {}
			grocerystore_layer.Show();
			map.Find("Grocery Store", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignGroceryStoreLayer);
		}
		show_grocerystores = !show_grocerystores;
	},
	
	HealthStores : function () {
		if (show_healthstores)
			AmenitiesLayers.HideLayer(healthstore_layer);
		else {
			try {
				map.AddShapeLayer(healthstore_layer);
			} catch (e) {}
			healthstore_layer.Show();
			map.Find("Health Store", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignHealthStoreLayer);
		}
		show_healthstores = !show_healthstores;
	},
	
	Parks : function () {
		if (show_parks)
			AmenitiesLayers.HideLayer(park_layer);
		else {
			try {
				map.AddShapeLayer(park_layer);
			} catch (e) {}
			park_layer.Show();
			map.Find("Public Park", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignParkLayer);
		}
		show_parks = !show_parks;
	},
	
	PoliceStations : function () {
		if (show_policestations)
			AmenitiesLayers.HideLayer(policestation_layer);
		else {
			try {
				map.AddShapeLayer(policestation_layer);
			} catch (e) {}
			policestation_layer.Show();
			map.Find("Police Department", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignPoliceStationLayer);
		}
		show_policestations = !show_policestations;
	},
	
	Universities : function () {
		if (show_universities)
			AmenitiesLayers.HideLayer(university_layer);
		else {
			try {
				map.AddShapeLayer(university_layer);
			} catch (e) {}
			university_layer.Show();
			map.Find("University", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignUniversityLayer);
		}
		show_universities = !show_universities;
	},
	
	Vets : function () {
		if (show_vets)
			AmenitiesLayers.HideLayer(vet_layer);
		else {
			try {
				map.AddShapeLayer(vet_layer);
			} catch (e) {}
			vet_layer.Show();
			map.Find("Veterinarian", null, null, null, null, null, null, null, null, null, AmenitiesLayers.assignVetLayer);
		}
		show_vets = !show_vets;
	}
}

///
/// Used for global layer pushpin assignment.
/// Also handles hiding "layers."
///
var AmenitiesLayers = {
	SchoolIcon 		: fs_url + 'realestate/img/static/map_icons/schools.gif',
	ChurchIcon 		: fs_url + 'realestate/img/static/map_icons/churches.gif',
	HospitalIcon 	: fs_url + 'realestate/img/static/map_icons/hospitals.gif',
	PostOfficeIcon 	: fs_url + 'realestate/img/static/map_icons/postoffices.gif',
	DayCareIcon 	: fs_url + 'realestate/img/static/map_icons/daycares.gif',
	HotelIcon 		: fs_url + 'realestate/img/static/map_icons/hotels.gif',
	CityHallIcon 	: fs_url + 'realestate/img/static/map_icons/cityhall.gif',
	UtilityIcon 	: fs_url + 'realestate/img/static/map_icons/utilities.gif',
	BankIcon 		: fs_url + 'realestate/img/static/map_icons/banks.gif',
	LibraryIcon 	: fs_url + 'realestate/img/static/map_icons/libraries.gif',
	AirportIcon 	: fs_url + 'realestate/img/static/map_icons/airports.gif',
	MovieIcon 		: fs_url + 'realestate/img/static/map_icons/movies.gif',
	GolfCourseIcon	: fs_url + 'realestate/img/static/map_icons/golfcourses.gif',
	ShoppingIcon	: fs_url + 'realestate/img/static/map_icons/shopping.gif',
	GasStationIcon	: fs_url + 'realestate/img/static/map_icons/gasstation.gif',
	RestaurantIcon	: fs_url + 'realestate/img/static/map_icons/restaurants.gif',
	DryCleanerIcon	: fs_url + 'realestate/img/static/map_icons/drycleaners.gif',
	PharmacyIcon	: fs_url + 'realestate/img/static/map_icons/pharmacies.gif',
	PoliceIcon		: fs_url + 'realestate/img/static/map_icons/policestations.gif',
	FireStationIcon	: fs_url + 'realestate/img/static/map_icons/firestations.gif',
	UniversityIcon	: fs_url + 'realestate/img/static/map_icons/universities.gif',
	ParkIcon		: fs_url + 'realestate/img/static/map_icons/parks.gif',
	GroceryStoreIcon: fs_url + 'realestate/img/static/map_icons/grocerystores.gif',
	VetIcon			: fs_url + 'realestate/img/static/map_icons/vets.gif',
	HealthStoreIcon	: fs_url + 'realestate/img/static/map_icons/healthstores.gif',
	
	assignSchoolLayer : function (layer, findResults, places, more, e) {
		school_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(school_layer, AmenitiesLayers.SchoolIcon);
	},
	assignChurchLayer : function (layer, findResults, places, more, e) {
		church_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(church_layer, AmenitiesLayers.ChurchIcon);
	},
	assignHospitalLayer : function (layer, findResults, places, more, e) {
		hospital_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(hospital_layer, AmenitiesLayers.HospitalIcon);
	},
	assignPostOfficeLayer : function (layer, findResults, places, more, e) {
		postoffice_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(postoffice_layer, AmenitiesLayers.PostOfficeIcon);
	},
	assignDayCareLayer : function (layer, findResults, places, more, e) {
		daycare_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(daycare_layer, AmenitiesLayers.DayCareIcon);
	},
	assignHotelLayer : function (layer, findResults, places, more, e) {
		hotel_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(hotel_layer, AmenitiesLayers.HotelIcon);
	},
	assignCityHallLayer : function (layer, findResults, places, more, e) {
		cityhall_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(cityhall_layer, AmenitiesLayers.CityHallIcon);
	},
	assignUtilityLayer : function (layer, findResults, places, more, e) {
		utility_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(utility_layer, AmenitiesLayers.UtilityIcon);
	},
	assignBankLayer : function (layer, findResults, places, more, e) {
		bank_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(bank_layer, AmenitiesLayers.BankIcon);
	},
	assignLibraryLayer : function (layer, findResults, places, more, e) {
		library_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(library_layer, AmenitiesLayers.LibraryIcon);
	},
	assignAirportLayer : function (layer, findResults, places, more, e) {
		airport_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(airport_layer, AmenitiesLayers.AirportIcon);
	},
	assignMovieLayer : function (layer, findResults, places, more, e) {
		movie_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(movie_layer, AmenitiesLayers.MovieIcon);
	},
	assignGolfCourseLayer : function (layer, findResults, places, more, e) {
		golfcourse_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(golfcourse_layer, AmenitiesLayers.GolfCourseIcon);
	},
	assignShoppingLayer : function (layer, findResults, places, more, e) {
		shopping_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(shopping_layer, AmenitiesLayers.ShoppingIcon);
	},
	assignGasStationLayer : function (layer, findResults, places, more, e) {
		gasstation_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(gasstation_layer, AmenitiesLayers.GasStationIcon);
	},
	assignRestaurantLayer : function (layer, findResults, places, more, e) {
		restaurant_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(restaurant_layer, AmenitiesLayers.RestaurantIcon);
	},
	assignDryCleanerLayer : function (layer, findResults, places, more, e) {
		drycleaner_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(drycleaner_layer, AmenitiesLayers.DryCleanerIcon);
	},
	assignPharmacyLayer : function (layer, findResults, places, more, e) {
		pharmacy_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(pharmacy_layer, AmenitiesLayers.PharmacyIcon);
	},
	assignParkLayer : function (layer, findResults, places, more, e) {
		park_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(park_layer, AmenitiesLayers.ParkIcon);
	},
	assignPoliceStationLayer : function (layer, findResults, places, more, e) {
		policestation_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(policestation_layer, AmenitiesLayers.PoliceIcon);
	},
	assignFireStationLayer : function (layer, findResults, places, more, e) {
		firestation_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(firestation_layer, AmenitiesLayers.FireStationIcon);
	},
	assignUniversityLayer : function (layer, findResults, places, more, e) {
		university_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(university_layer, AmenitiesLayers.UniversityIcon);
	},
	assignGroceryStoreLayer : function (layer, findResults, places, more, e) {
		grocerystore_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(grocerystore_layer, AmenitiesLayers.GroceryStoreIcon);
	},
	assignVetLayer : function (layer, findResults, places, more, e) {
		vet_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(vet_layer, AmenitiesLayers.VetIcon);
	},
	assignHealthStoreLayer : function (layer, findResults, places, more, e) {
		healthstore_layer = layer;
		AmenitiesLayers.UpdateLayerIcon(healthstore_layer, AmenitiesLayers.HealthStoreIcon);
	},
	
	
	HideLayer : function (amen_layer) {
		if (amen_layer != null) {
			// amen for this indeed
			amen_layer.DeleteAllShapes();
			amen_layer.Hide();
		}
	},
	
	UpdateLayerIcon : function (pin_layer, icon) {
		for (var i=0; i<pin_layer.GetShapeCount(); i++) {
			pin_layer.GetShapeByIndex(i).SetCustomIcon(icon);
			//alert(pin_layer[i].Phone);
			//VEShape.SetCustomIcon(customIcon);
		    //var pinNode = document.getElementById(pin_layer[i].ID);
		    //if (pinNode)
		    //{
		       //pinNode.getElementsByTagName("img")[0].src = icon;
		    //}
			//pin_layer[i].;
		}
	}
};