if(typeof(Meetup)=="undefined"){Meetup={}}Meetup.GMap=function(window,div,centLat,centLon,width,height,noBalloon,isTopic){this.window=window;this.div=div;this.centLat=centLat;this.centLon=centLon;this.width=width;this.height=height;this.noBalloon=noBalloon;this.isTopic=isTopic||false;this.editable=false;this.zoom=11;this.bounds=[];this.frame=null;this.gmap=null;this.data=[];this.points=[];this.pendData=[];this.displayed=false;this.isOverlay=false};Meetup.GMap.prototype.getData=function(){return this.data};Meetup.GMap.prototype.getPoints=function(){return this.points};Meetup.GMap.prototype.getCentLat=function(){return this.centLat};Meetup.GMap.prototype.getCentLon=function(){return this.centLon};Meetup.GMap.prototype.getEditable=function(){return this.editable};Meetup.GMap.prototype.getGMap=function(){return this.gmap};Meetup.GMap.prototype.isDisplayed=function(){return this.displayed};Meetup.GMap.prototype.getZoom=function(){return this.zoom};Meetup.GMap.prototype.setData=function(data,markerColor){this.data[markerColor]=data};Meetup.GMap.prototype.setZoom=function(zoom){this.zoom=zoom};Meetup.GMap.prototype.setEditable=function(editable){this.editable=editable};Meetup.GMap.prototype.setIsTopicMap=function(){this.isTopicMap=true};Meetup.GMap.prototype.insertMap=function(){var zoom=this.zoom;var iframe='<iframe name="mapFrame" frameborder="0" scrolling="no" id="mapFrame" style="width: 100%; '+(this.width>0?"width: expression('"+this.width+"px');":"")+"height: "+this.height+'px" src="http://www.meetup.com/gmaps/gmap_frame.jsp?lat='+this.centLat+"&lon="+this.centLon+"&zoom="+(zoom?zoom:"11")+"&smallMap=1"+(this.width>0?"&width="+this.width:"")+"&height="+this.height+""+(this.editable?"&edit=1":"")+(this.isTopic?"&istopic=1":"")+'"></iframe>';this.div.innerHTML=iframe};Meetup.GMap.prototype.setGMap=function(gmap){this.gmap=gmap;if(this.isOverlay){gmap.addOverlay(this)}if(this.pendData&&this.pendData.length>0){for(var color in pendData){this.plotPoints(this.pendData[color],color)}this.pendData=null}};Meetup.GMap.prototype.setIsOverlay=function(){this.isOverlay=true};Meetup.GMap.prototype.plotPoints=function(points,markerColor,now){this.points[markerColor]=points;if(!this.data[markerColor]){this.data[markerColor]=points}else{for(var i=0;i<points.length;i++){this.data[markerColor].push(points[i])}}if(this.gmap&&now){if(!this.frame){this.frame=this.window.frames.mapFrame}this.frame.plotWrapper(this)}};Meetup.GMap.prototype.safeClearMap=function(){try{for(var i=0;i<this.points.length;i++){if(this.points[i]){this._map.removeOverlay(this.points[i])}}}catch(e){}try{if(this.isOverlay){var pane=this.getGMap().getPane(4);pane.innerHTML=""}}catch(e){}this.data=[];this.points=[];this.pendData=[]};Meetup.GMap.prototype.clearMap=function(){this.data=[];this.points=[];this.pendData=[];try{this.gmap.clearOverlays()}catch(e){}try{if(this.isOverlay){var pane=this.getGMap().getPane(4);pane.innerHTML=""}}catch(e){}};Meetup.GMap.markerImg={black:"http://img1.meetupstatic.com/img/71485564981052320/pin/mm_20_black.png",blue:"http://img1.meetupstatic.com/img/055321427273940750224/pin/mm_20_blue.png",green:"http://img1.meetupstatic.com/img/43777896878374447/pin/mm_20_green.png",orange:"http://img1.meetupstatic.com/img/4721214854214212529/pin/mm_20_orange.png",purple:"http://img1.meetupstatic.com/img/87578529171532395874/pin/mm_20_purple.png",red:"http://img1.meetupstatic.com/img/2184992875147899292278/pin/mm_20_red.png",white:"http://img1.meetupstatic.com/img/58732790581107660521/pin/mm_20_white.png",yellow:"http://img1.meetupstatic.com/img/3403841687252425248275/pin/mm_20_yellow.png",red_trans:"http://img1.meetupstatic.com/img/2184992875147899292278/pin/mm_20_red.png",white_trans:"http://img1.meetupstatic.com/img/58732790581107660521/pin/mm_20_white.png"};Meetup.GMap.drawMap=function(map){this.displayed=true;var gmap=map.getGMap();gmap.checkResize();var data=map.getData();var points=map.getPoints();var zoom=map.getZoom();var isTopicMap=map.isTopicMap;var sets=[];function extract_set(points){var extracted=[];var index=0;for(var color in points){var data=points[color];for(var i=0;i<data.length;i++){var datum=data[i];datum.color=color;var key=datum.latitude+":"+datum.longitude;if(!extracted[key]){extracted[key]=[];extracted[key]["index"]=index++;extracted[key]["data"]=new Array();index++}extracted[key]["data"].push(datum)}}extracted.index=index;return extracted}sets=extract_set(points);if(sets.index>0){delete sets.index;if(map.isOverlay){var pane=map.getGMap().getPane(4)}else{var baseIcon=new GIcon();baseIcon.shadow="http://img1.meetupstatic.com/img/69201937097781826/pin/mm_20_shadow.png";baseIcon.iconSize=new GSize(13,18);baseIcon.shadowSize=new GSize(22,20);baseIcon.iconAnchor=new GPoint(6,20);baseIcon.infoWindowAnchor=new GPoint(5,1);baseIcon.infoShadowAnchor=new GPoint(11,15)}for(var key in sets){var point=sets[key];for(var i=0,il=point.data.length;i<il;i++){if(map.isOverlay){this.addOverlayNode(point,point.data[i],map,point.data[i].color)}else{baseIcon.image=Meetup.GMap.markerImg[point.data[i].color];gmap.addOverlay(Meetup.GMap.makeMarker(point,baseIcon,map))}}}}sets=extract_set(data);if(sets.index>0){delete sets.index;var bounds=Meetup.GMap.getBounds(sets);if(isTopicMap){zoom=(gmap.getBoundsZoomLevel(bounds)>4?4:gmap.getBoundsZoomLevel(bounds))}else{zoom=gmap.getZoom()}gmap.setCenter(bounds.getCenter(),zoom,G_NORMAL_MAP)}else{try{gmap.setCenter(new GLatLng(map.getCentLat(),map.getCentLon()),zoom,G_NORMAL_MAP)}catch(e){}}};Meetup.GMap.addOverlayNode=function(fullDataSet,dataSet,map,color){var pane=map.getGMap().getPane(4);var datum=dataSet;var point=new GLatLng(datum.latitude,datum.longitude);var pos=gmap.fromLatLngToDivPixel(point);datum.point=point;datum.node=document.createElement("div");datum.node.style.left=pos.x+"px";datum.node.style.top=pos.y+"px";datum.node.className="marker-"+color;if(!map.noBalloon){datum.node.onclick=function(){gmap.openInfoWindowHtml(point,Meetup.GMap.getMarkup(fullDataSet))}}pane.appendChild(datum.node)};Meetup.GMap.prototype.copy=function(){};Meetup.GMap.prototype.initialize=function(map){};Meetup.GMap.prototype.redraw=function(force){if(force){for(var color in this.data){var points=this.data[color];for(var key in points){var dataSet=points[key];if(dataSet.node&&dataSet.point){var iconPosition=this.gmap.fromLatLngToDivPixel(dataSet.point);dataSet.node.style.left=iconPosition.x+"px";dataSet.node.style.top=iconPosition.y+"px"}}}}};Meetup.GMap.getBounds=function(sets){try{var bounds=new GLatLngBounds();for(var key in sets){var pts=key.split(":");bounds.extend(new GLatLng(parseFloat(pts[0]),parseFloat(pts[1])))}return bounds}catch(e){return[]}};Meetup.GMap.makeMarker=function(dataSet,baseIcon,map){var domain="meetup.com";var icon=new GIcon(baseIcon);var point=new GLatLng(dataSet.data[0].latitude,dataSet.data[0].longitude);var marker;if(map.getEditable()){marker=new GMarker(point,{icon:icon,draggable:true});GEvent.addListener(marker,"dragend",function(){Meetup.GMap.reportNewCoords(marker.getPoint())})}else{marker=new GMarker(point,icon)}if(typeof(dataSet.data[0]["count"])!=="undefined"&&!this.noBalloon){GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(Meetup.GMap.getMarkup(dataSet))})}return marker};Meetup.GMap.getMarkup=function(dataSet){var my;for(var i=0;i<dataSet.data.length;i++){var group=dataSet.data[i];var memberLbl=Meetup.Copy.memberLbl.replace("__MEMBER_CNT__",group.note);if(group.url){mu='<nobr><a target="_top" href="'+group.url+'">'+group.count+"</a></nobr><br />"+(group.photo?('<img style="float: left" src="'+group.photo+'"/>'):"")+"<nobr>"+memberLbl+"</nobr><br />"}else{mu="<strong>"+Meetup.Copy.waitingLbl.replace("__MEMBER_CNT__",group.count).replace("__CITY__",group.city)+"</strong><br />"+(group.photo?('<img style="float: left" src="'+group.photo+'"/>'):"")+"<br />"}}return mu};Meetup.GMap.reportNewCoords=function(coords){top.setCoords(coords.lat(),coords.lng())};Meetup.GMap.icon={red:null,blue:null,yellow:null,green:null,orange:null,purple:null,white:null,black:null};
