var map;
var gdir;
var geocoder = null;


    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(51.1100,13.9200), 14);
        geocoder = new GClientGeocoder();
        map.setMapType(G_HYBRID_MAP);
        // map.enableScrollWheelZoom();



        gdir = new GDirections(map, document.getElementById("Route"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

// setDirections("Bautzen", "Radeberg", "de"); 

       
    // A TextualZoomControl is a GControl that displays textual "Zoom In"
    // and "Zoom Out" buttons (as opposed to the iconic buttons used in
    // Google Maps).
    function TextualZoomControl() {
    }
    TextualZoomControl.prototype = new GControl();

    // Creates a one DIV for each of the buttons and places them in a container
    // DIV which is returned as our control element. We add the control to
    // to the map container and return the element for the map class to
    // position properly.
    TextualZoomControl.prototype.initialize = function(map) {
      var container = document.createElement("div");

      var zoomInDiv = document.createElement("div");
      this.setButtonStyle_(zoomInDiv);
      container.appendChild(zoomInDiv);
      zoomInDiv.appendChild(document.createTextNode("näher"));
      GEvent.addDomListener(zoomInDiv, "click", function() {
        map.zoomIn();
      });

      var zoomOutDiv = document.createElement("div");
      this.setButtonStyle_(zoomOutDiv);
      container.appendChild(zoomOutDiv);
      zoomOutDiv.appendChild(document.createTextNode("weiter"));
      GEvent.addDomListener(zoomOutDiv, "click", function() {
        map.zoomOut();
      });

      map.getContainer().appendChild(container);
      return container;
    }

    // By default, the control will appear in the top left corner of the
    // map with 7 pixels of padding.
    TextualZoomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(2, 2));
    }

    // Sets the proper CSS for the given button element.
    TextualZoomControl.prototype.setButtonStyle_ = function(button) {
      button.style.textDecoration = "none";
      button.style.color = "#000000";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "1px solid black";
      button.style.padding = "0px";
      button.style.marginBottom = "0px";
      button.style.textAlign = "center";
      button.style.width = "5em";
      button.style.cursor = "pointer";
    }
        
        
        // map.addControl(new GSmallMapControl());
        // map.addControl(new GMapTypeControl()); unten mit Positionierung
        
        var mapScale = new GScaleControl();
        var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(2,2));     
        map.addControl(mapScale, topLeft);
        
        var mapType = new GMapTypeControl();
        var BottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(2,2));     
        map.addControl(mapType, BottomRight);
     
        map.addControl(new TextualZoomControl());
        //map.addControl(new GOverviewMapControl());        
             
        
        // Add  lines to the map at  locations
map.addOverlay(yelwline(51.1249,13.9356,   51.1251,13.9351));
map.addOverlay(yelwline(51.1251,13.9351,   51.1257,13.9354));
map.addOverlay(yelwline(51.1257,13.9354,   51.1257,13.9363));
map.addOverlay(yelwline(51.1257,13.9363,   51.1250,13.9362));        
map.addOverlay(yelwline(51.1250,13.9362,   51.1220,13.9340));
map.addOverlay(yelwline(51.1220,13.9340,   51.1200,13.9330));
map.addOverlay(yelwline(51.1200,13.9330,   51.1181,13.9327));
map.addOverlay(yelwline(51.1181,13.9327,   51.1163,13.9332));
map.addOverlay(yelwline(51.1163,13.9332,   51.1136,13.9343));
map.addOverlay(yelwline(51.1136,13.9343,   51.1131,13.9348));
map.addOverlay(yelwline(51.1131,13.9348,   51.1127,13.9355));
map.addOverlay(yelwline(51.1127,13.9355,   51.1130,13.9361));
map.addOverlay(yelwline(51.1130,13.9361,   51.1134,13.9361));
// sternwarte
map.addOverlay(yelwline(51.1136,13.9343,   51.1131,13.9343));
map.addOverlay(yelwline(51.1131,13.9343,   51.1128,13.9337));
map.addOverlay(yelwline(51.1128,13.9337,   51.1132,13.9332));
map.addOverlay(yelwline(51.1132,13.9332,   51.1138,13.9333));

map.addOverlay(redline(51.1136,13.9343,   51.1068,13.9372));
map.addOverlay(redline(51.1068,13.9372,   51.1046,13.9383));


//pillnitzer bis löwen
map.addOverlay(redline(51.1006,13.9234,   51.0998,13.9235));
map.addOverlay(redline(51.0998,13.9235,   51.0996,13.9243));
map.addOverlay(redline(51.0996,13.9243,   51.0996,13.9246));
map.addOverlay(redline(51.0996,13.9246,   51.1006,13.9279));
map.addOverlay(redline(51.1006,13.9279,   51.1030,13.9312));
map.addOverlay(redline(51.1030,13.9312,   51.1036,13.9332));
map.addOverlay(redline(51.1036,13.9332,   51.1034,13.9376));

//einmünd löwen
map.addOverlay(redline(51.1034,13.9376,   51.1044,13.9382));
map.addOverlay(redline(51.1034,13.9376,   51.1032,13.9381));

//löwen bis radeberger
map.addOverlay(redline(51.1046,13.9383,   51.0912,13.9375));

//radeberger bis erksdorfer
map.addOverlay(redline(51.0912,13.9375,   51.0911,13.9375));


// erksdorfer bis baum
map.addOverlay(redline(51.0911,13.9375,   51.0876,13.9370));

// am baum
map.addOverlay(redline(51.0876,13.9370,   51.0808,13.9375));

//löwenbrücke unten
map.addOverlay(yelwline(51.0979,13.9418,   51.0991,13.9402));
map.addOverlay(yelwline(51.0991,13.9402,   51.1027,13.9398));
map.addOverlay(yelwline(51.1027,13.9398,   51.1042,13.9402));
map.addOverlay(yelwline(51.1042,13.9402,   51.1049,13.9396));
map.addOverlay(yelwline(51.1049,13.9396,   51.1052,13.9380));
map.addOverlay(yelwline(51.1052,13.9380,   51.1049,13.9332));



// molkerei

map.addOverlay(redline(51.0779,13.9362,   51.0786,13.9357));
map.addOverlay(redline(51.0786,13.9357,   51.0799,13.9344));
map.addOverlay(redline(51.0786,13.9357,   51.0808,13.9375));
map.addOverlay(redline(51.0808,13.9375,   51.0801,13.9376));
map.addOverlay(redline(51.0801,13.9376,   51.0796,13.9384));
map.addOverlay(redline(51.0796,13.9384,   51.0787,13.9374));
map.addOverlay(redline(51.0787,13.9374,   51.0786,13.9366));
map.addOverlay(redline(51.0786,13.9366,   51.0779,13.9362));

// einmündung rossendorf
map.addOverlay(redline(51.0779,13.9362,   51.0731,13.9334));


        // Add  markers to the map at  locations
					
          var latlng = new GLatLng(51.1099,13.9196);  
          	map.addOverlay(createMarker(latlng, 'Wasserturm','bild/m_schill.jpg','von Pillnitzer Straße zu Schiller-Straße'));
          	
          var latlng = new GLatLng(51.1141,13.9138);  
           map.addOverlay(createMarker(latlng, 'Radeberger Exportbier-Brauerei','bild/m_brau.jpg','von Bahnhofstraße zu Dresdener Straße'));
           
          var latlng = new GLatLng(51.1038,13.9075);  
           map.addOverlay(createMarker(latlng, 'Neubau Sporthalle','bild/m_sport1.jpg','Berufsschule Robert-Blum-Weg'));
           
          var latlng = new GLatLng(51.1056,13.9222);  
           map.addOverlay(createMarker(latlng, 'Kreisverkehr am Storchennest','bild/m_pill1.jpg','Pillnitzer Straße'));

          var latlng = new GLatLng(51.1010,13.9400);  
           map.addOverlay(createMarker(latlng, 'Neubau Umgehungsstraße Ost','bild/m_umg1.jpg','von Kleinwolmsdorf nach Radeberg'));
					
					var latlng = new GLatLng(51.1123,13.8970);  
           map.addOverlay(createMarker(latlng, 'Tankstelle West','bild/m_heide.jpg','von Elsa-Fenske-Straße nach Heidestraße'));           

					var latlng = new GLatLng(51.1225,13.9176);  
           map.addOverlay(createMarker(latlng, 'Gaststätte Lindenhof','bild/m_lind1.jpg','von Bad-Straße nach Lotzdorfer Straße'));           

      }
    }
    
   function showAddress(address) {
  	// alert('in showaddress / init.js');
  	
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");

            } else {
              //var map = new GMap2(document.getElementById("map_canvas"));
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }