function ReallyDirections(B){this.mapElement=B.mapElement;this.dirElement=B.dirElement;this.loadingElement=B.loadingElement;this.addressInput=(typeof B.addressInput!="undefined")?B.addressInput:null;this.language=B.language;this.destinations=B.destinations;this.zoomLevel=(typeof B.zoomLevel!="undefined")?B.zoomLevel:15;if(typeof B.destination!="undefined"){this.destinations=[];this.destinations[0]=B.destination}this.geocoder=null;this.map=null;this.gdir=null;this.mgr=null;this.beginIcon;this.beginMarker=null;this.endIcon;this._replaceMarker=function(H,G){var F=new GMarker(H.getLatLng(),G);this.map.addOverlay(F);this.map.removeOverlay(H);GEvent.addListener(F,"click",function(){GEvent.trigger(H,"click")});return(F)};if(!GBrowserIsCompatible()){this.mapElement.innerHTML="<center><h3>"+ReallyDirections.texts[this.language].BROWSER_SUPPORT+"</h3></center>"}else{mapOptions={};this.map=new GMap2(this.mapElement,mapOptions);this.map.addControl(new ReallyZoomControl());this.map.addControl(new ReallyMapTypeControl());this.map.enableDoubleClickZoom();this.gdir=new GDirections(this.map);GEvent.addListener(this.gdir,"addoverlay",GEvent.callback(this,function(){if(this.beginMarker!=null){this.map.removeOverlay(this.beginMarker)}this.beginMarker=this._replaceMarker(this.gdir.getMarker(0),{icon:this.beginIcon});this.map.removeOverlay(this.gdir.getMarker(this.gdir.getNumRoutes()))}));GEvent.addListener(this.gdir,"error",GEvent.callback(this,function(){var F=this.gdir.getStatus().code;switch(F){case G_GEO_UNKNOWN_ADDRESS:alert(ReallyDirections.texts[this.language].LOCATION_NOT_FOUND);break;case G_GEO_BAD_REQUEST:alert("A directions request could not be successfully parsed.");break;case G_GEO_SERVER_ERROR:alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.");break;case G_GEO_MISSING_QUERY:alert("The HTTP q parameter was either missing or had no value. For geocoding requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.");break;case G_GEO_UNKNOWN_ADDRESS:alert("No corresponding geographic location could be found for the specified address. This may be due to the fact that the address is relatively new, or it may be incorrect.");break;case G_GEO_UNAVAILABLE_ADDRESS:alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.");break;case G_GEO_UNKNOWN_DIRECTIONS:alert(ReallyDirections.texts[this.language].ROUTE_NOT_FOUND);break;case G_GEO_BAD_KEY:alert("The given key is either invalid or does not match the domain for which it was given.");break;case G_GEO_TOO_MANY_QUERIES:alert("The given key has gone over the requests limit in the 24 hour period.");break;default:alert("An unknown error occurred.\nError code: "+F)}this._hideLoading()}));this.dirSummary=null;this.dirSteps=null;GEvent.addListener(this.gdir,"load",GEvent.callback(this,function(){while(this.dirElement.hasChildNodes()){this.dirElement.removeChild(this.dirElement.firstChild)}var H=document.createElement("div");H.innerHTML=this.gdir.getSummaryHtml();var O=document.createElement("table");var F=document.createElement("tbody");var P=this.gdir.getNumRoutes();for(var M=0;M<P;M++){var R=this.gdir.getRoute(M);var K=R.getNumSteps();for(var L=0;L<K;L++){var J=R.getStep(L);var G=document.createElement("tr");GEvent.addDomListener(G,"click",GEvent.callbackArgs(this,function(S){if(this.map.getExtInfoWindow()!=null){this.map.closeExtInfoWindow()}this.map.showMapBlowup(S.getLatLng())},J));var I=document.createElement("td");I.className="dirstepidx";I.innerHTML=(""+(L+1)+".");var Q=document.createElement("td");Q.className="dirstepdesc";Q.innerHTML=('<a href="#" onclick="return false;">'+J.getDescriptionHtml()+"</a>");var N=document.createElement("td");N.className="dirstepdist";N.innerHTML=(J.getDistance().html);G.appendChild(I);G.appendChild(Q);G.appendChild(N);F.appendChild(G)}}O.appendChild(F);this.dirElement.appendChild(H);this.dirElement.appendChild(O);this._hideLoading()}));this.map.markers=[];var E=GEvent.callback(this,function(G,F){if(F==0){this.map.setCenter(G,this.zoomLevel);this.beginIcon=new GIcon();this.beginIcon.image="/themes/_default/widgets/location/pics/img_gm_mark_startpoint.png";this.beginIcon.iconSize=new GSize(28,28);this.beginIcon.iconAnchor=new GPoint(14,14);this.beginIcon.infoWindowAnchor=new GPoint(14,14);this.endIcon=new GIcon();this.endIcon.image="/themes/_default/widgets/location/pics/img_gm_mark_endpoint.png";this.endIcon.iconSize=new GSize(28,28);this.endIcon.iconAnchor=new GPoint(14,14);this.endIcon.infoWindowAnchor=new GPoint(0,-24)}this.map.markers[F]=new GMarker(G,{icon:this.endIcon});GEvent.addListener(this.map.markers[F],"click",GEvent.callback(this,function(){this.map.markers[F].openExtInfoWindow(this.map,"reallyWindow",this.destinations[F].dialog,{borderSize:12,beakOffset:-2,paddingX:5,paddingY:5,width:200});this.currentDestination=this.destinations[F]}));this.map.addOverlay(this.map.markers[F]);if(F==0){GEvent.trigger(this.map.markers[F],"click");this.currentDestination=this.destinations[F]}});this.geocoder=new GClientGeocoder();this.geocoder.setBaseCountryCode("fi");_mHL="fi";_mHost="http://maps.google.fi";nDestinations=this.destinations.length;for(var C=0;C<nDestinations;C++){this.destination=this.destinations[C];if(typeof this.destination!="object"){continue}if(!this.destination.lat||!this.destination.lon){var D=this.geocoder;var A=this.destination.address;(function(){var F=C;D.getLatLng(A,function(G){if(!G){alert("Osoitetta '"+A+"' ei löytynyt")}else{E(G,F)}})})()}else{E(new GLatLng(this.destination.lat,this.destination.lon),C)}}}}ReallyDirections.prototype={};ReallyDirections.prototype._showLoading=function(){if(this.loadingElement==null){return }this.loadingElement.style.visibility="visible"};ReallyDirections.prototype._hideLoading=function(){if(this.loadingElement==null){return }this.loadingElement.style.visibility="hidden"};ReallyDirections.prototype.setFromAddress=function(A,B){this._showLoading();if(!/^.*,.*,.*$/.test(A)){A+=", Suomi"}this.geocoder.getLocations(A,GEvent.callback(this,function(D){if(!D||D.Status.code!=200){}else{switch(D.Placemark.length){case 0:this._hideLoading();alert(ReallyDirections.texts[this.language].LOCATION_NOT_FOUND);return ;case 1:var C="from: "+A+" to: "+this.currentDestination.address;if(this.currentDestination.lat&&this.currentDestination.lon){C="from: "+A+" to: "+this.currentDestination.lat+", "+this.currentDestination.lon}this.gdir.load(C,{locale:this.language,getSteps:true});break;default:this._hideLoading();alert(ReallyDirections.texts[this.language].FOUND_MANY);break}}}))};ReallyDirections.texts={fi:{LANG_CUSTOMERSERVICE:"Asiakaspalvelu",BROWSER_SUPPORT:"Käyttämäsi selain ei ole yhteensopiva Google Mapsin kanssa.",LOCATION_NOT_FOUND:"Antamaasi lähtöosoitetta ei löytynyt. Osoite voi olla suhteellisen uusi tai virheellinen",ROUTE_NOT_FOUND:"Reittiä ei löytynyt.",FOUND_MANY:"Antamallasi merkkijonolla löytyi useita osoitteita. Tarkenna hakua nähdäksesi reitin."},en:{LANG_CUSTOMERSERVICE:"Customer service",BROWSER_SUPPORT:"Your browser does not support Google Maps.",LOCATION_NOT_FOUND:"No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.",ROUTE_NOT_FOUND:"The GDirections object could not compute directions between the points mentioned in the query. This is usually because there is no route available between the two points, or because we do not have data for routing in that region.",FOUND_MANY:"Search query you gave matches multiple addresses. Please refine your query."}};