﻿    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        map.setCenter(new GLatLng(53,18.515284), 3);
        //setDirections("Mundsburg, Hamburg", "Heinrich-Hertz-Straße 115, Hamburg", "de_DE");
			
			var related = new GIcon();   
			related.image = '';  
			related.shadow = "/fileadmin/templates/images/map_logo_small.gif";
			related.iconSize = new GSize(16, 8);
			related.shadowSize = new GSize(16, 8);
			related.iconAnchor = new GPoint(8, 4);
			related.infoWindowAnchor = new GPoint(8, 4);
			
			var another = new GIcon();    
			another.image = '';  
			another.shadow = "";
			another.iconSize = new GSize(16, 8);
			another.shadowSize = new GSize(16, 8);
			another.iconAnchor = new GPoint(8, 4);
			another.infoWindowAnchor = new GPoint(8, 4);
				
			var point = new GLatLng(53.573588,10.024981);			
			var de = new GMarker(point,related);      
			GEvent.addListener(de, "click", function() {
				de.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON GmbH</strong></p><p>Heinrich-Hertz-Straße 115<br />22083 Hamburg<br />DEUTSCHLAND</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+49 40 22808-0<br />Email: <a href="mailto:info@transwaggon.de">info@transwaggon.de</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(de);
				
			var point = new GLatLng(56.050472,12.683887);			
			var se = new GMarker(point,related);      
			GEvent.addListener(se, "click", function() {
				se.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON AB</strong></p><p class="bodytext">Båthusgatan 13<br>25267 Helsingborg<br>SWEDEN</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+46 42 176200<br />Email: <a href="mailto:info@transwaggon.se">info@transwaggon.se</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(se);
				
			var point = new GLatLng(45.498361,9.202423);			
			var it = new GMarker(point,related);      
			GEvent.addListener(it, "click", function() {
				it.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON S.p.A.</strong></p><p class="bodytext">Via Costantino Corti, 1<br>20125 Milano<br>ITALY</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+39 02 6966901<br />Email: <a href="mailto:info@transwaggon.it">info@transwaggon.it</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(it);
				
			var point = new GLatLng(48.874496,2.353392);			
			var fr = new GMarker(point,related);      
			GEvent.addListener(fr, "click", function() {
				fr.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON S.A.S.</strong></p><p class="bodytext">16, rue Martel<br>75010 Paris<br>FRANCE</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+33 1 532 41680<br />Email:<a href="mailto:info@transwaggon.fr">info@transwaggon.fr</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(fr);
				
			var point = new GLatLng(47.172124,8.515284);			
			var ch = new GMarker(point,related);      
			GEvent.addListener(ch, "click", function() {
				ch.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON AG</strong></p><p class="bodytext">Gotthardstrasse 14<br>6304 Zug<br>SCHWEIZ</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+41 41 7294161<br />Email: <a href="mailto:info@transwaggon.ch">info@transwaggon.ch</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(ch);
			
			
			var point = new GLatLng(47.160745,9.476352);			
			var ch1 = new GMarker(point,another);      
			GEvent.addListener(ch1, "click", function() {
				ch1.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON AG</strong><br />Buchs</p><p class="bodytext">Churerstrasse 35<br>9470 Buchs<br>SCHWEIZ</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+41 81 7405646<br />Email: <a href="mailto:hartmann@transwaggon.ch">hartmann@transwaggon.ch</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(ch1);
				
			var point = new GLatLng(42.041134,14.355354);			
			var it1 = new GMarker(point,another);      
			GEvent.addListener(it1, "click", function() {
				it1.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON S.p.A</strong><br />Office Atessa</p><p class="bodytext">S. S. 154 Val di Sangro <br>66041	Atessa (Chieti)<br>ITALY</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+39 0872 897932<br />Email: <a href="mailto:info.atessa@transwaggon.it">info.atessa@transwaggon.it</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(it1);
			
			var point = new GLatLng(43.836508,10.508616);			
			var it2 = new GMarker(point,another);      
			GEvent.addListener(it2, "click", function() {
				it2.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>TRANSWAGGON S.p.A.</strong><br />Office Lucca</p><p class="bodytext">Via Lorenzo Nottolini, 442<br>55100 Lucca<br>ITALY</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+39 0583 464681<br />Email: <a href="mailto:marco.riccomini@transwaggon.it">marco.riccomini@transwaggon.it</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(it2);
			
			var point = new GLatLng(46.052744,14.5047);			
			var si = new GMarker(point,related);      
			GEvent.addListener(si, "click", function() {
				si.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>WAGGON SERVICE d.o.o.</strong></p><p class="bodytext">Kav&scaron;ekova ulica 14<br>1000 Ljubljana<br>SLOVENIA</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+386 1 2302850<br />Email: <a href="mailto:waggon.ljubljana@siol.net">waggon.ljubljana@siol.net</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(si);
				
				
			var point = new GLatLng(49.595483,17.249544);			
			var cz = new GMarker(point,related);      
			GEvent.addListener(cz, "click", function() {
				cz.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>WAGGON SERVICE s.r.o</strong></p><p class="bodytext">8. května 517/15<br>77200 Olomouc<br>CZECH REPUBLIC</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+420 585 204010<br />Email: <a href="mailto:info@waggonservice.cz">info@waggonservice.cz</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(cz);


			var point = new GLatLng(52.263771,20.993071);			
			var pl = new GMarker(point,related);      
			GEvent.addListener(pl, "click", function() {
				pl.openInfoWindowHtml('<div style="font-size: 10px; line-height: 1.1em;"><p><strong>WAGGON SERVICE sp. z.o.o.</strong></p><p class="bodytext">ul. Gwia&#378;dzista 7B/8<br>01-651 Warszawa<br>POLAND</p><p>Tel: &nbsp;&nbsp;&nbsp;&nbsp;+48 22 8699901<br />Email: <a href="mailto:info@waggonservice.pl">info@waggonservice.pl</a></p></div>');
				//document.location.href=content;
			});
      map.addOverlay(pl);
			
			
			
			
			/*
			var point = new GLatLng(56.050472,12.683887);
      var content = 'http://transwaggon.com/Schweden.35.0.html';
  		var image = "http://transwaggon.com/fileadmin/templates/images/map_logo_small.gif"; 
      map.addOverlay(createPoint(point, image, content));
			

			var point = new GLatLng(45.498361,9.202423);
      var content = 'http://transwaggon.com/Italien.36.0.html';
  		var image = "http://transwaggon.com/fileadmin/templates/images/map_logo_small.gif"; 
      map.addOverlay(createPoint(point, image, content));

			var point = new GLatLng(v);
      var content = 'http://transwaggon.com/Frankreich.37.0.html';
  		var image = "http://transwaggon.com/fileadmin/templates/images/map_logo_small.gif"; 
      map.addOverlay(createPoint(point, image, content));

			var point = new GLatLng(47.172124,8.515284);
      var content = 'http://transwaggon.com/Schweiz.38.0.html';
  		var image = "http://transwaggon.com/fileadmin/templates/images/map_logo_small.gif"; 
      map.addOverlay(createPoint(point, image, content));
			*/
      }

  function createPoint(point, image, content, w, h) {
    var related = new GIcon();   
    related.image = '';  
    related.shadow = image;
    if(!w) w = 16;
    if(!h) h = 8;
    // related.shadow = "http://www.secondcasa.com/img/marker_related_house.png";
    related.iconSize = new GSize(w, h);
    related.shadowSize = new GSize(w, h);
    related.iconAnchor = new GPoint(8, 4);
    related.infoWindowAnchor = new GPoint(0, 6);
    var marker = new GMarker(point,related);      
    GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(content);
			//document.location.href=content;
			});      
    return marker;
  }
    
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
