GControl.subclasses=[];var Control=Class.create(GControl,{initialize:function(a){var b=this._initialized?this._addToMap:this._initialize;return b.apply(this,arguments)},_initialize:function(a){this.container=a;this._initialized=true},_addToMap:function(a){a.getContainer().appendChild(this.container);return this.container},getDefaultPosition:function(){return new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,7))}});var Map=Class.create({initialize:function(b,a){this.options=Object.extend({feed:null,userIcon:{},multipleIcon:{}},a||{});this.activeMarkers=$H();this.map=new GMap2(document.getElementById(b));this.map.addMapType(G_PHYSICAL_MAP);this.map.setMapType(G_PHYSICAL_MAP);this.types={k:G_SATELLITE_MAP,h:G_HYBRID_MAP,m:G_NORMAL_MAP,p:G_PHYSICAL_MAP};var c=location.href.split("geo:")[1];if(c){c=c.split(",");this.map.setCenter(new GLatLng(Number(c[0]),Number(c[1])),Number(c[2])||15);if(c[3]&&$w("k h m p").include(c[3])){this.map.setMapType(this.types[c[3]])}this.reload()}else{this.map.setCenter(new GLatLng(51,11),2)}this.map.enableDoubleClickZoom();this.map.enableContinuousZoom();this.USER_ICON=new GIcon(this.options.userIcon);this.MULTIPLE_ICON=new GIcon(this.options.multipleIcon);this.MULTIPLE_ICON_BIG=new GIcon(this.options.multipleBigIcon);this.setupTypeControl();this.setupMoveControl();this.setupZoomControl();this.registerEvents()},setupTypeControl:function(){var c=$("type_control");this.map.addControl(new Control(c),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,7)));var a={p:$("map_type_p"),k:$("map_type_k"),m:$("map_type_m"),h:$("map_type_h")};var b=function(){Object.values(a).invoke("removeClassName","active");a[this.map.getCurrentMapType().getUrlArg()].addClassName("active")}.bind(this);Object.values(a).each(function(d){GEvent.addDomListener(d,"click",function(e){if(e&&("stop" in e)){e.stop()}this.map.setMapType(this.types[d.id.gsub("map_type_","")]);b()}.bind(this))},this);b();c.show()},setupMoveControl:function(){var a=$("move_control");this.map.addControl(new Control(a),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,35)));var b=100;$w("left right up down center").each(function(c){GEvent.addDomListener($(c),"click",function(d){if(d&&("stop" in d)){d.stop()}if(c!="center"){this.map.panBy(new GSize(c=="left"?b:c=="right"?-b:0,c=="up"?b:c=="down"?-b:0))}else{this.map.setCenter(new GLatLng(51,11),2)}}.bind(this))},this);a.show()},setupZoomControl:function(){var a=$("zoom_control");this.map.addControl(new Control(a),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(7,120)));$w("plus minus").each(function(b){GEvent.addDomListener($(b),"click",function(c){if(c&&("stop" in c)){c.stop()}this.map[b=="plus"?"zoomIn":"zoomOut"]()}.bind(this))},this);a.show()},registerEvents:function(){GEvent.addListener(this.map,"zoomend",this.checkForReload.curry(true).bind(this));GEvent.addListener(this.map,"dragend",this.checkForReload.bind(this));GEvent.addDomListener(this.map,"click",this.dispatchClick.bind(this))},dispatchClick:function(a){if(a&&a._type&&(a._type.include("cluster")||a._type.include("single")||a._type.include("list"))){this.showInfoFor(a)}},showInfoFor:function(a){if(a._type=="single"){this.renderSingleInfo(a)}else{if(a._type=="list"){this.renderListInfo(a)}else{if(a._type=="cluster"){this.renderMultipleInfo(a)}}}},renderSingleInfo:function(a){var c=a._info,b='<div class="map-single-profile"><img src="#{avatar}" width="32" height="32"/><div class="info"><h4>#{login}</h4>#{address}<br/><a href="/profile/#{login}" class="more">Profil anzeigen</a></div></div>';a.openInfoWindowHtml(new Template(b).evaluate(c))},renderListInfo:function(a){html="";a._info.each(function(b){template='<div class="map-single-profile"><img src="#{avatar}" width="32" height="32"/><div class="info"><h4>#{login}</h4>#{address}<br/><a href="/profile/#{login}" class="more">Profil anzeigen</a></div></div>';html+=new Template(template).evaluate(b)});html='<div class="marker-profile-list">'+html+"</div>";a.openInfoWindowHtml(html)},renderMultipleInfo:function(marker){var info=marker._info,id="cluster_content_"+new Date().getTime(),content='<div class="map-multiple-users" id="'+id+'"></div>';marker.openInfoWindowHtml(content);new Ajax.Request("/map/cluster_details",{method:"get",parameters:{q:info.bounds},onSuccess:function(request){var responseText=request.responseText;var bounds=info.bounds.split(",");var gBounds=new GLatLngBounds(new GLatLng(bounds[0],bounds[1]),new GLatLng(bounds[2],bounds[3]));var link=new Element("a",{href:"#",className:"more"}).update("Zoom").observe("click",function(event){if(event&&("stop" in event)){event.stop()}this.map.setCenter(gBounds.getCenter());this.map.setZoom(this.map.getBoundsZoomLevel(gBounds));marker.closeInfoWindow()}.bind(this));var content=new Element("div",{className:"count"}).update("In diesem Bereich gibt es "+info.count+" Sauspieler ").insert(link);var clusterData=eval(responseText);var html="";clusterData.each(function(theInfo){var singleData={avatar:theInfo.profile.image_file_name,login:theInfo.profile.user.login};var template='<div><img src="#{avatar}" width="32" height="32"/><div class="info"><h4>#{login}</h4><a href="/profile/#{login}" class="more">Profil anzeigen</a></div></div>';html+=new Template(template).evaluate(singleData)});var htmlElement=new Element("div",{className:""});htmlElement.innerHTML=html;$(id).insert(content);$(content).insert("<div>"+html+"</div>")}.bind(this)})},checkForReload:function(a){(this.ajax&&this.ajax.transport.abort());if(this.reloadTimeout){window.clearTimeout(this.reloadTimeout)}this.reloadTimeout=window.setTimeout(this.reload.curry(a).bind(this),1000);document.location="#geo:"+this.map.getCenter().toUrlValue()+","+this.map.getZoom()+","+this.map.getCurrentMapType().getUrlArg()},reload:function(a){var b=[this.map.getBounds().getSouthWest().lat(),this.map.getBounds().getSouthWest().lng(),this.map.getBounds().getNorthEast().lat(),this.map.getBounds().getNorthEast().lng()];var c="/map/load_markers?q="+b.join(",")+"&zoom="+this.map.getZoom();this.ajax=new Ajax.Request(c,{method:"get",onSuccess:function(d){if(a){this.clear()}this.addMarkers(d.responseText.evalJSON())}.bind(this)})},clear:function(){this.activeMarkers.values().invoke("remove");this.activeMarkers=$H()},addMarkers:function(a){a.each(function(c){if(Object.isArray(c)&&c.length>0){if(this.activeMarkers.get(c.first().profile.user_id)==undefined){var b=new GLatLng(c.first().profile.lat_rounded,c.first().profile.lng_rounded);this.addListMarker(b,c)}}else{if(this.activeMarkers.get(c.profile.user_id)==undefined){var b=new GLatLng(c.profile.lat_rounded,c.profile.lng_rounded);if(parseInt(c.profile.count)==1){this.addSingleMarker(b,c)}else{this.addClusterMarker(b,c)}}}}.bind(this))},addSingleMarker:function(a,c){var d=new GMarker(a,{icon:this.USER_ICON});this.activeMarkers.set(c.profile.user_id,d);this.map.addOverlay(d);d._type="single";var b="";b+=c.profile.user.zip_code;if(b.length>0){}if(c.profile.user.city!=null){}if(b.length>0){b+=", "}if(c.profile.user.country!=null){b+=c.profile.user.country}d._info={avatar:c.profile.image_file_name,login:c.profile.user.login,address:b}},addListMarker:function(a,b){var c=new ClusterMarker(a,{icon:this.MULTIPLE_ICON,label:b.length,offset:new GSize(-7,-10),map:this.map});c._type="list";info=[];b.each(function(e){var d="";d+=e.profile.user.zip_code;if(d.length>0){d+=", "}if(e.profile.user.country!=null){d+=e.profile.user.country}info.push({avatar:e.profile.image_file_name,login:e.profile.user.login,address:d})}.bind(this));this.activeMarkers.set(b.first().profile.user_id,c);c._info=info},addClusterMarker:function(a,b){var c={icon:this.MULTIPLE_ICON,label:b.profile.count,offset:new GSize(-7,-10),map:this.map};if(b.profile.count>100){Object.extend(c,{icon:this.MULTIPLE_ICON_BIG,className:"cluster-marker big"})}var d=new ClusterMarker(a,c);d._type="cluster";d._info={bounds:b.profile.bounds,count:b.profile.count,lat:b.profile.lat_rounded,lng:b.profile.lng_rounded};this.activeMarkers.set(b.profile.user_id,d)}});var SauspielMap={SEARCH_FIELD_LABEL:"Adresse eingeben",initialize:function(a){this.homeAddress=a||[0,0];this.homeButton=$("map_home");this.searchField=$("map_address_search");this.map=new Map("sauspiel_map",this.setOptions());this.submitSearch=$("map_search_submit");this.geoCoder=new GClientGeocoder();this.registerEvents();this.map.reload()},registerEvents:function(){this.searchField.setValue(this.SEARCH_FIELD_LABEL).defaultValueActsAsHint();this.searchField.defaultValueActsAsHint();this.submitSearch.observe("click",this.search.bind(this));this.searchField.observe("return:pressed",this.search.bind(this));if(this.homeButton){this.homeButton.observe("click",this.goHome.bind(this))}},search:function(a){if(a&&("stop" in a)){a.stop()}if(this.searchField.hasClassName("hint")){return}this.geoCoder.getLocations($F(this.searchField),this.showResult.bind(this))},showResult:function(b){if(!b||b.Status.code==602){alert("Die eingegebene Adresse gibts anscheinend nicht. Bitte überprüf die Adresse nochmal.");this.searchField.select();return}var a=new GLatLng(b.Placemark[0].Point.coordinates[1],b.Placemark[0].Point.coordinates[0]);this.map.map.setCenter(a,8+b.Placemark[0].AddressDetails.Accuracy);this.map.reload()},goHome:function(a){if(a&&("stop" in a)){a.stop()}if(!this.homeAddress){return}this.map.map.setCenter(new GLatLng(this.homeAddress[0],this.homeAddress[1]),15);this.map.reload()}};Object.extend(SauspielMap,{setOptions:function(){return{userIcon:{image:"/images/markers/single/marker.png",shadow:"/images/markers/single/shadow.png",shadowSize:new GSize(26,24),transparent:"/images/markers/transparent.png",printImage:"/images/markers/single/print-ie.gif",mozPrintImage:"/images/markers/single/print-ff.gif",iconsSize:new GSize(15,24),iconAnchor:new GPoint(7,12),infoWindowAnchor:new GPoint(3,16)},multipleIcon:{image:"/images/markers/medium/marker.png",shadow:"/images/markers/medium/shadow.png",shadowSize:new GSize(42,25),transparent:"/images/markers/transparent.png",printImage:"/images/markers/medium/print-ie.gif",mozPrintImage:"/images/markers/medium/print-ff.gif",iconSize:new GSize(27,28),iconAnchor:new GPoint(7,12),infoWindowAnchor:new GPoint(8,15)},multipleBigIcon:{image:"/images/markers/big/marker.png",shadow:"/images/markers/big/shadow.png",shadowSize:new GSize(50,28),transparent:"/images/markers/transparent.png",printImage:"/images/markers/big/print-ie.gif",mozPrintImage:"/images/markers/big/print-ff.gif",iconSize:new GSize(44,28),iconAnchor:new GPoint(7,12),infoWindowAnchor:new GPoint(18,20)}}}});GMarker.subclasses=[];var ClusterMarker=Class.create(GMarker,{initialize:function(){(this.initialized?this._addAsOverlay:this._initialize).apply(this,arguments)},_initialize:function(a,b){this.superClass=this.constructor.superclass;this.point=a;this.options=Object.extend({label:"",className:"cluster-marker",offset:new GSize(0,0),clickable:true,draggable:false,info:null},b||{});this.superClass.apply(this,[a,this.options]);this.initialized=true;if(this.options.map){this.options.map.addOverlay(this)}if(this.options.hidden){this.hide()}},_addAsOverlay:function(a){this.map=a;this.superClass.prototype.initialize.apply(this,arguments);if(!!this.options.label){this._createLabel()}},_createLabel:function(){this.div=new Element("div",{className:this.options.className}).update(this.options.label);this.div.setStyle({position:"absolute"});this.map.getPane(G_MAP_MARKER_PANE).appendChild(this.div);if(this.options.clickable){$w("click dblclick mousedown mouseup mouseover mouseout").each(function(a){GEvent.addDomListener(this.div,a,function(){GEvent.trigger(this,a)}.bind(this))}.bind(this));this.div.setStyle({cursor:"pointer"})}GEvent.bind(this,"drag",this,function(){this.setPoint(this.getLatLng())}.bind(this))},setPoint:function($super,a){$super(a);this.point=a;this._redrawDiv()},_redrawDiv:function(){if(this.div){var a=this.map.fromLatLngToDivPixel(this.point),b=GOverlay.getZIndex(this.point.lat());this.div.setStyle({left:(a.x+this.options.offset.width)+"px",top:(a.y+this.options.offset.height)+"px",zIndex:b+1})}},setLabel:function(a){this.options.label=a;if(!this.map){return}else{if(!this.div){this._createLabel()}}this.div.update(a)},redraw:function($super,a){$super(a);(a&&this._redrawDiv())},remove:function($super){if(this.div){GEvent.clearInstanceListeners(this.div);this.div.remove();this.div=null}$super()},cumulativeOffset:function(){var a=this.map.cumulativeOffset(),b=this.map.fromLatLngToDivPixel(this.getPoint());return{x:b.x+a.left,y:b.y+a.top}},infoIsOpened:function(){var a=this.map.getInfoWindow();return !a.isHidden()&&a.getPoint().equals(this.getPoint())},open:function(b,a){if(Object.isString(b)){b='<div class="infowindow">'+b+"</div>";this.openInfoWindowHtml(b,a)}else{b.addClassName("html");this.openInfoWindow(b,a)}},showTooltip:function(b,e){this._tooltipContainer=b;e=Object.extend({x:0,y:0},e||{});var c=this.cumulativeOffset(),a=b.up(),d=a.cumulativeOffset();b.setStyle({left:(c.x+e.x-d.left+a.offsetLeft)+"px",top:(c.y+e.y-d.top+a.offsetTop)+"px"}).show()},hideTooltip:function(){(this._tooltipContainer&&this._tooltipContainer.hide())},hide:function($super){(this.div&&this.div.hide());$super()},show:function($super){(this.div&&this.div.show());$super()},onDrag:function(){this.setPoint(this.getLatLng())}});