/*
 * MapsObjectsManager
 * (c) visuamundo.com
 * Version 1.0
 */
function MapObjectsManager(gmap,path2jsondata){this.map=gmap;this.mapData={};this.infoWindow=new google.maps.InfoWindow();this.mapObjects={};this.mapObjects.markers={};this.mapObjects.overlays={};this.mapObjects.infowindows={};this.loadJson(path2jsondata);}MapObjectsManager.prototype.loadJson=function(path){var d=new Date();path+="?d="+d.getTime();var that=this;$.getJSON(path,function(data){that.mapData=data;that.createMapObjects(data);});};MapObjectsManager.prototype.createMapObjects=function(jsonData){if(jsonData.hasOwnProperty('markers')){this.createMarkers(jsonData.markers);}};MapObjectsManager.prototype.createMarkers=function(markerData){var i=0;for(var mId in markerData){var latLon=new google.maps.LatLng(parseFloat(markerData[mId].lat),parseFloat(markerData[mId].lon));var img=this.createMarkerImage(mId,markerData[mId].icon.img);var imgOver=this.createMarkerImage(mId,markerData[mId].icon.imghighlight);var imgShadow=this.createMarkerImage(mId,markerData[mId].icon.shadowicon);var marker=new google.maps.Marker({position:latLon,title:markerData[mId].title,shadow:imgShadow,icon:img,zIndex:parseInt(markerData[mId].zindex),visible:markerData[mId].visibility});marker.set("id",mId);marker.set("iconOver",imgOver);marker.set("iconNormal",img);this.addEventToMarker(marker);marker.setMap(this.map);this.mapObjects.markers[mId]=marker;if(this.mapData.infowindows[mId]){this.mapObjects.infowindows[mId]=this.mapData.infowindows[mId];}}};MapObjectsManager.prototype.addEventToMarker=function(marker){var that=this;google.maps.event.addListener(marker,'click',function(){that.openInfoWindow(marker);});google.maps.event.addListener(marker,'mouseover',function(){that.changeMarkerIconOver(marker.id);});google.maps.event.addListener(marker,'mouseout',function(){that.changeMarkerIconNormal(marker.id);});};MapObjectsManager.prototype.openInfoWindow=function(marker){var cont='';if(this.mapObjects.infowindows[marker.id]){cont=this.mapObjects.infowindows[marker.id].content;}else{return;}this.infoWindow.setContent(cont);this.infoWindow.setPosition(marker.getPosition());this.infoWindow.open(this.map,marker);};MapObjectsManager.prototype.createMarkerImage=function(markerId,imgURL){var image=new google.maps.MarkerImage(imgURL,new google.maps.Size(this.mapData.markers[markerId].icon.width,this.mapData.markers[markerId].icon.height),new google.maps.Point(0,0),new google.maps.Point(this.mapData.markers[markerId].icon.imganchorx,this.mapData.markers[markerId].icon.imganchory));return image;};MapObjectsManager.prototype.changeMarkerIconOver=function(markerId){var marker=this.mapObjects.markers[markerId];marker.setIcon(marker.iconOver);};MapObjectsManager.prototype.changeMarkerIconNormal=function(markerId){var marker=this.mapObjects.markers[markerId];marker.setIcon(marker.iconNormal);};MapObjectsManager.prototype.hideMarker=function(markerId){var marker=this.mapObjects.markers[markerId];marker.setVisible(false);};MapObjectsManager.prototype.showMarker=function(markerId){var marker=this.mapObjects.markers[markerId];marker.setVisible(true);};MapObjectsManager.prototype.toggleMarkerVisibility=function(markerId){var marker=this.mapObjects.markers[markerId];marker.setVisible(!marker.getVisible());}
