LANG = 'en';
var map = null;
var id = null;
var mapproject = null;
var data = null;
var categories = [];
var categoriesMap = new Object;
var subcategories = [];
var condos = [];
var catArray = new Array( );
var subCatArray = new Array( );
var contextPin = null;
var loadIds = null;
var cstmCount = 0;
var defaults = {
	xml : '/xml/map-xml.php',
	dashboard : 'Normal',
	sortable : true,
	listView : false,
	hotelOnly: false,
	printNames : true,
	miniMap : false,
	kilometers : false,
	context : false,
	acceptQuery : false,
	simpleMap : false,
	printMap : false
};
var regional = [];
regional[''] = {};
var items = [];
var changedItems = new Array();
var layer;
var editmode = false;
var editid;
var orgPoint;
var orgIndex;
var centerArray = new Array();
var centerLat = 39.642458;
var centerLong = -106.38604;
var zoomOutLat = 39.643858;
var zoomOutLong = -106.36904;
var hashURL;
var currentPin=null;
var currentID=null;
var _hide;
var _currentShape = null;
var _isPanning = false;


	function MSNMap(mapid,project) {
		id = mapid;
		mapproject = project;
		this.getData();					
		$(window).unload(function() { if(this._map) { this._map.Dispose(); } });
	}
	
	function getData() {
		var obj = this;
		$.get(defaults.xml, function(data) { 
			
			$('item', data).each(function(i) {
				items[i] = {};
				$(this).children().each(function() {
					if (this.tagName == 'category'){		
						var tempCat = $(this).text().split(",");
						var catName = [];
						
						if (tempCat.length > 1) { 
							var tempCatArray = tempCat;
							catName = [];
		
							for (x in tempCatArray){								
								var tempCatName = tempCatArray[x].toString();
								tempCatName = tempCatName.replace(/\W/g, "");
								tempCatName = tempCatName.toLowerCase(); 
								catName.push(tempCatName);
								categoriesMap[tempCatName] = tempCatArray[x].toString();
							}
						} else { 
							catName = []
							var tempCatName = $(this).text().replace(/\W/g, "");
							tempCatName = tempCatName.toLowerCase(); 
							catName.push(tempCatName);
							categoriesMap[tempCatName] = $(this).text();
						}
						items[i][this.tagName] = catName;
					} else if (this.tagName =='gallery') {
					    var gallyArray = [];
					    $(this).children().each(function() {
						    gallyArray.push( $(this).text() );
					    });
					    items[i]['galleryImages'] = gallyArray;
					}else 
						items[i][this.tagName] = $(this).text();	
				});
			});

			// Get String Query
			var q = window.location.search.substring(1);
			if(q.length>0) {
				var query = obj.parseQuery(q);
				if(query.id!==null&&query.id!==undefined) {
					obj.loadIds = query.id.split(',');							
				}
			}
			createMap();
		});
	}
	
	function createMap() {
		map = new VEMap(id);

		// initial point to loap map, 
		if ( items[0]['georss:point'] ) {
			var fp = getLatLong(items[0]['georss:point']);
		}
		
		map.LoadMap(new VELatLong(centerLat, centerLong), 15);
		map.SetMapStyle(VEMapStyle.Aerial);
		map.SetMouseWheelZoomToCenter(false);
		map.Hide3DNavigationControl();
		map.SetMouseWheelZoomToCenter(false);
							
		lineLayer = new VEShapeLayer();
		map.AddShapeLayer(lineLayer);  
				
		map.PanToLatLong(new VELatLong(centerLat, centerLong));
				
		var testURL = String(hashURL);
		testURL = testURL.split('?');
		var q = String(hashURL);
		q = q.split('?');
		q = q[1];
		if(q != undefined) {
			var query = parseQuery(q);
			if(query.id!==null&&query.id!==undefined) {
				loadIds = query.id.split(',');					;
			}
			loadPoints('property');
		}
		
		getCategories();
		
		if(q != undefined) {
			$('div#condo-list-'+loadIds).addClass('on');
		}
		loadIds = null;
	}
	
	function getLatLong(point) {
		var pts = point.split(" ");
		return pts;
	}
	
	function getCategories() {	
		var obj = this;
		var divCondo = $('div#condos');
		$.each(items, function(i, val) {			
			var dup = false; // duplicate set to false
			var tempsplit = val.category; // split each subcategory node
			
			catArray = val.category;
			for (x in catArray){
				dup = false; // duplicate set to valse
				$.each(categories, function(j, val2) {
					if ( catArray[x] == val2 ) {
						dup = true;
					}					
				});

				if ( !window.one ) {
					window.one = []
				}
				window.one.push(val)

				if ( catArray[x] == 'condo') {
					loadCondos(val.id);	
					$('<div />').addClass('condo-list').attr('id','condo-list-'+val.id).html(val.title)
					.click(function() {							
						loadCondos(val.id);							
						return false;
					}).appendTo(divCondo);	
					$('div.condo-list').mouseover(function () {$(this).addClass('condohover');});
					$('div.condo-list').mouseout(function () {$(this).removeClass('condohover');});				
				}
				if(!dup) {
					categories.push(catArray[x]);
				}			
			}			
			
		});
		printCategories();
	}
	
	function printCategories() {
		// Print all of the categories
		var div = $('div#categories');
		var catCounter = 1;
		$.each(categories, function(i, val) {
						
				if ( (val != 'condo') && (val != 'property') && (val != 'Top of the Village')) {
					$('<div />').addClass('category').attr('id',val).html('<span class="cat-num">' + catCounter + '</span>' + categoriesMap[val])
					.click(function() {
						$(this).addClass('on');
						loadPoints(val);							
						return false;
					}).appendTo(div);
					catCounter++;
					$('div.category').mouseover(function () {$(this).addClass('hover');});
					$('div.category').mouseout(function () {$(this).removeClass('hover');});
				}
		});
	}
	
	function loadPoints(cat) {
		var obj = this;
		var cats = cat===null?categories:[cat];
		var notMade = checkLayers(cat);
		var catName = '';
		if(notMade) {
			$.each(cats, function(i, val) {
				layer = new VEShapeLayer();
				layer.id = val;
				var shapes = [];
								
				if(loadIds!==null) {
					$.each(loadIds, function(k, val2) {
						$.each(items, function(j) {
							if(items[j].id==val2) {
								//cat = 'allcats';
								var d = addPoint(shapes, j, 'property', 'qstring');
							}								
						});						
					});
				} else {
					$.each(items, function(j) {										   										   
						var catSelectedArray = new Array( );
						var currarray = String(items[j].category);
						catSelectedArray = currarray.split(",");

						for (x in catSelectedArray){
							if(catSelectedArray[x]==val) {
								var d = addPoint(shapes, j, cat);
								var centerPoint = obj.getLatLong(items[j]['georss:point']); 		
								if (centerPoint != ''&centerPoint!='null,null') {
									var newPoint = new VELatLong(parseFloat(centerPoint[0]), parseFloat(centerPoint[1]));
								}
								centerArray.push(newPoint);
							}
						}
						
						
					});
				}
				map.AddShapeLayer(layer);		
				if ( (cat != 'property') && (cat != 'condo')) {
					$('.condo-list').each(function() { 
						if ($(this).hasClass('on')) {	
							var condoon = $(this).attr('id').toString().substr(11,1);
							var mapLayers = map.GetShapeLayerCount();
							for(var h=0; h<mapLayers; h++) {
								var l = map.GetShapeLayerByIndex(h);
								if(l.id!=undefined && l.id==condoon) {
									if ( l.IsVisible() ) {
										var shapeid = parseFloat(condoon) + 1;						
										var shape = l.GetShapeByIndex(0);
										shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+condoon+'-small.png" alt="" /></div>');									 
										$(this).removeClass('on');
									}
								}
							}
						}
					});
					//map.SetMapStyle(VEMapStyle.Road);
					map.SetCenterAndZoom(new VELatLong(zoomOutLat, zoomOutLong), 14);		
					//map.SetMapView(centerArray);
					centerArray.length = 0;
				}
			});
		}
	}
	
	function loadCondos(condoid) {
		var notMade = checkCondos(condoid);

                //if ( window.console ) console.log('hi')

                                                                /*
								var latLongPin = new VELatLong(parseFloat(point[0]), parseFloat(point[1]));
		
								map.SetCenterAndZoom(latLongPin, 16);
								map.SetMapStyle(VEMapStyle.Birdseye);											
								map.SetCenterAndZoom(latLongPin, 16);
                                                                */
		if(notMade) {
			layer = new VEShapeLayer();
			layer.id = condoid;
			var shapes = [];
			$.each(items, function(j) {
				if (condoid == items[j].id) {	
					var d = addPoint(shapes, j, 'property');
				}							
			});
			map.AddShapeLayer(layer);		
		}
	}
	
	function checkLayers(cat) {		
		var obj = this;
		var mapLayers = map.GetShapeLayerCount();
		for(var h=0; h<mapLayers; h++) {
			var l = map.GetShapeLayerByIndex(h);
			// this will hide the layer, since it is preloaded		
			if(l.id!=undefined && l.id==cat) {
				if ( l.IsVisible() ) {
					l.Hide();
					$('div#'+cat).removeClass('on');
					$('div#'+cat).addClass('off');
				} else {
					l.Show();
					
					if ( (cat != 'property') && (cat != 'condo')) {
						$('.condo-list').each(function() { 
							if ($(this).hasClass('on')) {	
								var condoon = $(this).attr('id').toString().substr(11,1);
								var cmapLayers = map.GetShapeLayerCount();
								for(var ch=0; ch<cmapLayers; ch++) {
									var cl = map.GetShapeLayerByIndex(ch);
									if(cl.id!=undefined && cl.id==condoon) {
										if ( cl.IsVisible() ) {
											var shapeid = parseFloat(condoon) + 1;						
											var shape = cl.GetShapeByIndex(0);
											shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+condoon+'-small.png" alt="" /></div>');									 
											$(this).removeClass('on');
										}
									}
								}
							}
	
							
							var cats = cat===null?categories:[cat];
							$.each(cats, function(i, val) {
								layer = new VEShapeLayer();
								layer.id = val;
								var shapes = [];
							
							
								$.each(items, function(j) {										   										   
									var catSelectedArray = new Array( );
									var currarray = String(items[j].category);
									catSelectedArray = currarray.split(",");
			
									for (x in catSelectedArray){
										if(catSelectedArray[x]==val) {
											var d = addPoint(shapes, j, cat);
											var centerPoint = obj.getLatLong(items[j]['georss:point']); 		
											if (centerPoint != ''&centerPoint!='null,null') {
												var newPoint = new VELatLong(parseFloat(centerPoint[0]), parseFloat(centerPoint[1]));
											}
											centerArray.push(newPoint);
										}
									}
								});
							});
							
						});
						
						//map.SetMapStyle(VEMapStyle.Road);
						map.SetMapView(centerArray);
						centerArray.length = 0;
						
						//centerArray.length = 0;
						//map.SetMapStyle(VEMapStyle.Road);
						//map.SetCenterAndZoom(new VELatLong(zoomOutLat, zoomOutLong), 14);		
					}
					
					$('div#'+cat).removeClass('off');
					$('div#'+cat).addClass('on');	
				}
				return false;
			} 			
		}
		return true;
	}
	
	
	function checkCondos(condoid) {
		var mapLayers = map.GetShapeLayerCount();
		for(var h=0; h<mapLayers; h++) {
			var l = map.GetShapeLayerByIndex(h);
			// this will hide the layer, since it is preloaded	
			
			if(l.id!=undefined && l.id!=condoid) {
				$('div.condo-list').each(function() { 														  
					var condoon = $(this).attr('id').toString().substr(11);
					if ( $(this).hasClass('on') ){							  
						if (condoon != condoid)
							$(this).removeClass('on'); 
										
						for(var h2=0; h2<mapLayers; h2++) {
							var l2 = map.GetShapeLayerByIndex(h2);
							if(l2.id==condoon) {
								var shape = l2.GetShapeByIndex(0);
								shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+condoon+'-small.png" alt="" /></div>');								
							}
						}
					}
				});							
			} else if (l.id==condoid && h == 2) {
				$('div.condo-list').each(function() { 														  
					var condoon = $(this).attr('id').toString().substr(11);
					if ( $(this).hasClass('on') ){							  
						if (condoon != condoid)
							$(this).removeClass('on'); 
										
						for(var h2=0; h2<mapLayers; h2++) {
							var l2 = map.GetShapeLayerByIndex(h2);
							if(l2.id==condoon) {
								var shape = l2.GetShapeByIndex(0);
								shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+condoon+'-small.png" alt="" /></div>');								
							}
						}
					}
				});				
			}
			
			if(l.id!=undefined && l.id==condoid) {
				if ( l.IsVisible() ) {
					if ( $('div#condo-list-'+condoid).hasClass('on') == false ) {
						var obj = this;																		
						$.each(items, function(j) {
							if (condoid == items[j].id) {
								condoid = parseFloat(condoid);
								var point = obj.getLatLong(items[j]['georss:point']); 
								var latLongPin = new VELatLong(parseFloat(point[0]), parseFloat(point[1]));
		
								map.SetCenterAndZoom(latLongPin, 16);
								map.SetMapStyle(VEMapStyle.Birdseye);											
								map.SetCenterAndZoom(latLongPin, 16);
																		
								var shape = l.GetShapeByIndex(0);
								currentID = condoid;
								shape.SetCustomIcon('<div id="pin-'+condoid+'" class="pushpin pushpin-condo pushpin-large"><img src="/images/map/pins/pin-'+condoid+'-large.png" alt="" /></div>');	
								$('div#condo-list-'+condoid).addClass('on');
								
								$('div#pin-'+condoid).parent().parent().css('z-index',1002);
							}
						});											
					} else {
						var obj = this;
						var shapeid = parseFloat(condoid) + 1;						
						var shape = l.GetShapeByIndex(0);
											
						var condoidx;
						$.each(items, function(j) {
							if (condoid == items[j].id) {
								condoidx = j;
							}
						});						
						
						var centerPoint = obj.getLatLong(items[condoidx]['georss:point']);
						var newPoint = new VELatLong(parseFloat(centerPoint[0]), parseFloat(centerPoint[1]));
						
						shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+condoid+'-small.png" alt="" /></div>');	
						var obj = this;
						var point = obj.getLatLong(items[condoidx]['georss:point']); 
						var latLongPin = new VELatLong(parseFloat(point[0]), parseFloat(point[1]));

                                                /* newww */
                                                map.SetCenterAndZoom(latLongPin, 16);
                                                map.SetMapStyle(VEMapStyle.Birdseye);											
                                                map.SetCenterAndZoom(latLongPin, 16);
						
						$('div#condo-list-'+condoid).removeClass('on');
						$('div#condo-list-'+condoid).addClass('off');
					}
				} else {
					var shape = l.GetShapeByIndex(0);
					shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+condoid+'-small.png" alt="" /></div>');	
				}
				return false;
			} 			
		}
		return true;
	}

	function addPoint(shapes, j, cat, cstm) {
		var obj = this;
		var info = '';
		var point = obj.getLatLong(items[j]['georss:point']); 
		if (point != '' & point!='null,null') {
			var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(parseFloat(point[0]), parseFloat(point[1])));
			var catName;
				
			var shapeCount = cstm?cstmCount:shapes.length;
			map.ClearInfoBoxStyles();
			
			//Set the icon
			var shapeCount = cstm?cstmCount:shapes.length;
				 
			//Set the info box
			map.ClearInfoBoxStyles();	
			map.AttachEvent("onmouseover", OnMouseOverCondo);
			map.AttachEvent("onclick", onClickCondo);		
			map.AttachEvent("onmousedown", OnMouseDown);
            map.AttachEvent("onmousemove", OnMouseMove);
            map.AttachEvent("onmouseup", OnMouseUp);
            map.AttachEvent("onstartpan", OnStartPan);
            map.AttachEvent("onstartzoom", OnStartZoom);
			map.AttachEvent('onendzoom',mapZoomed);

			if (cat == 'property') {
				info = '<div class="more-info-wrapper">';
				info += '<div class="more-info-content">';
				info += '<a href="#" onclick="EnableEroHide();map.HideInfoBox();changePin();return false;" class="btn-x-info"><img src="/images/map/btn-close-info.gif" /></a>';
				if(items[j].category!==''&&items[j].category!==undefined) {
					if ( items[j].category.length > 1 ) {
						shape.SetCustomIcon('<div class="pushpin"><img src="/images/map/pins/star.gif" alt="" /></div>');
						var catarraytemp = String(items[j].category);
						catarraytemp = catarraytemp.split(",");
						info += '<ul class="itemsub">';
						for (x in catarraytemp){								
							info += '<li id="iconcat-'+ catarraytemp[x] + '"><em class="alt">' + catarraytemp[x] + '</em></li>';
						}
						info += '</ul>';
						if(items[j].title!==''&&items[j].image!==undefined) {
							info += '<div class="title">'+items[j].title+'</div>';
						}
					} else {
						if (cstm=='qstring')
							shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+items[j].id+'-large.png" alt="" /></div>');
						else 
							shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+items[j].id+'-small.png" alt="" /></div>');
						if(items[j].title!==''&&items[j].title!==undefined) {
							info += '<div class="title">'+items[j].title+'</div>';
						}
					}				
					if (items[j].image!==''&&items[j].image!==undefined) {
						info += '<div class="box-links">';
						if(items[j].image!==''&&items[j].image!==undefined) {
							var imageurl = items[j].image;
							imageurl = imageurl.replace('small','orig');
							if(items[j]['galleryImages'].length){
								var gallerylist ='<div class="property-map-gallery"><ul>';
								$.each(items[j]['galleryImages'], function() {
								    gallerylist += '<li><img src="'+this+'" alt="" /></li>';
								});
								gallerylist += '</ul><div class="cycle-controls"><a class="prev" href="#">prev</a><a class="next" href="#">next</a></div></div>';
								gallerylist = gallerylist.replace(/small/g,'orig');
								info += '<div id="popup-image">'+gallerylist+'</div>';	
							} else {
								info += '<div id="popup-image"><img src="'+imageurl+'" alt="" /></div>';	
							}
						}		
						info += '</div>';		
					}
					if(items[j].address!==''&&items[j].address!==undefined) {
						info += '<div class="address">' + items[j].address + '</div>';
					}
					if(items[j].description!==''&&items[j].description!==undefined) {
						info += '<div class="description">' +  items[j].description + '</div>';
					}
					if(items[j].website!==''&&items[j].website!==undefined) {
						info += '<a class="map-btn-more-info" href="'+items[j].website+'"><img src="/images/map/btn-more-info.gif" alt="" /></a>';
					}
					
				}
				info += '</div>';
				info += '</div>';
								
			} else { 
				info = '<div class="cat-popup-wrapper">';
				info += '<a href="#" onclick="map.HideInfoBox();return false;" class="btn-x"><img src="/images/map/x.gif" /></a>';
			
				if(items[j].category!==''&&items[j].category!==undefined) {
					if ( items[j].category.length > 1 ) {
						shape.SetCustomIcon('<div class="pushpin"><img src="/images/map/pins/star.gif" alt="" /></div>');
						var catarraytemp = String(items[j].category);
						catarraytemp = catarraytemp.split(",");
						info += '<ul class="itemsub">';
						for (x in catarraytemp){								
							info += '<li id="iconcat-'+ catarraytemp[x] + '"><em class="alt">' + catarraytemp[x] + '</em></li>';
						}
						info += '</ul>';
						if(items[j].title!==''&&items[j].title!==undefined) {
							info += '<div class="title">'+items[j].title+'</div>';
						}
					} else {
						shape.SetCustomIcon('<div class="pushpin"><img src="/images/map/pins/unit.png" alt="" /></div>');
						if(items[j].title!==''&&items[j].title!==undefined) {
							info += '<div class="title">'+items[j].title+'</div>';
						}
					}
					if(items[j].image!==''&&items[j].image!==undefined) {
						info += '<div id="pin-image"><img src="'+items[j].image+'" alt="" /></div>';
					}
					if(items[j].address!==''&&items[j].address!==undefined) {
						info += '<div class="address">' + items[j].address + '</div>';
					}
					if(items[j].description!==''&&items[j].description!==undefined) {
						info += '<div class="description">' +  items[j].description + '</div>';
					}
					info += '<p class="box-links">';
					if(items[j].moreinfo!==''&&items[j].moreinfo!==undefined) {
						info += '<a onclick="map.HideInfoBox();return false;" href="'+items[j].moreinfo+'" target="_blank">More Info</a>';
					}		
					if (items[j].moreinfo!==''&& items[j].moreinfo!==undefined && items[j].schedule!=='' && items[j].schedule!==undefined) {
						info += '<span class="box-pipe">|</span>';	
					}		
					if(items[j].schedule!==''&&items[j].schedule!==undefined) {
						info += '<a onclick="map.HideInfoBox();return false;" href="'+items[j].schedule+'" target="_blank">Schedule</a>';
					}				
					info += '</p>';		
				}
				info += '</div>';			
			}		
			
			shape.SetDescription(info);
	
			if (cat == 'property')
				layer.id = items[j].id;
			else
				layer.id = cat;
			layer.AddShape(shape);
		}
	}

	function parseQuery(str){
		var vars = str.split("&");
		var pairs = {};
		for (var i=0;i<vars.length;i++) {
			var p = vars[i].split("=");
			pairs[p[0]] = this.urlDecode(p[1]);
		}
		return pairs;
	}
		
	function urlDecode(encodedString) {
		var output = encodedString;
		var binVal, thisString;
		var myregexp = /(%[^%]{2})/;
		while ((match = myregexp.exec(output)) !== null && match.length > 1 && match[1] !== '') {
			binVal = parseInt(match[1].substr(1),16);
			thisString = String.fromCharCode(binVal);
			output = output.replace(match[1], thisString);
		}
		return output;
	}	

	function changePin() {
		if (currentID != null) {
			currentPin.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+currentID+'-small.png" alt="" /></div>');	
			$('div#condo-list-'+currentID).removeClass('on');
		}
	}

	/* Map Override Functions */
	function OnMouseOverCondo(e) {
		var shape = map.GetShapeByID(e.elementID);
		if ( $('#'+e.elementID).find('div.pushpin').hasClass('pushpin-condo') ) {
			 return true;
		}		
	}

	function onClickCondo(e){
		var shape = map.GetShapeByID(e.elementID);
		currentPin = map.GetShapeByID(e.elementID);
		if ( $('#'+e.elementID).find('div.pushpin').hasClass('pushpin-condo') ) {
			// KEEPS INFO BOX ON THE MAP
			DisableEroHide();		
		
			 map.ShowInfoBox(shape, new VEPixel(40,30));
			 _currentShape = shape;
			 $('.property-map-gallery ul').cycle({ 
				 fx: 'fade',
				 next: '.next',
				 prev: '.prev'
			});
			 return true;
		}		
	}

	function OnMouseDown(e){
            if (e.leftMouseButton)
                _isPanning = true;
	}

	function OnMouseMove(e){
		if (_isPanning)
			CustomHideInfoBox(_currentShape);
	}

	function OnMouseUp(e){
		_isPanning = false;
	}       

	function OnStartPan(e){
		if (e.leftMouseButton)
		{
			// We don't want to handle this here, because a simple mouse click on a shape,
			// could be interpreted as a "start pan" action.
			return;
		}
		CustomHideInfoBox(_currentShape);
	}

	function OnStartZoom(e){
		CustomHideInfoBox(_currentShape);
	}

	function DisableEroHide(){
		_hide = window.ero.hide;
		window.ero.hide = function(a)
		{
			return;
		}       
	}
   
	function EnableEroHide(){
		window.ero.hide = _hide;
	}

	function CustomHideInfoBox(shape){
		if (!shape)
			return;
		   
		EnableEroHide();
		map.HideInfoBox(shape);
		_currentShape = null;
	}
	
	function mapZoomed(e){
		if(e!=null){
			var zoom = e.zoomLevel;	
			if (zoom >= 16) {
			} else { 
				if(e.mapStyle!='o') {
					var mapLayers = map.GetShapeLayerCount();
					for(var h=0; h<mapLayers; h++) {
						var l = map.GetShapeLayerByIndex(h);
						// this will hide the layer, since it is preloaded		
						$('div.condo-list').each(function() { 														  
							var condoon = $(this).attr('id').toString().substr(11,2);
							if ( $(this).hasClass('on') ){							
								$.each(items, function(k) {
									if (condoon != items[k].id) { 
										$('div#condo-list-'+condoon).removeClass('on'); 
									}
								});
														
												
								for(var h2=0; h2<mapLayers; h2++) {
									var l2 = map.GetShapeLayerByIndex(h2);
									if(l2.id==condoon) {
										var shape = l2.GetShapeByIndex(0);
										shape.SetCustomIcon('<div class="pushpin pushpin-condo"><img src="/images/map/pins/pin-'+condoon+'-small.png" alt="" /></div>');								
									}
								}
							}
						});										
					}
				}
			}
		}
	}

