function GSRoute(a){this.options={network:"nz",directionsServiceUrl:null,returnToStart:false,calculateInstructions:true,distanceUnit:"Km",instructionDistanceDecimalPlaces:1,tmc:false,dragToInsertWaypoints:false,style:{stroke:"#0048FF","stroke-width":"6px","stroke-opacity":0.59,"stroke-style":"solid","stroke-linecap":"butt"},tmcStyle:{stroke:"#00FF48","stroke-width":"6px","stroke-opacity":0.59,"stroke-style":"solid","stroke-linecap":"butt"}};GSUtil.merge(a,this.options);this.pathPolylines=[];this.waypoints=a.waypoints!==undefined?a.waypoints:[];this.instructionTemplates=a.instructionTemplates!==undefined?a.instructionTemplates:null;if(this.instructionTemplates==null){this.instructionTemplates={start:"Starting from <strong>[waypoint]</strong>, go <strong>[bearing]</strong> on <strong>[roadname]</strong>",stop:"Continue for [distance] "+this.options.distanceUnit+" along <strong>[roadname]</strong> to <strong>[waypoint]</strong>",roundabout:"After [distance] "+this.options.distanceUnit+" go <strong>[direction]</strong>  at the roundabout onto <strong>[roadname]</strong>",turn:"After [distance] "+this.options.distanceUnit+" go <strong>[direction]</strong> onto <strong>[roadname]</strong>",uturn:"Make a <strong>U-turn</strong>",nodistanceturn:"Go <strong>[direction]</strong> onto <strong>[roadname]</strong>",fly:"Fly [distance] "+this.options.distanceUnit+" to <strong>[roadname]</strong>"}}this.data=a.data!==undefined?a.data:null;this.layer=a.layer!==undefined?a.layer:null;this.map=this.layer!==null?this.layer.map:null;this.currentDragHandle=null;this.distance=null;this.time=null;this.originalData=null;this.originalDataJson=null;if(this.data!=undefined&&this.layer!=undefined){this.addToLayer(this.layer)}this.request=new GSXHR({autoCancel:true,onSuccess:GSUtil.bind(this.loaded,this),onFailure:GSUtil.bind(this.failed,this),method:"post",urlEncodeData:false,contentType:"application/json"});this.addedToLayer=false;this.preventDragToInsertWaypoints=false;this.nextWaypointId=1}GSUtil.include(GSRoute,new GSEventBroadcasterMixin());GSRoute.NUM_LEVELS=4;GSRoute.FAILURE="ROUTEFAILURE";GSRoute.SNAP_FAILURE="SNAPFAILURE";GSRoute.prototype.getStyle=function(){return this.options.style};GSRoute.prototype.getTMCStyle=function(){return this.options.tmcStyle};GSRoute.prototype.getInstructionDistanceDecimalPlaces=function(){return this.options.instructionDistanceDecimalPlaces};GSRoute.prototype.canDragToInsertWaypoints=function(){return this.options.dragToInsertWaypoints};GSRoute.prototype.toGeoJsonObj=function(){var c=[];for(var b=0,a=this.waypoints.length;b<a;b++){c.push(this.waypoints[b].toGeoJsonObj())}if(this.options.returnToStart&&this.waypoints[0]){c.push(this.waypoints[0].toGeoJsonObj())}var d={type:"FeatureCollection",features:c};return d};GSRoute.prototype.calculate=function(j,b){if(this.waypoints.length<2){throw new Error("GSRoute.calculate called with only one waypoint.")}if(j){this.calculateOnSuccess=j}if(b){this.calculateOnFailure=b}this.preventDragToInsertWaypoints=true;if(this.addedToLayer){this.map.customCursor="wait";this.map.setCursor()}var m=GSUtil.objToJson(this.toGeoJsonObj());var h=[];var g=[];var a=[];for(var f=0,d=this.waypoints.length;f<d;f++){var k=this.waypoints[f];g.push(k.stringify());if(k.type=="stop"){h.push(k.label)}a.push({label:GSUtil.clone(k.label),coordinate:GSUtil.clone(k.coordinate),type:GSUtil.clone(k.type)})}if(this.options.returnToStart&&this.waypoints[0]){var k=this.waypoints[0];g.push(k.stringify());if(k.type=="stop"){h.push(k.label)}a.push({label:GSUtil.clone(k.label),coordinate:GSUtil.clone(k.coordinate),type:GSUtil.clone(k.type)})}var c=["extents"];if(this.options.calculateInstructions){c.push("instructions")}if(this.options.tmc){c.push("tmccodes");c.push("tmcpaths")}else{c.push("paths")}this.request.cancel();this.request.waypointLabels=h;this.request.waypointCache=a;var e="/"+this.options.network+"/services/journey/"+c.join(":");this.request.send(this.options.directionsServiceUrl+(this.options.directionsServiceUrl.indexOf("?")==-1?"?":"&")+"params="+encodeURIComponent(e),m);this.broadcastMessage("routeCalculating",this)};GSRoute.prototype.setData=function(b,a){this.request.cancel();this.request.waypointLabels=a;this.calculateOnSuccess=null;this.loaded(b)};GSRoute.prototype.getData=function(){return this.originalData};GSRoute.prototype.nearWaypoint=function(e){var b=12*this.layer.map.mpx;for(var c=0,a=this.waypoints.length;c<a;c++){var d=new GSBounds(this.waypoints[c].coordinate.x-b,this.waypoints[c].coordinate.y-b,this.waypoints[c].coordinate.x+b,this.waypoints[c].coordinate.y+b);if(d.contains(e)){return true}}return false};GSRoute.prototype.getJsonData=function(){return this.originalDataJson};GSRoute.prototype.loaded=function(data,rawData){this.data=data;this.originalData=eval("("+rawData+")");this.originalDataJson=rawData;if(!data||data.resulttype!="SUCCESS"){this.failed(data,rawData)}else{this.removeFromLayer();this.legs=this.instantiateLegs(this.data.instructions,this.data.extents,this.request.waypointLabels);var paths=this.data.tmcpaths?this.data.tmcpaths:this.data.paths;this.paths=this.instantiatePaths(paths);if(data.tmccodes){this.tmccodes=data.tmccodes}else{this.tmccodes=undefined}this.distance=null;this.time=null;if(this.layer){this.addToLayer()}this.preventDragToInsertWaypoints=false;if(this.addedToLayer){this.layer.map.customCursor=undefined;this.layer.map.setCursor()}if(typeof this.calculateOnSuccess=="function"){this.calculateOnSuccess();this.calculateOnSuccess=null}this.broadcastMessage("routeCalculated",this)}};GSRoute.prototype.failed=function(d,f){if(this.addedToLayer){this.layer.map.customCursor=undefined;this.layer.map.setCursor()}this.preventDragToInsertWaypoints=false;if(typeof this.calculateOnFailure=="function"){this.calculateOnFailure();this.calculateOnFailure=null}if(d&&d.resulttype){switch(d.resulttype){case GSRoute.SNAP_FAILURE:var e=[];for(var c=0,b=d.waypoints.features.length;c<b;c++){var a=this.getWaypointById(d.waypoints.features[c].id);if(a){e.push(a)}}this.broadcastMessage("routeCalculationFailed",this,GSRoute.SNAP_FAILURE,e);break;default:this.broadcastMessage("routeCalculationFailed",this,GSRoute.FAILURE)}}else{this.broadcastMessage("routeCalculationFailed",this,GSRoute.FAILURE)}};GSRoute.prototype.instantiateLegs=function(b,k,h){var n=[];this.resetCurrentInstructionIndex();this.resetRunningDistance();if(b){var e=b.features;var g=e.length;var c=0;var j=0;for(var f=0,d=k.length;f<d;f++){var a=j;while(a<g&&e[a].properties.instructiontype!="stop"){a++}var m=new GSRouteLeg(this,e.slice(j,a+1),k[f].length,k[f].weight,h[f],h[f+1],f);n.push(m);j=a+1}}else{for(var f=0,d=k.length;f<d;f++){var m=new GSRouteLeg(this,[],k[f].length,k[f].weight,f);n.push(m)}}return n};GSRoute.prototype.instantiatePaths=function(a){var p=[];var h=GSRoute.NUM_LEVELS;var e,d,c,b;for(var e=0;e<a.features.length;e++){var q=a.features[e];var d,c;var n=[];var g=q.geometry.coordinates;for(d=0,c=g.length;d<c;d++){n.push(new GSPoint(g[d][0],g[d][1]))}var f=[];if(q.properties.slices){var m=q.properties.slices;for(d=0,c=m.length;d<c;d++){f.push({start:m[d][0],end:m[d][1]})}}var o=new GSRoutePath(this,n,q.geometry.levels,f,e);p.push(o)}return p};GSRoute.prototype.resetCurrentInstructionIndex=function(){this.currentInstructionIndex=1};GSRoute.prototype.getNextInstructionIndex=function(){return this.currentInstructionIndex++};GSRoute.prototype.resetRunningDistance=function(){this.currentRunningDistance=0};GSRoute.prototype.increaseRunningDistance=function(a){this.currentRunningDistance+=a;return this.currentRunningDistance};GSRoute.prototype.clear=function(){for(var b=0,a=this.waypoints.length;b<a;b++){this.waypoints[b].remove()}this.waypoints=[];this.removeFromLayer();this.data=undefined;this.distance=null;this.time=null;this.legs=undefined};GSRoute.prototype.getWaypointCount=function(){return this.waypoints.length};GSRoute.prototype.getWaypointByIndex=function(a){return this.waypoints[a]};GSRoute.prototype.getWaypointById=function(c){for(var b=0,a=this.waypoints.length;b<a;b++){if(this.waypoints[b].id==c){return this.waypoints[b]}}return null};GSRoute.prototype.getWaypointIndex=function(b){for(var c=0,a=this.waypoints.length;c<a;c++){if(this.waypoints[c]==b){return c}}return false};GSRoute.prototype.createWaypointId=function(){return this.nextWaypointId++};GSRoute.prototype.addWaypoint=function(a){a.setRoute(this);this.waypoints.push(a);return a};GSRoute.prototype.replaceWaypointAtIndex=function(a,b){a.setRoute(this);this.waypoints[b]=a;return a};GSRoute.prototype.insertWaypointBefore=function(b,d){b.setRoute(this);for(var c=0,a=this.waypoints.length;c<a;c++){if(d==this.waypoints[c]){this.waypoints.splice(c,0,b);return b}}this.waypoints.push(b);return b};GSRoute.prototype.insertWaypointAfter=function(b,d){b.setRoute(this);for(var c=0,a=this.waypoints.length;c<a;c++){if(d==this.waypoints[c]){this.waypoints.splice(c+1,0,b);return b}}this.waypoints.push(b);return b};GSRoute.prototype.replaceWaypoint=function(b,d){b.setRoute(this);for(var c=0,a=this.waypoints.length;c<a;c++){if(d==this.waypoints[c]){this.waypoints[c]=b;return b}}this.waypoints.push(b);return b};GSRoute.prototype.removeWaypoint=function(b){for(var c=0,a=this.waypoints.length;c<a;c++){if(b==this.waypoints[c]){this.waypoints[c].remove();this.waypoints.splice(c,1);return true}}return false};GSRoute.prototype.formatDistance=function(a){if(a<100000){return(Math.round(a/100)/10).toFixed(1)+" Km"}else{return GSUtil.addThousandsSeparators(Math.round(a/1000))+" Km"}};GSRoute.prototype.formatTime=function(c){c=Math.round(c);var a=Math.floor(c/60);var b=c%60;return(a>0?(a+" hour"+(a==1?"":"s")+" "):"")+b+" min"+(b==1?"":"s")};GSRoute.prototype.getTime=function(){if(this.time===null){var c=0;for(var b=0,a=this.legs.length;b<a;b++){c+=this.legs[b].time}this.time=c}return this.time};GSRoute.prototype.getDistance=function(){if(this.distance===null){var c=0;for(var b=0,a=this.legs.length;b<a;b++){c+=this.legs[b].distance}this.distance=c}return this.distance};GSRoute.prototype.getLegs=function(){return this.legs};GSRoute.prototype.getPaths=function(){return this.paths};GSRoute.prototype.getTmcCodes=function(){return this.tmccodes};GSRoute.prototype.getBounds=function(){if(this.paths){var a,g,f,e;var d=[];for(var c=0,b=this.paths.length;c<b;c++){d.push(this.paths[c].getBounds())}a=GSUtil.getMinimum(GSUtil.getPropertyArray(d,"minX"));g=GSUtil.getMinimum(GSUtil.getPropertyArray(d,"minY"));f=GSUtil.getMaximum(GSUtil.getPropertyArray(d,"maxX"));e=GSUtil.getMaximum(GSUtil.getPropertyArray(d,"maxY"));return new GSBounds(a,g,f,e)}else{return null}};GSRoute.prototype.setCurrentDragHandleByIndex=function(a){if(this.waypoints[a]){this.currentDragHandle=this.waypoints[a].dragHandle}else{this.currentDragHandle=null}};GSRoute.prototype.getCurrentDragHandle=function(){return this.currentDragHandle};GSRoute.prototype.removeFromLayer=function(){for(var b=0,a=this.waypoints.length;b<a;b++){this.waypoints[b].hideDragHandle()}if(this.paths){for(var b=0,a=this.paths.length;b<a;b++){this.paths[b].remove()}this.addedToLayer=false;this.setCurrentDragHandleByIndex(-1)}};GSRoute.prototype.addToLayer=function(c){if(c){this.layer=c}if(this.layer&&!this.addedToLayer){this.addedToLayer=true;for(var b=0,a=this.paths.length;b<a;b++){this.paths[b].addToRouteLayer()}return true}return false};function GSRouteLeg(b,d,g,e,f,a,c){this.route=b;this.instructionFeatures=d;this.distance=g;this.time=e;this.startLabel=f;this.stopLabel=a;this.index=c;this.instructions=null}GSRouteLeg.prototype.getTime=function(){return this.time};GSRouteLeg.prototype.getDistance=function(){return this.distance};GSRouteLeg.prototype.getInstructions=function(){if(!this.instructions&&this.instructionFeatures){var b=[];for(var c=0,a=this.instructionFeatures.length;c<a;c++){b.push(new GSRouteInstruction(this,this.instructionFeatures[c]))}this.instructions=b}return this.instructions};function GSRoutePath(a,d,e,c,b){this.route=a;this.points=d;this.levels=e;this.tmcRanges=c;this.index=b}GSRoutePath.prototype.addToRouteLayer=function(){var c=this.getPolylines();for(var b=0,a=c.length;b<a;b++){c[b].addPolylinesToLayer(this.route.layer)}};GSRoutePath.prototype.remove=function(){if(this.polylines){for(var b=0,a=this.polylines.length;b<a;b++){this.polylines[b].removePolylines()}this.polylines=undefined}};GSRoutePath.prototype.getFirstCoordinate=function(){var a=this.getPolylines();return a[0].levelPoints[0][0]};GSRoutePath.prototype.getBounds=function(){if(!this.bounds){var g=this.getPolylines();var d=[];var j=[];for(var h=0,e=g.length;h<e;h++){d=d.concat(GSUtil.getPropertyArray(g[h].levelPoints[0],"x"));j=j.concat(GSUtil.getPropertyArray(g[h].levelPoints[0],"y"))}var f=GSUtil.getMinimum(d);var c=GSUtil.getMinimum(j);var b=GSUtil.getMaximum(d);var a=GSUtil.getMaximum(j);this.bounds=new GSBounds(f,c,b,a)}return this.bounds};GSRoutePath.prototype.getPolylines=function(){if(!this.polylines){var b=[];var h;if(this.tmcRanges&&this.tmcRanges.length){var f=this.points;var g=this.levels;var d=this.tmcRanges;var j=this.getLevelPointsWithTmc(f,g,d,this.route.getStyle(),this.route.getTMCStyle());for(var c=0,a=j.length;c<a;c++){var h=new GSMultiLevelPolyline(j[c].levelPoints,{style:j[c].style});if(this.route.canDragToInsertWaypoints()){h.addEventHandler("mouseover",GSUtil.bindAsEventListener(this.polylineMouseOverHandler,this,h))}b.push(h)}}else{var e=GSMultiLevelPolyline.getLevelPoints(this.points,this.levels);h=new GSMultiLevelPolyline(e,{style:this.route.getStyle()});if(this.route.canDragToInsertWaypoints()){h.addEventHandler("mouseover",GSUtil.bindAsEventListener(this.polylineMouseOverHandler,this,h))}b.push(h)}this.polylines=b}return this.polylines};GSRoutePath.prototype.getLevelPointsWithTmc=function(h,j,e,b,f){var g=GSRoute.NUM_LEVELS;var d,c;var a=[];for(d=0,c=e.length;d<c;d++){j[e[d].start]=g-1;j[e[d].end]=g-1}if(e[0].start!=0){a.push({levelPoints:GSMultiLevelPolyline.getLevelPoints(h.slice(0,e[0].start+1),j.slice(0,e[0].start+1)),style:b})}for(d=0,c=e.length;d<c;d++){a.push({levelPoints:GSMultiLevelPolyline.getLevelPoints(h.slice(e[d].start,e[d].end+1),j.slice(e[d].start,e[d].end+1)),style:f})}for(d=0,c=e.length-1;d<c;d++){a.push({levelPoints:GSMultiLevelPolyline.getLevelPoints(h.slice(e[d].end,e[d+1].start+1),j.slice(e[d].end,e[d+1].start+1)),style:b})}if(e[e.length-1].end!=h.length-1){a.push({levelPoints:GSMultiLevelPolyline.getLevelPoints(h.slice(e[e.length-1].end,h.length),j.slice(e[e.length-1].end,h.length)),style:b})}return a};GSRoutePath.prototype.polylineMouseOverHandler=function(c,a){this.disableMapMouseMoveHandler(true);if(!this.route.preventDragToInsertWaypoints){if(this.route.dragHandleHideToken){clearTimeout(this.route.dragHandleHideToken)}var b=this.route.layer.map;this.route.mapMouseMoveHandlerToken=GSEventManager.addEventListener(b.container,"mousemove",GSUtil.bindAsEventListener(this.mapMouseMoveHandler,this,a));this.route.setCurrentDragHandleByIndex(this.index);this.mapMouseMoveHandler(c,a)}GSUtil.cancelEvent(c)};GSRoutePath.prototype.mapMouseMoveHandler=function(g,c){var b=12;var f=this.route.layer.map;if(this.route.waypoints[this.index]&&this.route.waypoints[this.index].dragMode==null&&!f.panning){var h=f.getMouseCoordinate(g);var d=c.projectPoint(h);if(d&&d.distance<b*f.mpx){var a=this.route.getCurrentDragHandle();if(this.route.nearWaypoint(h)){a.setVisible(false)}else{if(a!==null){a.coordinate=d.coordinate;a.setVisible(true)}}}else{this.disableMapMouseMoveHandler()}}};GSRoutePath.prototype.disableMapMouseMoveHandler=function(a){var b=this.route.getCurrentDragHandle();if(b!==null){if(a){b.setVisible(false);this.route.setCurrentDragHandleByIndex(-1)}else{this.route.dragHandleHideToken=setTimeout(GSUtil.bind(function(){b.setVisible(false);this.route.setCurrentDragHandleByIndex(-1)},this),500)}}if(this.route.mapMouseMoveHandlerToken){GSEventManager.removeEventListener(this.route.mapMouseMoveHandlerToken);this.route.mapMouseMoveHandlerToken=null}};function GSRouteInstruction(b,a){this.leg=b;this.feature=a;this.properties=a.properties;this.type=a.properties.instructiontype;this.index=this.leg.route.getNextInstructionIndex();switch(this.type){case"start":this.properties.waypoint=this.leg.startLabel;this.properties.bearing=this.getBearing(this.properties.azimuth);break;case"stop":this.properties.waypoint=this.leg.stopLabel;break;case"roundabout":this.properties.direction=this.getDirection(this.properties.inboundazimuth,this.properties.outboundazimuth);break;case"turn":this.properties.direction=this.getDirection(this.properties.inboundazimuth,this.properties.outboundazimuth);if(this.properties.distance==0){this.type="nodistanceturn"}break}this.runningDistanceMetres=this.leg.route.increaseRunningDistance(this.properties.distance?this.properties.distance:0);if(this.properties.distance){this.properties.distanceMetres=this.properties.distance;this.properties.distance=GSUtil.roundNumber(this.properties.distance/1000,this.leg.route.getInstructionDistanceDecimalPlaces()).toFixed(this.leg.route.getInstructionDistanceDecimalPlaces())}this.coordinate=new GSPoint(a.geometry.coordinates[0],a.geometry.coordinates[1])}GSRouteInstruction.prototype.getName=function(){return this.properties.waypoint};GSRouteInstruction.prototype.getBearing=function(c){c=this.normalizeBearing(c);var d=45/2;if(1*d<=c&&c<3*d){return"north east"}else{if(3*d<=c&&c<5*d){return"east"}else{if(5*d<=c&&c<7*d){return"south east"}else{if(7*d<=c&&c<9*d){return"south"}else{if(9*d<=c&&c<11*d){return"south west"}else{if(11*d<=c&&c<13*d){return"west"}else{if(13*d<=c&&c<15*d){return"north west"}else{return"north"}}}}}}}};GSRouteInstruction.prototype.getDirection=function(c,b){var a=15;var d=this.normalizeBearing(b-c);if(180<d&&d<(360-a)){return"left"}else{if(a<d&&d<180){return"right"}else{return"straight"}}};GSRouteInstruction.prototype.normalizeBearing=function(a){while(a>=360){a-=360}while(a<0){a+=360}return a};GSRouteInstruction.prototype.getHTML=function(){var b=this.leg.route.instructionTemplates[this.type];for(var c in this.properties){var a=GSUtil.escapeHTML(this.properties[c]);b=b.replace("["+c+"]",a)}return b};GSRouteInstruction.prototype.getCoordinate=function(){return this.coordinate};function GSWaypoint(b,a){this.coordinate=b;this.label=(a.label!=undefined?a.label:null);this.type=(a.type!=undefined?a.type:"stop");this.route=null;this.dragMode=null;this.id=null}GSWaypoint.prototype.createPointFeature=function(){if(this.type=="via"&&this.route.layer){var a=new GSIcon();a.imageSrc=_globals.resourceURL+"via-point.png";a.imageSize=new GSDimension(11,11);a.iconOffset=new GSPoint(-6,-6);this.pointFeature=new GSPointFeature({icon:a,coordinate:this.coordinate,visible:true,draggable:true});this.pointFeature.setTip("Drag this icon to move the via point.",{offset:new GSPoint(10,10),showDelay:10});this.pointFeature.addEventHandler("mouseover",function(b){GSUtil.cancelEvent(b)});this.pointFeature.addToLayer(this.route.layer);this.pointFeature.addListener(new GSWaypointDragListener(this,"move",this.route.layer,this.route.getStyle()))}};GSWaypoint.prototype.setRoute=function(a){this.route=a;this.id=this.route.createWaypointId();this.createDragHandle();this.createPointFeature()};GSWaypoint.prototype.createDragHandle=function(){if(this.route.canDragToInsertWaypoints()&&this.route.layer){var a=new GSIcon();a.imageSrc=_globals.resourceURL+"via-point.png";a.imageSize=new GSDimension(11,11);a.iconOffset=new GSPoint(-6,-6);this.dragHandle=new GSPointFeature({icon:a,coordinate:new GSPoint(0,0),visible:false,draggable:true});this.dragHandle.setTip("Drag this icon to insert a via point.",{offset:new GSPoint(10,10),showDelay:10});this.dragHandle.addToLayer(this.route.layer);this.dragHandleListener=new GSWaypointDragListener(this,"insert",this.route.layer,this.route.getStyle());this.dragHandle.addListener(this.dragHandleListener)}};GSWaypoint.prototype.dragStart=function(a){this.dragMode=a.type};GSWaypoint.prototype.getDragCoordinates=function(a){if(a.type=="insert"){return[this.coordinate,this.dragHandle.coordinate,this.route.waypoints[this.getIndex()+1].coordinate]}else{return[this.route.waypoints[this.getIndex()-1].coordinate,this.pointFeature.coordinate,this.route.waypoints[this.getIndex()+1].coordinate]}};GSWaypoint.prototype.dragEnd=function(f){this.dragMode=null;var d=this.route;var c=this;var h,e;var g=function(i){i.graphicsEl.style.cursor="pointer"};if(f.type=="insert"){this.dragHandle.setVisible(false);var b=this.route.insertWaypointAfter(new GSWaypoint(this.dragHandle.coordinate,{label:"via",type:"via"}),this);b.pointFeature.graphicsEl.style.cursor="wait";h=function(){g(b.pointFeature);var j=d.getPaths();var i=b.getIndex();b.setCoordinate(j[i].getFirstCoordinate());d.broadcastMessage("routeViaWaypointInserted",d,b,c)};e=function(){d.removeWaypoint(b)}}else{if(f.type=="move"){var a=this.coordinate;this.setCoordinate(this.pointFeature.coordinate);this.pointFeature.graphicsEl.style.cursor="wait";h=function(){g(c.pointFeature);var j=d.getPaths();var i=c.getIndex();c.setCoordinate(j[i].getFirstCoordinate());d.broadcastMessage("routeViaWaypointMoved",d,c)};e=function(){g(c.pointFeature);c.setCoordinate(a)}}}this.route.calculate(h,e)};GSWaypoint.prototype.setCoordinate=function(a){this.coordinate=a;if(this.pointFeature){this.pointFeature.setCoordinate(a)}};GSWaypoint.prototype.hideDragHandle=function(){if(this.dragHandle){this.dragHandle.setVisible(false)}};GSWaypoint.prototype.getIndex=function(){return this.route.getWaypointIndex(this)};GSWaypoint.prototype.stringify=function(){return this.coordinate.x+":"+this.coordinate.y+":"+this.label.replace(/,/g,"[comma]").replace(/\:/g,"[colon]")+":"+this.type};GSWaypoint.prototype.remove=function(){if(this.dragHandle){this.dragHandle.remove()}if(this.pointFeature){this.pointFeature.remove()}};GSWaypoint.prototype.toGeoJsonObj=function(){var a={type:"Feature",id:this.id,geometry:this.coordinate.toGeoJsonObj(),properties:{waypointtype:this.type}};return a};function GSWaypointDragListener(a,d,b,c){this.owner=a;this.type=d;this.layer=b;this.style=c}GSWaypointDragListener.prototype.featureDragStart=function(){this.createDragBoundary();this.owner.dragStart(this)};GSWaypointDragListener.prototype.featureDrag=function(){this.renderDragBoundary(this.owner.getDragCoordinates(this))};GSWaypointDragListener.prototype.featureDragEnd=function(){this.destroyDragBoundary();this.owner.dragEnd(this)};GSWaypointDragListener.prototype.createDragBoundary=function(){if(_browser.svg){this.dragBoundary=document.createElementNS(_globals.svgns,"polyline");this.dragBoundary.style.display="none";this.dragBoundary.setAttributeNS(null,"stroke",this.style.stroke);this.dragBoundary.setAttributeNS(null,"stroke-width",this.style["stroke-width"]);this.dragBoundary.setAttributeNS(null,"stroke-opacity",this.style["stroke-opacity"]);this.dragBoundary.setAttributeNS(null,"stroke-dasharray",this.style["stroke-width"]+","+this.style["stroke-width"]);this.dragBoundary.setAttributeNS(null,"fill","none");GSUtil.makeUnselectable(this.dragBoundary)}else{if(_browser.isIE6up){this.dragBoundary=document.createElement(_globals.vmlnsPrefix+":shape");this.dragBoundary.style.display="none";this.dragBoundary.setAttribute("unselectable","on");var b=document.createElement(_globals.vmlnsPrefix+":stroke");b.setAttribute("on","true");b.setAttribute("color",this.style.stroke);b.setAttribute("weight",Math.max(parseInt(this.style["stroke-width"],10)-2,1));b.setAttribute("opacity",this.style["stroke-opacity"]);b.setAttribute("dashstyle","1 1");this.dragBoundary.appendChild(b);var a=document.createElement(_globals.vmlnsPrefix+":fill");a.setAttribute("on","false");this.dragBoundary.appendChild(a)}}if(this.dragBoundary){if(!this.layer.vectorContainer){this.layer.vectorContainer=this.layer.createVectorContainer()}this.layer.vectorContainer.appendChild(this.dragBoundary);if(!_browser.svg&&_browser.isIE6up){this.dragBoundary.style.width=this.layer.map.pxWidth;this.dragBoundary.style.height=this.layer.map.pxHeight;this.dragBoundary.coordsize=this.layer.map.pxWidth+" "+this.layer.map.pxHeight}this.dragBoundary.style.display=""}};GSWaypointDragListener.prototype.destroyDragBoundary=function(){if(this.dragBoundary){this.layer.vectorContainer.removeChild(this.dragBoundary);this.dragBoundary=null}};GSWaypointDragListener.prototype.renderDragBoundary=function(f){if(this.dragBoundary){var e=this.layer.map.translateToMapCoordinate(f[0]);var d=this.layer.map.translateToMapCoordinate(f[1]);var b=this.layer.map.translateToMapCoordinate(f[2]);if(_browser.svg){var a=[e.x,e.y,d.x,d.y,b.x,b.y];this.dragBoundary.setAttributeNS(null,"points",a);this.layer.map.container.scrollLeft=this.layer.map.container.scrollLeft}else{if(_browser.isIE6up){var c="m "+Math.round(e.x)+","+Math.round(e.y)+" l "+Math.round(d.x)+", "+Math.round(d.y)+", "+Math.round(b.x)+", "+Math.round(b.y)+" e";this.dragBoundary.style.display="none";this.dragBoundary.path=c;this.dragBoundary.style.display=""}}}};if(window.GSModule&&GSModule.moduleLoaded){GSModule.moduleLoaded("routing")};