protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            String idString = "";
            if (!NavigationContext.QueryString.TryGetValue("stopId", out idString))
            {
                Debug.WriteLine("No stop ID provided!");
                NavigationService.GoBack();
                return;
            }
            stopId = UInt32.Parse(idString);
            Debug.WriteLine("Stop id: " + stopId);

            OmnibussModel model = new OmnibussModel();
            Stop stop = model.GetStop(stopId);
            Panorama.Title = stop.Name;

            routeList.ItemsSource = routes = model.GetRoutesByStop(stop);

            addLocationPin(stop.Latitude, stop.Longitude, stop.Name);
            map1.Center = new GeoCoordinate((double)stop.Latitude, (double)stop.Longitude);
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            String stopIdStr, routeIdStr;
            if (!NavigationContext.QueryString.TryGetValue("stopId", out stopIdStr))
            {
                Debug.WriteLine("No stop ID provided!");
                NavigationService.GoBack();
                return;
            }

            if (!NavigationContext.QueryString.TryGetValue("routeId", out routeIdStr))
            {
                Debug.WriteLine("No route ID provided!");
                NavigationService.GoBack();
                return;
            }

            UInt32 stopId = UInt32.Parse(stopIdStr);
            Debug.WriteLine("Stop id: " + stopId);
            UInt32 routeId = UInt32.Parse(routeIdStr);
            Debug.WriteLine("Route id: " + routeId);

            OmnibussModel model = new OmnibussModel();

            Stop stop = model.GetStop(stopId);
            Route route = model.GetRoute(routeId);

            List<Stop_time> times = new List<Stop_time>();
            List<List<Stop>> stopsList = new List<List<Stop>>();

            ProgressIndicator progress = new ProgressIndicator();
            progress.IsVisible = true;
            progress.IsIndeterminate = true;
            SystemTray.SetProgressIndicator(this, progress);

            BackgroundWorker bgWorker = new BackgroundWorker();
            bgWorker.DoWork += new DoWorkEventHandler(
                (sender, args) =>
                {
                    for (int i = 0; i < 2; i++)
                    {
                        Trip trip = model.GetMaxTripByRoute(route, i);
                        if (trip != null)
                        {
                            Debug.WriteLine("TripID: " + trip.Trip_id);
                            List<Stop> stops = model.GetStopsByTrip(trip);
                            stopsList.Add(stops);
                        }
                    }

                    times.AddRange(model.GetTimesByRouteAndStop(route, stop));

                }
            );
            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                (sender, args) =>
                {
                    if (times.Count == 0)
                    {
                        NextTime.Text = "Kahjuks see liin täna rohkem ei sõida.";
                    }
                    else if (myLocation != null)
                    {
                        DateTime now = DateTime.Now;
                        int dep = (int)times[0].Departure_time;
                        int cur = (now.Hour * 10000 + now.Minute * 100 + now.Second);

                        double _diff = 0.0;
                        _diff += (dep % 100) - (cur % 100);
                        dep /= 100; cur /= 100;
                        _diff += ((dep % 100) - (cur % 100)) * 60;
                        dep /= 100; cur /= 100;
                        _diff += ((dep % 100) - (cur % 100)) * 3600;

                        double timeInHours = _diff / 3600.0;
                        // TEMP END

                        NextTime.Text = "Buss väljub järgnevatel aegadel:";
                        Location stopLocation = new Location();
                        stopLocation.Latitude = (double)stop.Latitude;
                        stopLocation.Longitude = (double)stop.Longitude;
                        double distanceKm = calculateDistance(myLocation, stopLocation);
                        string warningText = "";
                        if (distanceKm > (10 * timeInHours))
                        {
                            warningText = " (Sinna bussile sa enam ei jõua. Kurb)";
                        }
                        else if (distanceKm < (10 * timeInHours) && distanceKm > (5 * timeInHours))
                        {
                            warningText = " (Jookse, sa jõuad veel!)";
                        }
                        NextTime.Text = "Buss väljub järgnevatel aegadel" + warningText + ":";

                    }

                    var timesList = new List<String>();

                    foreach (var time in times)
                    {
                        String timeString = time.Departure_time.ToString();
                        String hours = timeString.Substring(0, timeString.Length > 5 ? 2 : 1);
                        String minutes = timeString.Substring(timeString.Length > 5 ? 2 : 1, 2);
                        timesList.Add(String.Format("{0,2:d2}:{1,2:d2}", hours, minutes));
                    }

                    schedule.ItemsSource = timesList;
                    foreach (var stops in stopsList)
                    {
                        GetRoute(stops);
                        foreach (var _stop in stops)
                        {
                            Pushpin pin = addLocationPin(_stop.Latitude, _stop.Longitude, _stop.Name);
                            int id = _stop.Id;

                            pin.MouseLeftButtonUp += new MouseButtonEventHandler(
                                (sender1, e1) =>
                                {
                                    NavigationService.Navigate(new Uri("/StopDetailsPanoramaPage.xaml?stopId=" + id, UriKind.Relative));
                                });
                        }
                    }
                    progress.IsVisible = false;
                }
            );
            bgWorker.RunWorkerAsync();

            Panorama.Title = route;

            var panoramaItem = Panorama.Items[0] as PanoramaItem;
            if (panoramaItem != null)
            {
                panoramaItem.Header = stop.Name;
            }
        }