
function initMap2(){}
function initMap(mode,pageType,mapElemId){mapModel('boundsSet',false);mapModel('maxzoom',13);mapModel('pageType',pageType);mapModel('mapMode',mode);if(mapElemId==null){mapElemId='map';}
var map=new RMap(mapElemId,mode);mapModel('mapObject',map);if(fromModel('hasMapTypeControl')){map.addControl(new RMapTypeControl());}
if(fromModel('hasMapPanZoomButtonControl')){map.addControl(new RSmallMapControl());}
reconfigureMap();}
function reconfigureMap(startCity,endCity){if(mapModel('mapObject')){debug('reconfigure');clearMap();self.onMapLoaded(mapModel('pageType'));if(mapModel('boundsSet')){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));}
try{var map=mapModel('mapObject');map.showMap();}catch(e){debugError('reconfigureMap: '+e);}
if(startCity||endCity){startCity=isEmpty(startCity)?'?':startCity;endCity=isEmpty(endCity)?'?':endCity;App.findBy('#mapRoundbox .inner h1').html(startCity+' - '+endCity);}}}
function reloadHotelList(){alert('now reloadHotelList();')}
function clearMap(){var map=mapModel('mapObject');if(map){map.clearOverlays();mapModel('bounds',new RCoordBounds());map.setCenter(new RCoord(51,10),5);}}
self.onMapLoaded=function(type){MapToolTip.init();mapModel('maptype',type);switch(type){case"home":loadSpaceIcons();loadRouteIcons();mapModel('activeLayer',null);Markers.showMobile();App.findBy('#fahrtenlink').click(Markers.showMobile);App.findBy('#raumlink').click(Markers.showSpace);App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;case"greencompany":loadSpaceIcons();loadRouteIcons();mapModel('activeLayer',null);Markers.showMobile();Markers.showCompanies();App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;case"mobileDetail":loadRouteIcons();Markers.showMobile();break;case"spaceDetail":loadSpaceIcons();Markers.showSpace();App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;case"myCommodities":loadSpaceIcons();loadRouteIcons();Markers.showSpace();Markers.showMobile();App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;case"bookmarks":loadSpaceIcons();loadRouteIcons();mapModel('maptype',"myCommodities");Markers.showSpace();Markers.showMobile();App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;case"searchresult":loadSpaceIcons();loadRouteIcons();mapModel('maptype',"myCommodities");Markers.showSpace();Markers.showMobile();var umkreis=fromModel('umkreisJSON');if(umkreis['start'])Markers.showUmkreis(umkreis['start'],'#65b84a',1,1.0,'#65b84a',.4);if(umkreis['ziel'])Markers.showUmkreis(umkreis['ziel'],'#fe7e71',1,1.0,'#fe7e71',.4);App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;case"profile":loadSpaceIcons();loadRouteIcons();mapModel('maptype',"myCommodities");Markers.showSpace();Markers.showMobile();Markers.showHome(fromModel('homeAddress'),true);App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;case"airtransfer":loadSpaceIcons();Markers.showSpace();App.findBy('#resetZoom').click(function(){setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));});break;default:break;}}
self.MapToolTip=new function(){this.init=function(){if(!this.jDiv){this.jDiv=jQuery('<div id="maptooltip">');this.on=0;this.mouseIsInside=false;this.mouseIsOnIcon=false;this.move=0;$('body').append(this.jDiv);App.findBy('div.gmap').bind('mousemove',this.updPos);}}
this.show=function(tooltip){MapToolTip.mouseIsOnIcon=true;MapToolTip.jDiv.html(tooltip);if($.fn.bgiframe)
MapToolTip.jDiv.bgiframe();MapToolTip.on=1;MapToolTip.jDiv.show();MapToolTip.jDiv.hover(function(){MapToolTip.mouseIsInside=true;},function(){MapToolTip.mouseIsInside=false;MapToolTip.hide();});};this.updPos=function(event){if(!MapToolTip.on)return;var p=jQuery.iUtil.getPointer(event);if(MapToolTip.move==1||MapToolTip.on!=2){MapToolTip.jDiv.css({left:p.x+fromModel('mapTooltipX')+'px',top:p.y+3+'px'});}
if(MapToolTip.on==2)return;MapToolTip.jDiv.fadeIn(100);MapToolTip.on=2;};this.hide=function(event){MapToolTip.mouseIsOnIcon=false;debug('hide event');window.setTimeout(function(){if(!MapToolTip.mouseIsInside&&!MapToolTip.mouseIsOnIcon){debug('not inside -> hide');MapToolTip.jDiv.fadeOut(500);MapToolTip.on=0;}},500);};};self.Markers=new function(){this.makeActive=function(type){switch(type){case"space":mapModel('activeLayer',"space");App.findBy('#fahrtenlink').css('color','#0033CC');App.findBy('#raumlink').css('color','#595959');break;case"mobile":mapModel('activeLayer',"routes");App.findBy('#fahrtenlink').css('color','#595959');App.findBy('#raumlink').css('color','#0033CC');break;}}
this.showSpace=function(){mapModel('raummarker',[]);var spaceAds=fromModel('spaceAdsJSON');for(advertid in spaceAds){Markers.addSpaceMarker(advertid);}}
this.showCompanies=function(){var companyInfosJSON=fromModel('companyInfosJSON');if(companyInfosJSON){for(loc in companyInfosJSON["locations"]){Markers.addCompanyMarker(companyInfosJSON["locations"][loc]);}}}
this.showMobile=function(){mapModel('startmarker',{});mapModel('zielmarker',{});mapModel('polyline',{});try{for(advertid in fromModel('mobileAdsJSON')){Markers.addRoute(advertid);}}catch(e){debugError(e);}}
this.showHome=function(address,showinfo){if(address.city!=''){var geocoder=new RClientGeocoder();var addressString=address.country+' '+address.zip+' '+address.city;if(mapModel('mapMode')=='flash'){addressString=address.city+' Germany';}
geocoder.getLatLng(addressString,function(point){Markers.addHomeMarker(point,showinfo,address);});}}
this.addHomeMarker=function(point,showinfo,address){if(!point){}else{var homemarker=new RMarker(point,raumicons["home"]);if(showinfo){var addressName=address.name?'<tr><td>'+address.name+'</td></tr>':'';homemarker.tooltip='<table>'+addressName+'<tr><td>'+address.country+', '+address.zip+' '+address.city+'</td></tr><table>';REvent.addListener(homemarker,'mouseover',function(){MapToolTip.show(homemarker.tooltip);});REvent.addListener(homemarker,'mouseout',MapToolTip.hide);REvent.addListener(homemarker,'mousemove',MapToolTip.updPos);}
mapModel('mapObject').addOverlay(homemarker);extendBounds(point,true);setMapToBounds(mapModel('bounds'),mapModel('maxzoom'));}}
this.addSpaceMarker=function(advertid){var raummarker=mapModel('raummarker');debug('addSpaceMarker: '+advertid);if(advertid>0){var space=fromModel('spaceAdsJSON')[advertid];var pos=new RCoord(space.pos.lat,space.pos.lng);raummarker[advertid]=new RMarker(pos,raumicons[space.icon]);extendBounds(pos,false);var entryImage=space.image==''?'':'<img src="'+ctx+space.image+'"/>';raummarker[advertid].tooltip="<table><tr><td>"+entryImage+"</td><td valign='top'>"+space.text+"</td></tr></table>";raummarker[advertid].url=space.url;if(mapModel('maptype')=="home"||mapModel('maptype')=="myCommodities"){REvent.addListener(raummarker[advertid],'click',function(){jumpTo(raummarker[advertid].url);});var row=App.findBy("#tr_"+advertid);row.mouseover(function(){hoverSpace(advertid,"on")});row.mouseout(function(){hoverSpace(advertid,"off")});}
if(mapModel('maptype')=="airtransfer"){raummarker[advertid].iata=space.iata;REvent.addListener(raummarker[advertid],'click',function(){jumpTo(raummarker[advertid].url);});var row=App.findBy("#tr_"+raummarker[advertid].iata);row.mouseover(function(){hoverSpace(advertid,"on")});row.mouseout(function(){hoverSpace(advertid,"off")});}
REvent.addListener(raummarker[advertid],'mouseover',function(){MapToolTip.show(raummarker[advertid].tooltip);});REvent.addListener(raummarker[advertid],'mouseout',MapToolTip.hide);REvent.addListener(raummarker[advertid],'mousemove',MapToolTip.updPos);mapModel('mapObject').addOverlay(raummarker[advertid]);}}
this.addCompanyMarker=function(loc){if(loc.lat&&loc.lng){var point=new RCoord(loc.lat,loc.lng);extendBounds(point,true);var mrk=new RMarker(point,raumicons["fabrik"]);var image='<tr><td><img src="'+ctx+'/images/'+layoutTheme+'/company_'+loc.zip+'.jpg" /></td></tr>';var title='<p><b>'+loc.title+'</b>'+(loc.name?'<br />'+loc.name:'')+'</p>';var address='<p>'+(loc.street?''+loc.street+' '+loc.streetNr+'<br />':'')+loc.zip+' '+loc.city+'</p>';var phone='<p>'+(loc.phone?'Tel. '+loc.phone:'')+(loc.fax?'<br />Fax '+loc.fax:'')+'</p>';var www='<p>'+(loc.url?''+loc.url:'')+(loc.email?'<br />'+loc.email:'')+'</p>';mrk.tooltip='<table>'+image+'<tr><td>'+title+address+phone+www+'</td></tr></table>';REvent.addListener(mrk,'mouseover',function(){MapToolTip.show(mrk.tooltip);});REvent.addListener(mrk,'mouseout',MapToolTip.hide);REvent.addListener(mrk,'mousemove',MapToolTip.updPos);mapModel('mapObject').addOverlay(mrk);}}
this.addRoute=function(advertid){var route=fromModel('mobileAdsJSON')[advertid];var startmarker=mapModel('startmarker');var zielmarker=mapModel('zielmarker');var polyline=mapModel('polyline');if(route.ziel.lat&&route.ziel.lng&&route.start.lat&&route.start.lng){var zielpos=new RCoord(route.ziel.lat,route.ziel.lng);zielmarker[advertid]=new RMarker(zielpos,routeicons["ziel"]);var startpos=new RCoord(route.start.lat,route.start.lng);startmarker[advertid]=new RMarker(startpos,routeicons["start"]);extendBounds(zielpos);extendBounds(startpos);var pts=[];pts.push(startpos);var stops=[]
for(i=0;i<route.stopovers.length;i++){stops[i]=new RCoord(route.stopovers[i].lat,route.stopovers[i].lng);pts.push(stops[i]);extendBounds(stops[i]);}
pts.push(zielpos);polyline[advertid]=new RPolyline(pts,"#0000FF",3,0.7);var entryImage=route.image==''?'':'<img src="'+route.image+'" width=43 height=43 />';var routeDescription=route.text;startmarker[advertid].url=route.url;if(mapModel('maptype')=="home"||mapModel('maptype')=="myCommodities"){REvent.addListener(startmarker[advertid],'click',function(){jumpTo(startmarker[advertid].url);});REvent.addListener(zielmarker[advertid],'click',function(){jumpTo(startmarker[advertid].url);});var row=App.findBy("#tr_"+advertid);row.mouseover(function(){hoverMobile(advertid,"on");});row.mouseout(function(){hoverMobile(advertid,"off");});routeDescription=routeDescription+"<a href='"+route.url+"'>Details...</a>"}
startmarker[advertid].tooltip="<table><tr><td>"+entryImage+"</td><td valign='top'>"+routeDescription+"</td></tr></table>";REvent.addListener(startmarker[advertid],'mouseover',function(){MapToolTip.show(startmarker[advertid].tooltip);});REvent.addListener(startmarker[advertid],'mouseout',MapToolTip.hide);REvent.addListener(startmarker[advertid],'mousemove',MapToolTip.updPos);REvent.addListener(zielmarker[advertid],'mouseover',function(){MapToolTip.show(startmarker[advertid].tooltip);});REvent.addListener(zielmarker[advertid],'mouseout',MapToolTip.hide);REvent.addListener(zielmarker[advertid],'mousemove',MapToolTip.updPos);mapModel('mapObject').addOverlay(startmarker[advertid]);mapModel('mapObject').addOverlay(zielmarker[advertid]);mapModel('mapObject').addOverlay(polyline[advertid]);}}
this.showUmkreis=function(kreis,strokeColor,strokeWidth,strokeOpacity,fillColor,fillOpacity){var r2d=180/Math.PI;var Clat=kreis.radius*r2d/6371;var Clng=Clat/Math.cos(kreis.pos.lat/r2d);var Cpoints=[];for(var i=0;i<33;i++){var theta=Math.PI*(i/16);Cy=kreis.pos.lat+(Clat*Math.sin(theta));Cx=kreis.pos.lng+(Clng*Math.cos(theta));var P=new RPoint(Cx,Cy);Cpoints.push(P);}
var polygon=new RPolygon(Cpoints,strokeColor,strokeWidth,strokeOpacity,fillColor,fillOpacity);mapModel('mapObject').addOverlay(polygon);}}
function hoverSpace(id,status){if((mapModel('activeLayer')||mapModel('maptype')=="myCommodities")&&raummarker[id]){if(mapModel('activeLayer')=="space"||mapModel('maptype')=="myCommodities"){if(status=="on"){raummarker[id].setImage(iconurl["raum_aktiv"]);for(advertid in fromModel('spaceAdsJSON')){if(advertid!=id){raummarker[advertid].hide();}}}
if(status=="off"){raummarker[id].setImage(iconurl[spaceAds[id].icon]);for(advertid in fromModel('spaceAdsJSON')){if(advertid!=id){raummarker[advertid].show();}}}}}}
function hoverMobile(id,status){var startmarker=mapModel('startmarker');var zielmarker=mapModel('zielmarker');var polyline=mapModel('polyline');if((mapModel('activeLayer')||mapModel('maptype')=="myCommodities"||mapModel('maptype')=="home")&&startmarker[id]&&zielmarker[id]){if(mapModel('activeLayer')=="routes"||mapModel('maptype')=="myCommodities"||mapModel('maptype')=="home"){if(status=="on"){for(advertid in fromModel('mobileAdsJSON')){if(advertid!=id){if(polyline[advertid])
polyline[advertid].hide();if(startmarker[advertid])
startmarker[advertid].hide();if(zielmarker[advertid])
zielmarker[advertid].hide();}}
startmarker[id].setImage(ctx+"/images/mapicons/start_hover.png");zielmarker[id].setImage(ctx+"/images/mapicons/ziel_hover.png");polyline[id].setStrokeStyle({color:"#FF0000"});}
if(status=="off"){for(advertid in fromModel('mobileAdsJSON')){if(advertid!=id){polyline[advertid].show();startmarker[advertid].show();zielmarker[advertid].show();}}
startmarker[id].setImage(ctx+"/images/mapicons/start.png");zielmarker[id].setImage(ctx+"/images/mapicons/ziel.png");polyline[id].setStrokeStyle({color:"#0000FF"});}}}}
function resetMap(type){var map=mapModel('mapObject')
switch(type){case"DE":map.setCenter(new RCoord(51,10),5);break;default:map.setCenter(new RCoord(51,10),5);}}
function extendBounds(point,setCenter){var map=mapModel('mapObject');if(!mapModel('boundsSet'))
mapModel('boundsSet',true);if(mapModel('bounds')){mapModel('bounds').extend(point);}else if(setCenter){map.setCenter(point,mapModel('maxzoom'));}}
function setMapToBounds(mapbounds,maxZoom,incZoom){debug('setMapToBounds: '+maxZoom);var map=mapModel('mapObject');if(!incZoom){incZoom=0;}
if(mapbounds){var zoom=Math.min(map.getBoundsZoomLevel(mapbounds),maxZoom)
var center=mapbounds.getCenter();map.setCenter(center,zoom+incZoom);}}
function extendByBounds(withBounds,boundsToExtend){if(!boundsToExtend){boundsToExtend=new RCoordBounds();}
if(withBounds){boundsToExtend.extend(withBounds.getNorthEast());boundsToExtend.extend(withBounds.getSouthWest());}
return boundsToExtend;}
function showBigMap(mapId,url){var map=mapModel('mapObject');showDialog('Vergr&ouml;&szlig;erter Kartenausschnitt',url);map.checkResize();map.setCenter(map.getCenter());}
function mapModel(key,value){if(value!=undefined){toModel(key,value,App.findBy('#map'));}
return fromModel(key,App.findBy('#map'));}
var iconurl=[];var raumicons=[];var routeicons=[];function loadSpaceIcons(){var iconpath=ctx+"/images/mapicons";iconurl["raumschatten"]=iconpath+"/raum_shadow.png";iconurl["default"]=iconpath+"/raum_inaktiv.png";iconurl["storage"]=iconpath+"/lagerraum_inaktiv.png";iconurl["living"]=iconpath+"/unterkunft_inaktiv.png";iconurl["parking"]=iconpath+"/parkplatz_inaktiv.png";iconurl["event"]=iconpath+"/partyraum_inaktiv.png";iconurl["work"]=iconpath+"/arbeitsraum_inaktiv.png";iconurl["home"]=iconpath+"/wohnort_inaktiv.png";iconurl["raum_aktiv"]=iconpath+"/raum_aktiv.png";iconurl["airport"]=iconpath+"/flughafen_inaktiv.png";iconurl["airport_aktiv"]=iconpath+"/flughafen_aktiv.png";iconurl["fabrik"]=iconpath+"/fabrik_inaktiv.png";iconurl["hotel"]=iconpath+"/map_hotels.png";var raumIcon=new RIcon(R_DEFAULT_ICON);raumIcon.image=iconurl["default"];raumIcon.shadow=iconurl["raumschatten"];raumIcon.iconSize=new RSize(24,24);raumIcon.shadowSize=new RSize(37,24);raumIcon.iconAnchor=new RPoint(12,23);raumIcon.infoWindowAnchor=new RPoint(12,23);raumicons["default"]=new RIcon(raumIcon);raumicons["living"]=new RIcon(raumIcon,iconurl["living"]);raumicons["parking"]=new RIcon(raumIcon,iconurl["parking"]);raumicons["storage"]=new RIcon(raumIcon,iconurl["storage"]);raumicons["event"]=new RIcon(raumIcon,iconurl["event"]);raumicons["work"]=new RIcon(raumIcon,iconurl["work"]);raumicons["home"]=new RIcon(raumIcon,iconurl["home"]);raumicons["raum_aktiv"]=new RIcon(raumIcon,iconurl["raum_aktiv"]);raumicons["airport"]=new RIcon(raumIcon,iconurl["airport"]);raumicons["airport_aktiv"]=new RIcon(raumIcon,iconurl["airport_aktiv"]);raumicons["fabrik"]=new RIcon(raumIcon,iconurl["fabrik"]);raumicons["hotel"]=new RIcon(raumIcon,iconurl["hotel"]);}
function loadRouteIcons(){var iconurl_start=ctx+"/images/mapicons/start.png";var iconurl_end=ctx+"/images/mapicons/ziel.png";var routeIcon=new RIcon(R_DEFAULT_ICON);routeIcon.image=ctx+"/images/mapicons/start.png";routeIcon.shadow=ctx+"/images/mapicons/start_shadow.png";routeIcon.iconSize=new RSize(20,30);routeIcon.shadowSize=new RSize(36,30);routeIcon.iconAnchor=new RPoint(10,29);routeIcon.infoWindowAnchor=new RPoint(10,29);routeicons["start"]=new RIcon(routeIcon,iconurl_start);routeicons["ziel"]=new RIcon(routeIcon,iconurl_end);}
var REvent=null;var R_DEFAULT_ICON=null;function RMap(mapElemId,mode){debug("init RMAP("+mapElemId+") with mode: "+mode);if(mode=='ajax'){this._adapter=new GoogleMapAdapter(mapElemId);}else if(mode=='flash'){this._adapter=new FlashMapAdapter(mapElemId);}else if(mode=='static'){this._adapter=new StaticMapAdapter(mapElemId);}}
function RMap_checkResize(){this._adapter.checkResize();}
function RMap_setZoom(zoomLevel){this._adapter.setZoom(zoomLevel);}
function RMap_addOverlay(overlay){this._adapter.addOverlay(overlay);}
function RMap_addControl(control){this._adapter.addControl(control);}
function RMap_addListener(listener,eventName,callback){this._adapter.addListener(listener,eventName,callback);}
function RMap_setCenter(coord,zoomLevel){this._adapter.setCenter(coord,zoomLevel);}
function RMap_setMapType(mapType){this._adapter.setMapType(mapType);}
function RMap_clearOverlays(){this._adapter.clearOverlays();}
function RMap_getBoundsZoomLevel(bounds){return this._adapter.getBoundsZoomLevel(bounds);}
function RMap_showMap(){return this._adapter.showMap();}
RMap.prototype.addControl=RMap_addControl;RMap.prototype.setCenter=RMap_setCenter;RMap.prototype.addOverlay=RMap_addOverlay;RMap.prototype.clearOverlays=RMap_clearOverlays;RMap.prototype.addListener=RMap_addListener;RMap.prototype.checkResize=RMap_checkResize;RMap.prototype.setZoom=RMap_setZoom;RMap.prototype.getBoundsZoomLevel=RMap_getBoundsZoomLevel;RMap.prototype.setMapType=RMap_setMapType;RMap.prototype.showMap=RMap_showMap;