
  $(function() {
    
    // Liste ausblenden
    $('.boxlefttext ul').hide('slow');

    $('.boxselect').toggle(function() {
      $(this).next('ul').show('slow');
      
    }, function() {
      $(this).next('ul').hide('slow');
    });
    
    //klappboxen startseite
    $('.newsletter .contentwrap').hide();
    
    $('.newsletter h2').toggle(function() {
      
      $('.newsletter .contentwrap').show('fast');
      $('.newsletter h2').attr('class', 'minus');
      
    }, function() {
      $('.newsletter .contentwrap').hide('fast');
      $('.newsletter h2').attr('class', 'plus');
    });
    
    
    //klappboxen startseite
    $('.klappbox .contentwrap').hide();
    
    $('.klappbox h2').toggle(function() {
      
      $('.klappbox .contentwrap').show('fast');
      $('.klappbox h2').attr('class', 'minus');
      
    }, function() {
      $('.klappbox .contentwrap').hide('fast');
      $('.klappbox h2').attr('class', 'plus');
    });
    
    
    
    //suchformular
	
    $('#suchbegriff').click(function() {
    
        $(this).attr('class', 'active');
    });
    
  
    // Boxtoggle
    $('.boxtoogletext').hide();
    
    $('.boxtoogleheader').toggle(function() {
      $(this).next('.boxtoogletext').show('fast');
      $(this).attr('class', 'boxtoogleheader plus');
    }, function() {
      $(this).next('.boxtoogletext').hide('fast');
      $(this).attr('class', 'boxtoogleheader minus');      
    });

    // Boxtoggle
    $('.boxstart').hide();
    
    
    // Boxtoggle
    $('.themenwrap').hide();
    $('.thema1').show();
    
    $('.thementitel').click(function() {
      
      //alle ausblenden
      //$('.themenwrap').hide();
      
      //titel activ setzen
      $('.thementitel').attr('class', 'thementitel');
      $(this).attr('class', 'thementitel themaactiv');
      
      $('.themenwrap').hide();
      
      //text zeigen
      $(this).parent().next('.themenwrap').show();
      
      return false;
      
    });

  });
  
  
  
  
      
    
    //Die Googlemap
    var map;
    
    //Ein Bündel von Koordinaten
    var mapBounds;
    
    /*Koordinatenpunkte der BAW in den einzelnen Formaten
     * GPoint(Longitude,Latitute)
     * LatLngPoint(Latitude,Longitude)
     */
    var BAWGPoint;
    var BAWLatLngPoint;
    
    /*Koordinatenpunkte des Bahnhofs in Hameln in den einzelnen Formaten
     * GPoint(Longitude,Latitute)
     * LatLngPoint(Latitude,Longitude)
     */
    var HBGPoint;
    var HBLatLngPoint;
    
    //Die Overlaymarker (Fähnchen) auf der Googlemap)
    var bawMarker;
    var hbMarker;
    
    //Der geoCoder, für die Umwandlung von Adressstrings in Längen und Breitengrade
    var geocoder;
    
    //Wird benötigt um eine umfassende Routenbeschreibung zu generieren
    var directionsPanel;
    //Routen
    var directions;
    
    //Wo soll die Googlemap angezeigt werden ID des HTML-Elementes
    var ElementIDToDisplay='googlemap';
    
    /*
     * MakeGPoint erstellt einen GPoint (longitude,latitude)
     */
    function MakeGPoint(longitude,latitude)
    {
    	return gPoint = new GPoint(longitude,latitude);
    
    }
    /*
     * MakeGPoint erstellt einen LatLngPoint (latitude,longitude)
     */
    function MakeLatLngPoint(longitude,latitude)
    {
    	return LatLngPoint = new GLatLng( latitude,longitude);
    }
    
    /*
     * Setzt den GPoint und den LatLngPoint für die BAW
     */
    function SetBawPoints(longitude,latitude)
    {
    	BAWGPoint=MakeGPoint(longitude,latitude);
    	BAWLatLngPoint=MakeLatLngPoint(longitude,latitude);
    }
    /*
     * Setzt den GPoint und den LatLngPoint für den Bahnhof
     */
    function SetHbPoints(longitude,latitude)
    {
    	HBGPoint=MakeGPoint(longitude,latitude);
    	HBLatLngPoint=MakeLatLngPoint(longitude,latitude);
    }
    /*
     * erstellt anhand eines GPoint und eines html.Infotextes
     * einen Marker mit click-funktion
     */
    function CreateMarker(point,html)
    {
            var marker = new GMarker(point,html);
            GEvent.addListener(marker, "click", function() {
           	 marker.openInfoWindowHtml(html);
    			 });
    	return marker;
    }
    /*
     * ruft die CreatMarker(point,html)-function auf und fügt den erzeugten Marker
     * der map hinzu
     */
    function SetMarker(point,html)
    {
    	newMarker = CreateMarker(point,html);
    	map.addOverlay(newMarker);
    }
    

    /*
     * -initialisiert die Googlemap
     * -setzt die BAW-und HB-Punkte
     * -fügt die
     */
    function BuildMap(zoomLevel)
    {
    	 mapBounds= new GLatLngBounds();
    
    	 SetBawPoints(bawLongitude,bawLatitude);
         SetHbPoints(hbLongitude,hbLatitude);
    
     	 mapBounds.extend(BAWLatLngPoint);
       	 mapBounds.extend(HBLatLngPoint);
    	 map = new GMap2(document.getElementById(ElementIDToDisplay));
    	 map.enableScrollWheelZoom();
         map.enableContinuousZoom();
    	 map.setCenter(BAWLatLngPoint, bawZoomLevel);
    }
    function CenterMap(latlngPoint)
    {
    	map.setCenter(latlngPoint, bawZoomLevel);
    }
    function DrawRoutHB_BAW()
    {
    	DrawRoute(hbLatitude,hbLongitude);
    }
    function GeocodeAddress()
    {
    	var address=document.getElementById("street").value+ ' '+document.getElementById("streetnr").value+ ' '+document.getElementById("plz").value+ ' '+document.getElementById("location").value+ ' ';
    	geocoder = new GClientGeocoder();
    	geocoder.getLatLng(address, function(point)
    	{
          if (!point)
    	  	{
    			 if(address=='    ')
    			 {
    			 	alert(address + " Bitte geben Sie eine Gültige Adresse ein");
    			 }
    			 else
    			 {
    			 	alert("Die Adresse "+address + " wurde leider nicht gefunden.");
    			 }
    
    		}
    	else
    	{
    		var	startlongitude=point.lng();
    		var	startlatitude=point.lat();
    			DrawRoute(startlatitude,startlongitude);	}
        }
     );
    }
    
    function DrawRoute(startlatitude,startlongitude)
    {
    	  map.clearOverlays();
    	  directionsPanel = document.getElementById("advancedRoute");
    	  directionsPanel.innerHTML = '';
    	  directions = new GDirections(map, directionsPanel);
    	var fromPoint = MakeLatLngPoint(startlongitude,startlatitude);
    
    	  var arrLocation = new Array(2);
    			arrLocation[0] = fromPoint;
             	arrLocation[1] = BAWLatLngPoint;
    
    		  directions.clear();
              directions.loadFromWaypoints(arrLocation);
    		  GEvent.addListener(directions, "load", function()
    		   {
    		   	var distanz=directions.getDistance().meters;
    			var dauer=directions.getDuration().seconds;
    			var infoDistanz=directions.getDistance().html;
    			var infodauer=directions.getDuration().html;
    			var infoSummery=directions.getSummaryHtml();
    			document.getElementById("simpleRoute").innerHTML = infoSummery;
    
    
    
        });
    
    }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
