// JavaScript Document
 if (GBrowserIsCompatible()) {
      var side_bar_html = "";
      var gmarkers = [];
      var htmls = [];
      var i = 0;
	  var to_htmls = []; 
      
      // Create some custom icons
      
      // This icon uses the same shape as the default Google marker
      // So we can use its details for everything except the image 
      var blueIcon = new GIcon();
      blueIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/coldmarker.png";
      blueIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/shadow50.png"; 
      blueIcon.iconSize = new GSize(20, 34);
      blueIcon.shadowSize = new GSize(37, 34);
      blueIcon.iconAnchor = new GPoint(9, 34);
      blueIcon.infoWindowAnchor = new GPoint(9, 2);
      blueIcon.infoShadowAnchor = new GPoint(18, 25);
      

//esa
 	  var  greenIcon = new GIcon();
      greenIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/coldmarker_esa.png";
      greenIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/shadow50.png"; 
      greenIcon.iconSize = new GSize(20, 34);
      greenIcon.shadowSize = new GSize(37, 34);
      greenIcon.iconAnchor = new GPoint(9, 34);
      greenIcon.infoWindowAnchor = new GPoint(9, 2);
      greenIcon.infoShadowAnchor = new GPoint(18, 25);
     
     
	  
//ese
 	  var  eseIcon = new GIcon();
      eseIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/coldmarker_ese.png";
      eseIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/shadow50.png"; 
      eseIcon.iconSize = new GSize(20, 34);
      eseIcon.shadowSize = new GSize(37, 34);
      eseIcon.iconAnchor = new GPoint(9, 34);
      eseIcon.infoWindowAnchor = new GPoint(9, 2);
      eseIcon.infoShadowAnchor = new GPoint(18, 25);
     
      

//estg
 	  var  estgIcon = new GIcon();
      estgIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/coldmarker_estg.png";
      estgIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/shadow50.png"; 
      estgIcon.iconSize = new GSize(20, 34);
      estgIcon.shadowSize = new GSize(37, 34);
      estgIcon.iconAnchor = new GPoint(9, 34);
      estgIcon.infoWindowAnchor = new GPoint(9, 2);
      estgIcon.infoShadowAnchor = new GPoint(18, 25);
      
      

//esenf
 	  var  esenfIcon = new GIcon();
      esenfIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/coldmarker_esenf.png";
      esenfIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/shadow50.png"; 
      esenfIcon.iconSize = new GSize(20, 34);
      esenfIcon.shadowSize = new GSize(37, 34);
      esenfIcon.iconAnchor = new GPoint(9, 34);
      esenfIcon.infoWindowAnchor = new GPoint(9, 2);
      esenfIcon.infoShadowAnchor = new GPoint(18, 25);
     
     
	  			   
//esce
 	  var  esceIcon = new GIcon();
      esceIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/coldmarker_esce.png";

      esceIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/shadow50.png"; 
      esceIcon.iconSize = new GSize(20, 34);
      esceIcon.shadowSize = new GSize(37, 34);
      esceIcon.iconAnchor = new GPoint(9, 34);
      esceIcon.infoWindowAnchor = new GPoint(9, 2);
      esceIcon.infoShadowAnchor = new GPoint(18, 25);
      
     
	  
//sas
 	  var  sasIcon = new GIcon();
      sasIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/coldmarker_sas.png";
      sasIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/shadow50.png"; 
      sasIcon.iconSize = new GSize(20, 34);
      sasIcon.shadowSize = new GSize(37, 34);
      sasIcon.iconAnchor = new GPoint(9, 34);
      sasIcon.infoWindowAnchor = new GPoint(9, 2);
      sasIcon.infoShadowAnchor = new GPoint(18, 25);
  
    

      // This icon is a different shape, so we need our own settings       
      var fingerIcon = new GIcon();
      fingerIcon.image = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/finger.png";
      fingerIcon.shadow = "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/fingershadow.png";
      fingerIcon.iconSize = new GSize(20, 34);
      fingerIcon.shadowSize = new GSize(36, 34);
      fingerIcon.iconAnchor = new GPoint(5, 34);
      fingerIcon.infoWindowAnchor = new GPoint(5, 2);
      fingerIcon.infoShadowAnchor = new GPoint(14, 25);
      
      
      
      // An array of GIcons, to make the selection easier
      var icons = [];
      icons[0] = blueIcon;
      icons[1] = fingerIcon;
	  icons[2] = greenIcon;
	  icons[3] = eseIcon;
	  icons[4] = estgIcon;
	  icons[5] = esenfIcon;
	  icons[6] = esceIcon;
	  icons[7] = sasIcon;

      // the icon information is passed to this function
      function createMarker(point,name,html,icontype) {
        var marker = new GMarker(point,icons[icontype]);
		to_htmls[i] = html + '<span style="font-family: Arial, Helvetica, sans-serif; font-size: 10px;" > <br><b>Como Chegar</b>' +
           '<br>Insira o seu ponto de partida (ex: Porto, Portugal)</span><form action="http://maps.google.com/maps" method="get" target="_blank"> ' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Pesquisar" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  
           '"/>';
		   
	   html = html + '<a href="javascript:tohere('+i+')" style="font-family: Arial, Helvetica, sans-serif; font-size: 10px;">Descubra como chegar aqui</a>';
		
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        htmls[i] = html;
        // add a line to the side_bar html
        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        i++;
        return marker;
      }

      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }
	  
	  function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
      }

      var map = new GMap2(document.getElementById("map"));
	  var mapTypeControl = new GMapTypeControl();
	  var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,40));
      map.addControl(new GMapTypeControl());
      map.addControl (new GSmallMapControl(),topRight);
	  map.setCenter(new GLatLng(41.865470, -8.629761), 9);
	  map.addControl (new GScaleControl());
	  map.addControl (new GOverviewMapControl());


      // Read the data from custom.xml
      var request = GXmlHttp.create();
      request.open("GET", "http://portal.ipvc.pt/images/ipvc/ipvc/mapa/custom6.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            var icontype = parseInt(markers[i].getAttribute("icontype"));
            // create the marker
            var marker = createMarker(point,label,html,icontype);
            map.addOverlay(marker);
          }
          // put the assembled side_bar_html contents into the side_bar div
          document.getElementById("side_bar").innerHTML = side_bar_html;
        }
      }
      request.send(null);
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm
	// 