
var Map={}
Map.Poi=Class.create({initialize:function(element,lat,lng,zoom,options){this.element=$(element);this.options=options;this.heightTarget=0;this.map=new GMap2(this.element);this.geocoder=new GClientGeocoder();this.marker_manager=null;this.poi_icon=new GIcon();this.directions=null;this.markers=new Array();this.options.typecontrol=this.options.typecontrol?true:false;this.options.zoomcontrol=this.options.zoomcontrol?true:false;this.options.iconwidth=this.options.iconwidth||17;this.options.iconheight=this.options.iconheight||21;this.options.anchorx=this.options.anchorx||8;this.options.anchory=this.options.anchory||21;this.map.setCenter(new GLatLng(lat,lng),zoom);if(this.options.typecontrol){this.map.addControl(new GMapTypeControl);}
if(this.options.zoomcontrol){this.map.addControl(new GSmallZoomControl);}
this.poi_icon.iconSize=new GSize(this.options.iconwidth,this.options.iconheight);this.poi_icon.iconAnchor=new GPoint(this.options.anchorx,this.options.anchory);Event.observe(window,'unload',this.cleanup.bindAsEventListener(this));},zoomIn:function(){this.map.zoomIn();return false;},zoomOut:function(){this.map.zoomOut();return false;},blow:function(){var height=this.element.getHeight();if(height>=350)return false;this.heightTarget=height/100*125;new Effect.BlindDown(this.element,{scaleFrom:100,scaleTo:125,afterFinish:FixHeight});return false;},shrink:function(){var height=this.element.getHeight();if(height<=300)return false;this.heightTarget=height/100*75;new Effect.BlindDown(this.element,{scaleFrom:100,scaleTo:75,afterFinish:FixHeight});return false;},addDragMarker:function(Icon,Lat,Lng,LatField,LngField){var tmp_icon=new GIcon(this.poi_icon);tmp_icon.image=Icon;var marker_options={icon:tmp_icon,draggable:true};var marker=new GMarker(new GLatLng(Lat,Lng),marker_options);marker.latfield=LatField;marker.lngfield=LngField;GEvent.addListener(marker,"dragend",function(){$(this.latfield).value=this.getLatLng().lat();$(this.lngfield).value=this.getLatLng().lng();});this.map.addOverlay(marker);},addPoi:function(Icon,Lat,Lng,Url,Title){if(this.marker_manager==null){this.marker_manager=new MarkerManager(this.map,{trackMarkers:true});this.marker_manager.refresh();}
var tmp_icon=new GIcon(this.poi_icon);tmp_icon.image=Icon;var marker_options={icon:tmp_icon};var tmp=new GMarker(new GLatLng(Lat,Lng),marker_options);var tooltip=new Tooltip(tmp,Title,4);tmp.tooltip=tooltip;tmp.url=Url;tmp.map=this.map;this.map.addOverlay(tooltip);GEvent.addListener(tmp,"mouseover",function(){this.tooltip.show();});GEvent.addListener(tmp,"mouseout",function(){this.tooltip.hide();});if(Url!=''){GEvent.addListener(tmp,"mouseup",function(){document.location.href=this.url;});}
this.markers[Url]=tmp;this.marker_manager.addMarker(tmp,0);},togglePoi:function(Link,Pois){for(i=0;i<Pois.length;i++){if(this.markers[Pois[i]['url']]){this.marker_manager.removeMarker(this.markers[Pois[i]['url']]);this.markers[Pois[i]['url']]=null;}else{this.addPoi(Pois[i]['icon'],Pois[i]['lat'],Pois[i]['lng'],Pois[i]['url'],Pois[i]['title']);}}
var img=Link.getElementsByTagName('img');if(img[0]){if(Element.visible(img[0])){Element.hide(img[0]);this.storeVisibility(Link.id,false);}else{Element.show(img[0]);this.storeVisibility(Link.id,true);}}
return false;},storeVisibility:function(poi_type,visible){var visibility=this.loadVisibility();if(visible){var is_in=false;for(var i=0;i<visibility.length;i++){if(poi_type==visibility[i])is_in=true;}
if(!is_in)visibility.push(poi_type);}else{var visibility_result=new Array();for(var i=0;i<visibility.length;i++){if(poi_type!=visibility[i])visibility_result.push(visibility[i]);}
visibility=visibility_result;}
var date=new Date();date.setTime(date.getTime()+(24*60*60*1000));var expires="; expires="+date.toGMTString();document.cookie="rheinmainmap="+visibility.join(',')+expires+"; path=/";return visibility;},loadVisibility:function(value){var name_eq="rheinmainmap=";var visibility_str='';var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(name_eq)==0)visibility_str=c.substring(name_eq.length,c.length);}
return visibility_str.split(',');},initDirections:function(Directions,Summary,Description){this.directions=new GDirections(this.map);this.directions.panel_element=Directions;this.directions.map_element=this.element;this.directions.summary_element=Summary;this.directions.description_element=Description;this.directions.parent=this;this.directions.panel_element.style.top=Element.cumulativeOffset(this.directions.map_element).top+'px';var panel_width=Element.getWidth(this.directions.panel_element);var map_width=Element.getWidth(this.directions.map_element);if(!this.directions.panel_element.visible()){if(!document.all){this.directions.map_element.style.width=(map_width-(panel_width+1))+'px';this.directions.map_element.style.marginLeft=panel_width-1+'px';}
this.directions.panel_element.style.display='block';this.map.checkResize();}else{if(!document.all){this.directions.map_element.style.width=(map_width+panel_width-5)+'px';this.directions.map_element.style.marginLeft='0';}
this.directions.panel_element.style.display='none';this.map.checkResize();}
GEvent.addListener(this.directions,"load",this.directionsLoad);GEvent.addListener(this.directions,"error",this.directionsError);return false;},getDirections:function(From,To){this.directions.clear();this.directions.load("from: "+From+" to: "+To,{"locale":'de',"getSteps":true});return false;},directionsLoad:function(){this.getMarker(0).getIcon().image='/fnp/pics/marker/a.gif';this.getMarker(0).getIcon().iconSize=this.parent.poi_icon.iconSize;this.getMarker(0).getIcon().iconAnchor=this.parent.poi_icon.iconAnchor;this.getMarker(0).getIcon().shadow='';this.getMarker(1).getIcon().image='/fnp/pics/marker/b.gif';this.getMarker(1).getIcon().iconSize=this.parent.poi_icon.iconSize;this.getMarker(1).getIcon().iconAnchor=this.parent.poi_icon.iconAnchor;this.getMarker(1).getIcon().shadow='';this.getPolyline().setStrokeStyle({"color":'#d60027',"opacity":0.8});this.summary_element.innerHTML=this.getSummaryHtml()+' <a href="#" onclick="window.print(); return false;">Drucken</a>';var description='<dl class="result">';for(var i=0;i<this.getRoute(0).getNumSteps();i++){description+='<dt'+(i%2==0?' class="hot"':'')+'>'+this.getRoute(0).getStep(i).getDescriptionHtml()+'</dt><dd>'+this.getRoute(0).getStep(i).getDistance().html+'</dd>';}
this.description_element.innerHTML=description+'</dl>';},directionsError:function(){this.summary_element.innerHTML='Die Route konnte nicht berechnet werden, da Abfahrt- oder Zielort nicht gefunden wurde.';this.description_element.innerHTML='';},directionsHide:function(){},cleanup:function(){GUnload();}});function Tooltip(marker,text,padding){this.marker_=marker;this.text_=text;this.padding_=padding;}
Tooltip.prototype=new GOverlay();Tooltip.prototype.initialize=function(map){var div=document.createElement("div");div.appendChild(document.createTextNode(this.text_));div.className='tooltip';div.style.position='absolute';div.style.visibility='hidden';map.getPane(G_MAP_FLOAT_PANE).appendChild(div);this.map_=map;this.div_=div;}
Tooltip.prototype.remove=function(){this.div_.parentNode.removeChild(this.div_);}
Tooltip.prototype.copy=function(){return new Tooltip(this.marker_,this.text_,this.padding_);}
Tooltip.prototype.redraw=function(force){if(!force)return;var markerPos=this.map_.fromLatLngToDivPixel(this.marker_.getPoint());var iconAnchor=this.marker_.getIcon().iconAnchor;var xPos=Math.round(markerPos.x-this.div_.clientWidth/2);var yPos=markerPos.y-iconAnchor.y-this.div_.clientHeight-this.padding_;this.div_.style.top=yPos+'px';this.div_.style.left=xPos+'px';}
Tooltip.prototype.show=function(){this.div_.style.visibility='visible';}
Tooltip.prototype.hide=function(){this.div_.style.visibility='hidden';}