/* v1.1.7.0 */ var __MGRouteForecast_internalHandle=null;var __MGRouteForecast_mapHandle=null;var directionsPanel=null;var directions=null;var info=null;function MGRouteForecast(b,a){this.options={symbols:{url:"./{IMG_NAME}.png",shadow_url:null,dimensions:{x:64,y:64},shadow_dimensions:{x:64,y:64},anchor:{x:32,y:32},max_amount:10,min_distance:20,getImagePath:function(c){return this.url.replace("{IMG_NAME}",c);}},route:{directionsPanel:document.getElementById("route"),style:{color:"#ff0000",opacity:0.45,weight:5},directionsOptions:{locale:GLanguage.getLanguageCode(),avoidHighways:true}},backend:{script:"getweather.php"}};this.setOptions(a);__MGRouteForecast_internalHandle=this;__MGRouteForecast_mapHandle=b;}MGRouteForecast.prototype.setOptions=function(c){if(c instanceof Object){if(c.symbols instanceof Object){if(typeof c.symbols.url=="string"){this.options.symbols.url=c.symbols.url;}if(typeof c.symbols.shadow_url=="string"){this.options.symbols.shadow_url=c.symbols.shadow_url;}if(c.symbols.dimensions instanceof Object){var b=parseInt(c.symbols.dimensions.x,10);var a=parseInt(c.symbols.dimensions.y,10);if(!isNaN(b)){if(b>0&&b==c.symbols.dimensions.x&&b.toString()==c.symbols.dimensions.x.toString()){this.options.symbols.dimensions.x=b;this.options.symbols.anchor.x=Math.round(b/2);}}if(!isNaN(a)){if(a>0&&a==c.symbols.dimensions.x&&a.toString()==c.symbols.dimensions.x.toString()){this.options.symbols.dimensions.y=a;this.options.symbols.anchor.y=Math.round(a/2);}}}if(c.symbols.shadow_dimensions instanceof Object){this.options.symbols.shadow_dimensions.x=parseInt(c.symbols.shadow_dimensions.x,10);this.options.symbols.shadow_dimensions.y=parseInt(c.symbols.shadow_dimensions.y,10);}if(!isNaN(c.symbols.max_amount)&&c.symbols.max_amount>=2){this.options.symbols.max_amount=parseInt(c.symbols.max_amount,10);}if(!isNaN(c.symbols.min_distance)&&c.symbols.min_distance>1){this.options.symbols.min_distance=parseFloat(c.symbols.min_distance);}}if(c.route instanceof Object){if(typeof c.route.directionsPanel=="string"){this.options.route.directionsPanel=document.getElementById(c.route.directionsPanel);}else{if(c.route.directionsPanel instanceof Object){this.options.route.directionsPanel=c.route.directionsPanel;}}if(c.route.style instanceof Object){if(/#[a-fA-F0-9]{6}/.test(c.route.style.color)){this.options.route.style.color=c.route.style.color;}if(c.route.style.opacity){this.options.route.style.opacity=parseFloat(c.route.style.opacity);}if(c.route.style.weight){this.options.route.style.weight=parseInt(c.route.style.weight,10);}}if(c.route.directionsOptions instanceof Object){for(var d in c.route.directionsOptions){if(jQuery.inArray(d,["locale","travelMode","avoidHighways","getPolyline","getSteps","getSteps"])){this.options.route.directionsOptions[d]=c.route.directionsOptions[d];}}}}if(c.backend instanceof Object){if(c.backend.script){this.options.backend.script=c.backend.script;}}}};MGRouteForecast.prototype.trafficInfo=new GTrafficOverlay({incidents:true});MGRouteForecast.prototype.toggleState=null;MGRouteForecast.prototype.toggleTraffic=function(){if(this.toggleState==1){__MGRouteForecast_mapHandle.removeOverlay(this.trafficInfo);this.toggleState=0;}else{__MGRouteForecast_mapHandle.addOverlay(this.trafficInfo);this.toggleState=1;}};MGRouteForecast.prototype.getRouteDuration=function(a){var c=0;for(var b=0;b<a.getNumSteps();b++){c+=a.getStep(b).getDuration().seconds*1000;}return c;};MGRouteForecast.prototype.getPreviousRouteStepNumber=function(a,d){for(var c=0;c<a.getNumSteps();c++){var b=a.getStep(c).getPolylineIndex();if(b>d){return c-1;}}};MGRouteForecast.prototype.getRouteDurationToStep=function(a,d){var c=0;for(var b=0;b<d;b++){c+=a.getStep(b).getDuration().seconds*1000;}return c;};MGRouteForecast.prototype.handleDirectionLoadError=function(a){alert("Error #"+a);};MGRouteForecast.prototype.correctAddress=function(a){var b=a.split(",");if(b instanceof Array&&b.length>1){a=b[0]+" 1, ";b.shift();a+=b.join(", ");return a.replace("  "," ");}else{return a;}};MGRouteForecast.prototype.getRoute=function(d,c,b,a){if(a!==false){a=true;}__MGRouteForecast_mapHandle.clearOverlays();directionsPanel=this.options.route.directionsPanel;while(directionsPanel.firstChild){directionsPanel.removeChild(directionsPanel.firstChild);}c=(c instanceof Array)?c.join(" to: "):c;directions=new GDirections(__MGRouteForecast_mapHandle,directionsPanel);directions.load("from: "+d+" to: "+c,__MGRouteForecast_internalHandle.options.route.directionsOptions);GEvent.addListener(directions,"error",function(){var e=false;var f,g;if(a===true&&directions.getStatus().code===G_GEO_UNKNOWN_ADDRESS){f=__MGRouteForecast_internalHandle.correctAddress(d);g=__MGRouteForecast_internalHandle.correctAddress(c);e=d!==f||c!==g;}if(e===true){__MGRouteForecast_internalHandle.getRoute(f,g,b,false);}else{__MGRouteForecast_internalHandle.handleDirectionLoadError(directions.getStatus().code);}});GEvent.addListener(directions,"load",function(){var l=directions.getPolyline();l.color=__MGRouteForecast_internalHandle.options.route.style.color;l.opacity=__MGRouteForecast_internalHandle.options.route.style.opacity;l.weight=__MGRouteForecast_internalHandle.options.route.style.weight;l.redraw(true);__MGRouteForecast_mapHandle.setZoom(__MGRouteForecast_mapHandle.getBoundsZoomLevel(l.getBounds()));var h=[];var m=b?new Date(b):new Date();var q=m.getTime();var H=directions.getNumRoutes();for(var x=0;x<H;x++){var G=directions.getRoute(x);var y=__MGRouteForecast_internalHandle.options.symbols.min_distance;var E=__MGRouteForecast_internalHandle.options.symbols.max_amount;var F=directions.getPolyline();var j=F.getVertexCount();var v=F.getLength()/1000;var w=Math.floor(v/y);w=w>E?E:w;var n=Math.round(j/w);var z=G.getStep(0);var C=new Date();var s=z.getPolylineIndex();C.setTime(q+z.getDuration().seconds*1000);if(x===0){h.push({point:z.getLatLng(),time:C});}for(var r=n+s;r<j;r+=n){var k=__MGRouteForecast_internalHandle.getPreviousRouteStepNumber(G,r);if(!k||k<0){break;}var D=G.getStep(k);var f=G.getStep(k+1);var p=D.getPolylineIndex();var u=f.getPolylineIndex();var J=q+__MGRouteForecast_internalHandle.getRouteDurationToStep(G,k);var o=q+__MGRouteForecast_internalHandle.getRouteDurationToStep(G,k+1);var e=(r-p)/(u-p);var I=J+((o-J)*(e));var g=new Date();g.setTime(I);h.push({point:F.getVertex(r),time:g});}if(x==H-1){z=G.getStep(G.getNumSteps()-1);var t=new Date();t.setTime(q+__MGRouteForecast_internalHandle.getRouteDurationToStep(G,G.getNumSteps()-1));h.push({point:z.getLatLng(),time:t});}q=q+__MGRouteForecast_internalHandle.getRouteDuration(G);}function B(L){try{var K=__MGRouteForecast_internalHandle.options.symbols;for(var M=0;M<L.length;M++){response=L[M];var Q=new GIcon(G_DEFAULT_ICON,K.getImagePath(response.weather));Q.iconSize=new GSize(K.dimensions.x,K.dimensions.y);Q.iconAnchor=new GPoint(K.anchor.x,K.anchor.y);if(K.shadow_url){Q.shadow=K.shadow_url;Q.shadowSize=new GSize(K.shadow_dimensions.x,K.shadow_dimensions.y);}else{Q.shadowSize=new GSize(0,0);}var P=new GLatLng(response.lat,response.lon);var O=new GMarker(P,{icon:Q,title:response.title,clickable:false});__MGRouteForecast_mapHandle.addOverlay(O);}}catch(N){alert(N);}}for(var A=0;A<h.length;A++){h[A]='{"p":{"lon":'+h[A].point.lng()+',"lat":'+h[A].point.lat()+'},"t":"'+h[A].time.toGMTString()+'"}';}jQuery.post(__MGRouteForecast_internalHandle.options.backend.script,{"data":"["+h.join(",")+"]"},B,"json");});};
