var map=false;var entities=new Array;var overlay_height=120;var mapControl=false;var currentPage=0;var initGMap=function(){if(window.GBrowserIsCompatible&&GBrowserIsCompatible()){window.addEvent("unload",function(){GUnload()});$("gmap").style.display="block";map=new GMap2($("gmap"));map.setCenter(new GLatLng(DEFAULT_LAT,DEFAULT_LONG),MAP_ZOOM);mapControl=new GSmallMapControl();map.addControl(mapControl,new GControlPosition(G_ANCHOR_TOP_LEFT));map.addControl(new GScaleControl());cgIcon=new GIcon(G_DEFAULT_ICON);cgIcon.image="/images/map-logo.png";cgIcon.iconSize=new GSize(41,47);cgIcon.shadowSize=new GSize(0,0);markerOptions={icon:cgIcon};point=new GLatLng(DEFAULT_LAT,DEFAULT_LONG);map.addOverlay(new GMarker(point,markerOptions));if(window.landmark!=undefined){populateLandmarks()}return true}return false};var Overlay=new Class({Implements:Log,initialize:function(a,b){this.element=new Element("table",{id:"entity-overlay"});this.fx=new Fx.Tween(this.element);this.ref=b;this.element.setStyles({opacity:0});this.setStyles();this.element.adopt(a.clone());this.element.getElement(".geo").destroy();this.element.getElement("span.region").destroy();this.element.getElement("br").destroy();this.element.obj=this;this.closeLink=new Element("a",{html:"[x] close",href:"#",id:"close-overlay"});this.element.getElement("tr.name td").adopt(this.closeLink);if(link=this.element.getElement("a.url")){link.externalLink()}this.closeLink.addEvent("click",this.destroy.bind(this))},setStyles:function(){coords=$("gmap").getCoordinates();this.element.setStyles({position:"absolute",top:coords.top,left:coords.left,"background-color":"#000",width:coords.width,display:"block"})},destroy:function(a){if(a instanceof Event){a.preventDefault()}if(!this.fx){return}this.fx.start("opacity",0.9,0).chain(this.postDestroy())},postDestroy:function(){this.element=this.element.dispose();this.visible=false;map.removeControl(mapControl);map.addControl(mapControl,new GControlPosition(G_ANCHOR_TOP_LEFT));entities[this.ref].deactivate()},show:function(){if($("entity-overlay")){$("entity-overlay").obj.destroy()}document.getElement("body").adopt(this.element);this.visible=true;this.fx.start("opacity",0,0.9).chain(function(){map.removeControl(mapControl);map.addControl(mapControl,new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(0,20)))})}});var Entity=new Class({Implements:Log,initialize:function(b,c,a){if(a!==false){a=true}geo=b.getElement(".geo");if(geo){this.domId=b.getParent().id;this.inactive=true;this.name=b.getElement(".fn.org").innerHTML;this.latitude=geo.getElement(".latitude").innerHTML;this.longitude=geo.getElement(".longitude").innerHTML;this.latLng=new GLatLng(this.latitude,this.longitude);this.ref=c;this.createMarker(a);this.mapLink=new Element("a",{html:"Show on map",href:"#"});this.mapLink.Entity=this;if(!a){return}this.overlay=new Overlay(b,this.ref);this.mapLink.addEvent("click",function(d){d.preventDefault();gmapPos=$("gmap").getCoordinates();scroller=new Fx.Scroll(window);scroller.Entity=this;scroller.addEvent("complete",function(){map.panTo(d.target.Entity.latLng);d.target.Entity.toggleStates()});scroller.toTop()});this.mapLink.inject(b.getElement("p.adr"),"top")}},createMarker:function(a,b){if(a!==false){a=true}myIcon=new GIcon(G_DEFAULT_ICON);if(b){this.inactive=false;myIcon.image=HTTP_HOST+"/images/marker-active.png"}else{this.inactive=true;myIcon.image=HTTP_HOST+"/images/marker.png"}myIcon.shadow=false;this.point=new GLatLng(this.latitude,this.longitude);this.marker=new GMarker(this.point,myIcon);GEvent.addListener(this.marker,"click",this.bindClickEvent.bind(this));if(a){this.marker.tooltip=tooltip=new Tooltip(this.marker,this.name+"<br />Click for more information",4);GEvent.addListener(this.marker,"mouseover",function(){this.tooltip.show()});GEvent.addListener(this.marker,"mouseout",function(){this.tooltip.hide()});map.addOverlay(tooltip)}map.addOverlay(this.marker)},bindClickEvent:function(){this.toggleStates()},deactivate:function(){if(!this.marker||!this.marker instanceof GMarker||this.inactive){return}this.inactive=true;this.marker.setImage(HTTP_HOST+"/images/marker.png")},activate:function(){this.marker.tooltip.hide();if(this.marker&&this.marker instanceof GMarker){this.inactive=false;map.setCenter(this.marker.getLatLng());this.marker.setImage(false);this.marker.setImage(HTTP_HOST+"/images/marker-active.png");this.overlay.show()}},toggleStates:function(){for(n=0;n<entities.length;n++){if(entities[n] instanceof Entity){if(n==this.ref){this.activate()}else{entities[n].deactivate()}}}}});window.addEvents({domready:function(){if(initGMap()){if(document.getElement("body").id=="directory"){i=0;$$("table#list tbody.vcard").each(function(a){entities[i]=new Entity(a,i);i++});p=new Pagination($$("table#list tbody.vcard"),10,1,$("list"),"after")}else{if(document.getElement("body").id=="entity"||document.getElement("body").id=="article"){singleEntity=new Entity(document.getElement(".vcard"),1,false);map.setCenter(singleEntity.marker.getPoint())}}}},resize:function(){for(i=0;i<entities.length;i++){if(entities[i].overlay instanceof Overlay){entities[i].overlay.setStyles()}}}});
