function StaticRouteManager(map) 
{
    var m_vemap = map;
    var m_route = null;
    var m_routeOptions = new VERouteOptions();
    var m_routeHighlight = null;
    var m_routeShapeLayer = null;
    var m_routeDecoder = new Msn.VE.DirectionsDecoder();
    var m_veLatLongFactory = new VELatLongFactory(new VELatLongFactorySpecFromMap(m_vemap));

    this.ProcessRoute = function(object, options) 
    {
        m_route = new VERoute();
        if ((typeof options != 'undefined') && (options != null)) 
        {
            m_routeOptions = options;
        }
        m_routeHighlight = null;

        if (object && object.ResponseSummary && (object.ResponseSummary.StatusCode == 0)) {
            if (object.RouteResult) {
                if (object.RouteResult.RouteSummary) {
                    if (object.RouteResult.RouteSummary.Distance) {
                        m_route.Distance = object.RouteResult.RouteSummary.Distance;
                    }

                    if (object.RouteResult.RouteSummary.TimeInSeconds) {
                        m_route.Time = object.RouteResult.RouteSummary.TimeInSeconds;
                    }
                }

                if (object.RouteResult.RouteLegs) {
                    var len = object.RouteResult.RouteLegs.length;
                    for (var i = 0; i < len; ++i) {
                        var leg = object.RouteResult.RouteLegs[i];
                        var itinerary = new VERouteItinerary();
                        var itineraryItemsLen = leg.Itinerary.Items.length;
                        for (var j = 0; j < itineraryItemsLen; ++j) {
                            var item = leg.Itinerary.Items[j];

                            var warnings = null;
                            if (item.ItemWarnings) {
                                warnings = new Array();
                                for (var k = 0; k < item.ItemWarnings.length; ++k) {
                                    warnings.push(new VERouteWarning(
                                                        item.ItemWarnings[k].WarningText.Text,
                                                        item.ItemWarnings[k].WarningCriticality));
                                }
                            }

                            var hints = null;
                            if (item.ItemHints) {
                                hints = new Array();
                                for (var k = 0; k < item.ItemHints.length; ++k) {
                                    hints.push(new VERouteHint(
                                                        item.ItemHints[k].HintType,
                                                        item.ItemHints[k].HintText.Text));
                                }
                            }

                            itinerary.Items.push(new VERouteItineraryItem(item.Text.Text,
                                                                          m_veLatLongFactory.CreateVELatLong(item.ItemDetails[0].Coordinate.Latitude, item.ItemDetails[0].Coordinate.Longitude),
                                                                          item.ItemSummary.Distance,
                                                                          null,
                                                                          item.ItemSummary.TimeInSeconds,
                                                                          warnings,
                                                                          hints));
                        }

                        m_route.RouteLegs.push(new VERouteLeg(m_veLatLongFactory.CreateVELatLong(leg.ActualStart.Latitude, leg.ActualStart.Longitude),
                                                              m_veLatLongFactory.CreateVELatLong(leg.ActualEnd.Latitude, leg.ActualEnd.Longitude),
                                                              leg.LegSummary.Distance,
                                                              itinerary,
                                                              leg.LegSummary.TimeInSeconds));
                    }
                }
            }

        }


        if (m_route && m_route.RouteLegs && (m_route.RouteLegs.length > 0)) {
            if (m_routeOptions.DrawRoute) {
                var shapes = new Array();
                var stepIndex = 0;

                for (var routeLegIndex = 0; routeLegIndex < m_route.RouteLegs.length; ++routeLegIndex) {
                    var routeLeg = m_route.RouteLegs[routeLegIndex];
                    for (var itemIndex = 0; itemIndex < routeLeg.Itinerary.Items.length; ++itemIndex) {
                        var item = routeLeg.Itinerary.Items[itemIndex];
                        var shape = new VEShape(VEShapeType.Pushpin, item.LatLong);

                        if ((routeLegIndex == 0) && (itemIndex == 0)) {
                            shape.SetTitle(L_Start_Text);
                            shape.SetCustomIcon(Msn.VE.API.Constants.vedirectionsstarticon);
                        }
                        else if ((routeLegIndex == (m_route.RouteLegs.length - 1)) && (itemIndex == (routeLeg.Itinerary.Items.length - 1))) {
                            shape.SetTitle(L_End_Text);
                            shape.SetCustomIcon(Msn.VE.API.Constants.vedirectionsendicon);
                        }
                        else {
                            shape.SetTitle(L_DirectionsStep_Text + ' ' + stepIndex);
                            shape.SetCustomIcon(Msn.VE.API.Constants.vedirectionsstepicon.replace("%1", stepIndex));
                        }
                        shape.SetDescription(item.Text);
                        item.Shape = shape;
                        shapes.push(shape);
                        ++stepIndex;
                    }
                }

                m_routeShapeLayer = new VEShapeLayer();
                m_vemap.AddShapeLayer(m_routeShapeLayer);
                m_routeShapeLayer.AddShape(shapes);
            }

            if (object.RouteResult && object.RouteResult.RoutePath) {
                var rp = object.RouteResult.RoutePath;

                var shapePointLatitudes = m_routeDecoder.DecodeCoordinatesString(rp.ShapePointsLatitudes);
                var shapePointLongitudes = m_routeDecoder.DecodeCoordinatesString(rp.ShapePointsLongitudes);

                if (m_vemap.HasClientToken()) {
                    m_route.ShapePoints = new Array();
                    if (shapePointLatitudes.length == shapePointLongitudes.length) {
                        var len = shapePointLatitudes.length;
                        for (var i = 0; i < len; ++i) {
                            m_route.ShapePoints[i] = m_veLatLongFactory.CreateVELatLong(shapePointLatitudes[i], shapePointLongitudes[i]);
                        }
                    }
                }


                if (m_routeOptions.DrawRoute) {

                    if (m_routeOptions.SetBestMapView && rp.JavascriptBestView) {
                        var bestView = eval(rp.JavascriptBestView);
                        var latlongs = new Array();
                        for (var i = 0; i < bestView.length; ++i) {
                            latlongs.push(new VELatLong(bestView[i].latitude, bestView[i].longitude));
                        }
                        m_vemap.SetMapView(latlongs);
                    }

                    this.CreateRouteHighLight("veDDHighlight",
                                               shapePointLatitudes,
                                               shapePointLongitudes,
                                               eval(rp.JavascriptRouteRegions),
                                               eval(rp.JavascriptZoomLevelsForGeneralizedLines));
                }
            }
        }
        else {

            if (m_routeOptions.ShowErrorMessages) {
                m_vemap.ShowMessage(L_invalidroute_Text);
            }
        }

        if (m_routeOptions.RouteCallback) {
            m_routeOptions.RouteCallback(m_route);
        }
    }

    this.CreateRouteHighLight = function(id, lats, lons, regionsbyZoomLevel, zoomLevelsforGeneralizedLines) {

        if (m_routeHighlight) {
            this.RemoveRouteHighLight();
        }

        m_routeHighlight = m_vemap.vemapcontrol.AddLine(id,
                                                        lats,
                                                        lons,
                                                        m_routeOptions.RouteWeight,
                                                        m_routeOptions.RouteColor,
                                                        m_routeOptions.RouteZIndex,
                                                        regionsbyZoomLevel,
                                                        zoomLevelsforGeneralizedLines);
    }

    this.RemoveRouteHighLight = function() {
        if (m_routeHighlight) {
            m_vemap.vemapcontrol.RemoveLine(m_routeHighlight.id);
            m_routeHighlight = null;
        }
    }
    
   this.ClearRoute = function()
   {
      if(m_route)
      {
         if(m_routeShapeLayer)
         {
            m_vemap.DeleteShapeLayer(m_routeShapeLayer);
            m_routeShapeLayer = null;
         }
         for(var a = 0; a < m_route.RouteLegs.length; ++a)
         {
            var c = m_route.RouteLegs[a];
            for(var b = 0; b < c.Itinerary.Items.length; ++b)
            {
               var d = c.Itinerary.Items[b];
               if(d.Shape)d.Shape = null;
            }
         }
         m_route = null;
      }
      this.RemoveRouteHighLight();
   }   
}