// the icon information is passed to this function
function createMarker(point,name,html,icons,gmarkers,htmls,icontype) {
 var marker = new GMarker(point,icons[icontype]);
 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 gmapUnload(){
 if (document.getElementById('shop_info') != null){
  GUnload();
 }
}

function gmapLoad(){
// questo try serve solo a non riportare l'errore di Gicon non esistente
// nel caso in cui non sia caricata la libreria di google per le mappe.
// if (document.getElementById('shop_info') != null){
try{
  var gmarkers = [];
  var htmls = [];
  var i =0;
  var icons = [];
  var blueIcon = new GIcon();
      blueIcon.image = "http://www.wuerth.it/images/google_maps_pin_wuerth.png";
      blueIcon.shadow = "http://www.wuerth.it/images/google_maps_pin_wuerth_shadow.png";
      blueIcon.iconSize = new GSize(50, 40);
      blueIcon.shadowSize = new GSize(50, 40);
      blueIcon.iconAnchor = new GPoint(10, 34);
      blueIcon.infoWindowAnchor = new GPoint(9, 2);
      blueIcon.infoShadowAnchor = new GPoint(18, 25);
      blueIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      blueIcon.printImage = "http://www.wuerth.it/images/google_maps_pin_wuerth.png";
      blueIcon.mozPrintImage = "http://www.wuerth.it/images/google_maps_pin_wuerth.png";
        
  icons[0] = blueIcon;
}catch(err){
}

 if (document.getElementById('shop_info') != null){
  if  (GBrowserIsCompatible()){
   var shop_lat=document.getElementById('shop_lat').value;
   var shop_lng=document.getElementById('shop_lng').value;
   var map = new GMap2(document.getElementById("map_placeholder"));    
   map.addControl(new GLargeMapControl());
   map.addControl(new GMapTypeControl());
   map.setCenter(new GLatLng(shop_lat,shop_lng), 15);
   // Aggiungi il marker alla mappa
   var marker = createMarker(new GLatLng(shop_lat, shop_lng),
                             'punto vendita',
                             document.getElementById('shop_info').innerHTML,
                             icons,
                             gmarkers,
                             htmls,
                             0)
   map.addOverlay(marker);
  }else {
   alert("Sorry, the Google Maps API is not compatible with this browser");
  }
 }
}