var ssInfoWindow=function(A,C,B){this.marker=A;this.title=C;this.content=B};ssInfoWindow.prototype=new GOverlay();ssInfoWindow.prototype.initialize=function(E){var D=document.createElement("div");D.className="info_window";D.id="gmap_info_window";var B=document.createElement("div");B.id="info_window_bg";B.className="png";var A=document.createElement("div");A.id="close_button";A.className="png";var F=document.createElement("h1");F.innerHTML=this.title;var C=document.createElement("p");C.innerHTML=this.content;D.appendChild(B);D.appendChild(A);D.appendChild(F);D.appendChild(C);offsetX=100;offsetY=120;D.style.top=(E.fromLatLngToDivPixel(this.marker.getPoint()).y-offsetY)+"px";D.style.left=(E.fromLatLngToDivPixel(this.marker.getPoint()).x-offsetX)+"px";A.onclick=ssGmap.closeOverlay;this._map=E;this._div=D;E.getPane(G_MAP_FLOAT_PANE).appendChild(D)};ssInfoWindow.prototype.remove=function(){this._div.parentNode.removeChild(this._div)};ssInfoWindow.prototype.redraw=function(){offsetX=100;offsetY=120;var A=document.getElementById("gmap_info_window");this._div.style.top=(map.fromLatLngToDivPixel(this.marker.getPoint()).y-offsetY)+"px";this._div.style.left=(map.fromLatLngToDivPixel(this.marker.getPoint()).x-offsetX)+"px"};function SurfshotMapControls(){}SurfshotMapControls.prototype=new GControl();SurfshotMapControls.prototype.setButtonStyle_=function(A){A.style.margin="2px";A.style.cursor="pointer";A.style.position="absolute";A.className="png"};SurfshotMapControls.prototype.initialize=function(A){var B=document.createElement("div");this.container=B;var E=Ext.get("gmap");var K=document.createElement("img");K.src="/images/gmap/map_type-map.png";this.setButtonStyle_(K);K.style.top="0px";K.style.left=(E.getWidth()-184)+"px";B.appendChild(K);GEvent.addDomListener(K,"click",function(){A.setMapType(G_NORMAL_MAP)});var I=document.createElement("img");I.src="/images/gmap/map_type-satellite.png";this.setButtonStyle_(I);I.style.top="0px";I.style.left=(E.getWidth()-124)+"px";B.appendChild(I);GEvent.addDomListener(I,"click",function(){A.setMapType(G_SATELLITE_MAP)});var H=document.createElement("img");H.src="/images/gmap/map_type-hybrid.png";this.setButtonStyle_(H);H.style.top="0px";H.style.left=(E.getWidth()-64)+"px";B.appendChild(H);GEvent.addDomListener(H,"click",function(){A.setMapType(G_HYBRID_MAP)});var F=document.createElement("img");F.src="/images/gmap/map_icons-plus.png";this.setButtonStyle_(F);F.style.top="70px";F.style.left="10px";B.appendChild(F);GEvent.addDomListener(F,"click",function(){A.zoomIn()});var L=document.createElement("img");L.src="/images/gmap/map_icons-minus.png";this.setButtonStyle_(L);L.style.top="90px";L.style.left="10px";B.appendChild(L);GEvent.addDomListener(L,"click",function(){A.zoomOut()});var J=document.createElement("img");J.src="/images/gmap/map_icons-left.png";this.setButtonStyle_(J);J.style.top="20px";J.style.left="0px";B.appendChild(J);GEvent.addDomListener(J,"click",function(){A.panDirection(+1,0)});var G=document.createElement("img");G.src="/images/gmap/map_icons-right.png";this.setButtonStyle_(G);G.style.top="20px";G.style.left="20px";B.appendChild(G);GEvent.addDomListener(G,"click",function(){A.panDirection(-1,0)});var D=document.createElement("img");D.src="/images/gmap/map_icons-up.png";this.setButtonStyle_(D);D.style.top="0";D.style.left="10px";B.appendChild(D);GEvent.addDomListener(D,"click",function(){A.panDirection(0,+1)});var C=document.createElement("img");C.src="/images/gmap/map_icons-down.png";this.setButtonStyle_(C);C.style.top="40px";C.style.left="10px";B.appendChild(C);GEvent.addDomListener(C,"click",function(){A.panDirection(0,-1)});A.getContainer().appendChild(B);return B};SurfshotMapControls.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(0,0))};var ssGmap={contextIcons:{Restaurants:"restaurant",Bars:"bar","Surf Shops":"surfshop","Surf Camps":"surfcamp","Surf Gear":"shaper",Spots:"wave","Travel Directory":"travel","Surf Board Repair":"shaper","Surf Boards":"surfshop",Photographers:"photo",Skateboard:"skateboard","Surf Clubs":"school","Surf Art":"surfshop","Surf Schools":"school",Hotels:"vacation","Vacation Rentals":"vacation","Surf Travel":"travel",Camping:"surfcamp","Non-Profit":"nonprofit",Default:"business"},icons:[],markers:[],currentMarker:null,currentRow:null,currentRowClass:null,decorateIcon:function(A){A.shadow="/images/gmap/map_marker_shadow.png";A.iconSize=new GSize(37,27);A.shadowSize=new GSize(57,27);A.iconAnchor=new GPoint(18,15);A.infoWindowAnchor=new GPoint(18,1)},createIcons:function(C){var A=(this.contextIcons[C])?this.contextIcons[C]:"business";for(var B=0;B<=10;B++){this.icons[B]=new GIcon();this.decorateIcon(this.icons[B]);this.icons[B].image="/images/gmap/map_marker-"+A+B+".png"}},createIcon:function(C,B){var A=(this.contextIcons[C])?this.contextIcons[C]:"business";icon=new GIcon();ssGmap.decorateIcon(icon);icon.image="/images/gmap/map_marker-"+A+B+".png";return icon},addMarker:function(A){this.markers.push(A)},load:function(A){if(GBrowserIsCompatible()){geocoder=new GClientGeocoder();map=new GMap2(document.getElementById("gmap"));map.addControl(new SurfshotMapControls());map.setCenter(new GLatLng(40,-100),4);ssGmap.getLocations(A)}},searchLocationsNear:function(B){var A=25;var C="locations.xml.php?lat="+B.lat()+"&lng="+B.lng()+"&radius="+A;GDownloadUrl(C,function(J){var L=GXml.parse(J);var H=L.documentElement.getElementsByTagName("marker");map.clearOverlays();var D=document.getElementById("sidebar");D.innerHTML="";if(H.length==0){D.innerHTML="No results found.";map.setCenter(new GLatLng(40,-100),4);return }var E=new GLatLngBounds();for(var K=0;K<H.length;K++){var G=H[K].getAttribute("name");var N=H[K].getAttribute("address");var F=parseFloat(H[K].getAttribute("distance"));var M=new GLatLng(parseFloat(H[K].getAttribute("lat")),parseFloat(H[K].getAttribute("lng")));var I=ssGmap.createMarker(M,G,N,K+1);map.addOverlay(I);E.extend(M)}map.setCenter(E.getCenter(),map.getBoundsZoomLevel(E))})},plotLocations:function(B){var F=this.markers;map.clearOverlays();if(F.length==0){return }var A=new GLatLngBounds();for(var H=0;H<F.length;H++){if(F[H]["lat"]!=0&&F[H]["lng"]!=0){var D=F[H]["name"];var K=F[H]["address"];var I=F[H]["index"];var E=F[H]["context"];var C=parseFloat(F[H]["distance"]);var J=new GLatLng(parseFloat(F[H]["lat"]),parseFloat(F[H]["lng"]));var G=ssGmap.createMarker(J,D,K,I,E);map.addOverlay(G);A.extend(J)}}map.setCenter(A.getCenter(),map.getBoundsZoomLevel(A))},searchLocations:function(){var A=document.getElementById("addressInput").value;geocoder.getLatLng(A,function(B){if(!B){alert(A+" not found")}else{ssGmap.searchLocationsNear(B)}})},getLocations:function(A){geocoder.getLatLng(A,function(B){if(!B){alert(A+" not found")}else{ssGmap.plotLocations(B)}})},createMarker:function(I,A,H,E,B){var F=ssGmap.createIcon(B,E);var D=new GMarker(I,{icon:F});GEvent.addListener(D,"click",function(){if(typeof ssInfoWindow!=="undefined"){ssGmap.closeOverlay();if(ssGmap.currentRow){ssGmap.currentRow.className=ssGmap.currentRowClass}if(!this.overlay){this.overlay=new ssInfoWindow(this,A,H)}ssGmap.currentMarker=this;ssGmap.currentRow=document.getElementById("map_item-"+E);ssGmap.currentRowClass=ssGmap.currentRow.className;ssGmap.currentRow.className+=" map_item-active";map.panTo(new GLatLng(this.getPoint().lat(),this.getPoint().lng()));map.addOverlay(this.overlay)}else{D.openInfoWindowHtml(html)}});var G=document.createElement("img");G.src=F.image;G.className="noborders png";var C=document.getElementById("map_icon-"+E);C.appendChild(G);GEvent.addDomListener(C,"click",function(){GEvent.trigger(D,"click")});return D},closeOverlay:function(){if(ssGmap.currentMarker){map.removeOverlay(ssGmap.currentMarker.overlay);ssGmap.currentRow.className=ssGmap.currentRowClass}},createSidebarEntry:function(B,D,A,G,C){var F=document.createElement("div");var E='<h3 style="width:30px;float:left;clear:left;">'+C+"</h3><b>"+D+"</b> ("+G.toFixed(1)+")<br/>"+A;F.innerHTML=E;F.style.cursor="pointer";F.style.marginBottom="5px";GEvent.addDomListener(F,"click",function(){GEvent.trigger(B,"click")});GEvent.addDomListener(F,"mouseover",function(){F.style.backgroundColor="#eee"});GEvent.addDomListener(F,"mouseout",function(){F.style.backgroundColor="#fff"});return F}};window.onunload=GUnload;