var DitMap=Class.create({map:null,dirObj:null,directionsInfoDiv:null,geocoder:null,options:{id:'default',map_element:'map',directions_element:'directions_info',address:'',zoom:9,infowindow:'',marker_title:'',directions:true,language:'uk',keys:null,traffic:true,strings:{'From':'From','To':'To','Show_route':'Click to view the route details','Search_route':'Find route!'}},initialize:function(options){Object.extend(this.options,options||{});if(this.options.map_element!=null){if(this.options){if(this.options.language){if(this.options.language=='uk'){this.options.language=='en'}else{this.options.strings=DitMap.Language[this.options.language].strings}}this.options.keys=DitMap.Keys}Event.observe(window,'load',this.load.bind(this),false);Event.observe(window,'unload',this.unload.bind(this),false)}},tr:function(str){return this.options&&this.options.strings?this.options.strings[str]||str:str},getKey:function(){var host=window.location.hostname;return this.options&&this.options.keys?this.options.keys[host]||host:host},setDirections:function(fromAddress,toAddress){this.fromAddress=fromAddress;this.toAddress=toAddress;this.dirObj=new GDirections(this.map);this.dirObj.load("from: "+this.fromAddress+" to: "+this.toAddress,{getSteps:true});GEvent.addListener(this.dirObj,"load",this.onDirectionsLoad.bind(this))},onDirectionsLoad:function(){var html='';var status=this.dirObj.getStatus();var bounds=this.dirObj.getBounds();this.map.clearOverlays();var summaryHTML=this.dirObj.getSummaryHtml();var distance=this.dirObj.getDistance();var duration=this.dirObj.getDuration();var numRoutes=this.dirObj.getNumRoutes();var oDriveFrom=this.fromAddress;var oDriveTo=this.toAddress;var startLatLng=this.dirObj.getRoute(0).getStep(0).getLatLng();var endLatLng=this.dirObj.getRoute(numRoutes-1).getEndLatLng();polyline=this.dirObj.getPolyline();this.map.addOverlay(polyline);var numGeoCodes=this.dirObj.getNumGeocodes();var startPoint=this.dirObj.getGeocode(0);var endPoint=this.dirObj.getGeocode(numGeoCodes-1);html+='<div class="globalSummaryDiv">';html+='<table cellspacing="0" cellpadding="2" width="100%">';html+='<tr><td valign="top"> <b>'+startPoint.address+'</b> '+this.tr('To')+' <b>'+endPoint.address+'</b></td></tr>';html+='<tr><td valign="top"> '+summaryHTML+'</td></tr>';html+='</table></div>';for(var r=0;r<numRoutes;r++){var route=this.dirObj.getRoute(r);var startGeoCode=this.dirObj.getGeocode(r);var endGeoCode=this.dirObj.getGeocode(r+1);var endLatLng=route.getEndLatLng();var routeSummaryHTML=route.getSummaryHtml();var routeDistance=route.getDistance();var routeDuration=route.getDuration();html+='<div class="routeSummaryDiv" onclick="$(\''+this.options.directions_element+'_routeTable_'+r+'\').toggle()" title="'+this.tr('Show_route')+'">';html+='<table cellspacing="0" cellpadding="2" width="100%">';html+='<tr>';if(numRoutes==1){html+='<td valign="top"><img src="/images/greenCircle.png" width="10px" height="10px"><br><img src="/images/redCircle.png"></td>'}else{if(r==0){html+='<td valign="top"><img src="/images/greenCircle.png" width="10px" height="10px"><br><img src="/images/yellowSquare.png" width="10px" height="10px"></td>';var midMarker=new GMarker(endLatLng,{icon:yellowIcon});this.map.addOverlay(midMarker)}else if(r==numRoutes-1){html+='<td valign="top"><img src="/images/yellowSquare.png" width="10px" height="10px"><br><img src="/images/redCircle.png" width="10px" height="10px"></td>'}else{html+='<td valign="top"><img src="/images/yellowSquare.png" width="10px" height="10px"><br><img src="/images/yellowSquare.png" width="10px" height="10px"></td>';var midMarker=new GMarker(endLatLng,{icon:yellowIcon});this.map.addOverlay(midMarker)}}html+='<td valign="top"><b>'+startGeoCode.address+'</b> to<br> <b>'+endGeoCode.address+'</b><br>'+routeDistance.html+' ('+routeDuration.html+')</td>';html+='</table></div>';var numSteps=route.getNumSteps();html+='<table cellspacing="0" cellpadding="0" id="'+this.options.directions_element+'_routeTable_'+r+'"  width="100%">';for(var s=0;s<numSteps;s++){var step=route.getStep(s);var stepLatLng=step.getLatLng();bounds.extend(stepLatLng);var stepPolylineIndex=step.getPolylineIndex();var stepDescriptionHTML=step.getDescriptionHtml();var stepDistance=step.getDistance();var stepDuration=step.getDuration();html+='<tr class="stepRow" onclick="contact_map.showStep('+stepLatLng.lat()+','+stepLatLng.lng()+');"><td>&nbsp;&nbsp;'+(s+1)+'.</td><td> '+stepDescriptionHTML+'</td><td>'+stepDistance.html+'</td></tr>'}html+='</table>'}this.directionsInfoDiv.innerHTML=html;this.map.setCenter(bounds.getCenter(this.map),this.map.getBoundsZoomLevel(bounds));if(this.traffic){var trafficOptions={incidents:true};trafficInfo=new GTrafficOverlay(trafficOptions);this.map.addOverlay(trafficInfo)}},showStep:function(lat,lng){stepLatLng=new GLatLng(lat,lng);this.map.showMapBlowup(stepLatLng);return false},showAddress:function(address){this.geocoder.getLatLng(address,function(point){if(!point){alert(address+" not found")}else{this.map.setCenter(point,this.options.zoom);var marker=new google.maps.Marker(point,{title:this.options.marker_title});this.map.addOverlay(marker);if(this.options.directions){marker.openInfoWindowHtml("<span class='small'>"+this.options.infowindow+"</span>"+"<form action='' onsubmit='return false;'>"+"<div class='formEntry'>"+"<label class='form_label' style='width:25px;color:#000000;'>"+this.tr('From')+":</label>"+"<input type='text' name=\""+this.options.directions_element+"_fromAddress\" id=\""+this.options.directions_element+"_fromAddress\" style='width:160px' class='forminput' value=''></input>"+"</div>"+"<div class='formEntry' style='margin-top:2px'>"+"<label class='form_label' style='width:25px;color:#000000;'>"+this.tr('To')+":</label>"+"<input type='text' name=\""+this.options.directions_element+"_toAddress\" id=\""+this.options.directions_element+"_toAddress\"  style='width:160px' class='forminput' value='"+this.options.address+"'>"+"</input>"+"</div>"+"<input name=\""+this.options.directions_element+"_submit_directions\" id=\""+this.options.directions_element+"_submit_directions\" class='new_formButton' style='margin-top:0px;margin-left:-48px' type=\"button\" value=\""+this.tr('Search_route')+"\" />"+"</form>",{maxWidth:($(this.options.map_element).getWidth()/2)});GEvent.addListener(marker,"infowindowopen",function(){$(this.options.directions_element+'_submit_directions').observe('click',function(){this.setDirections($F(this.options.directions_element+'_fromAddress'),$F(this.options.directions_element+'_toAddress'))}.bind(this))}.bind(this))}else{marker.openInfoWindowHtml("<span class='small'>"+this.options.infowindow+"</span>")}}}.bind(this))},unload:function(){GUnload()},load:function(){new AjaxCSSJS("http://www.google.com/jsapi?sensor=false&key="+this.getKey()+"&callback=",'js',function(){this.load2()}.bind(this))},load2:function(){google.load("maps","2",{"sensor":false,"language":this.options.language,"callback":this.loaded.bind(this)})},loaded:function(){if($(this.options.map_element)){if($(this.options.directions_element)&&this.options.directions){this.directionsInfoDiv=$(this.options.directions_element)}if(google.maps.BrowserIsCompatible()){this.map=new google.maps.Map2($(this.options.map_element));this.map.addControl(new google.maps.LargeMapControl());this.map.addControl(new google.maps.MapTypeControl());this.geocoder=new google.maps.ClientGeocoder();this.showAddress(this.options.address)}}}});DitMap.Language={'nl':{strings:{'From':'Van','To':'Naar','Show_route':'Klik om de route te bekijken','Search_route':'Plan route!'}}};