function createGIcon(url) {

  var icon = new GIcon();
  
  if (url == "") {
    icon.image = "http://www.google.com/intl/en_ALL/mapfiles/marker.png";
  } else {
    icon.image = url;
  } // if-else
  
  // VALUES FROM RED GOOGLE DEFAULT MARKER
  
  icon.shadow = "http://www.google.com/intl/en_ALL/mapfiles/shadow50.png";
  icon.iconSize = new GSize(20, 34);
  icon.shadowSize = new GSize(37, 34);
  icon.iconAnchor = new GPoint(9, 34);
  icon.infoWindowAnchor = new GPoint(9, 2);
  icon.printImage = "http://www.google.com/intl/en_ALL/mapfiles/markerie.gif";
  icon.mozPrintImage = "http://www.google.com/intl/en_ALL/mapfiles/markerff.gif";
  icon.printShadow = "http://www.google.com/intl/en_ALL/mapfiles/dithshadow.gif";
  icon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
  icon.imageMap = new Array(9, 0, 6, 1, 4, 2, 2, 4, 0, 8, 0, 12, 1, 14, 2, 16, 5, 19, 7, 23, 8, 26, 9, 30, 9, 34, 11, 34, 11, 30, 12, 26, 13, 24, 14, 21, 16, 18, 18, 16, 20, 12, 20, 8, 18, 4, 16, 2, 15, 1, 13, 0);
  
  return icon;
} // if


var red_icon = createGIcon("");
var tourstart_icon = createGIcon("http://www.google.com/intl/en_ALL/mapfiles/dd-start.png");
var green_icon = createGIcon("http://mamas.strg.at/templates/mamas/pix/map_marker_green.png");
var blue_icon = createGIcon("http://mamas.strg.at/templates/mamas/pix/map_marker_blue.png");


function loadMap() {
  if (GBrowserIsCompatible()) {
    
    // INIT MAP
    global_map = new GMap2(document.getElementById("map"));
    var map = global_map;
    
    map.enableDoubleClickZoom();
    map.enableContinuousZoom();
    if (typeof(zoomSlider) != 'undefined' && zoomSlider == true) {
      map.addControl(new GLargeMapControl());
    } // if
    if (typeof(viewSelection) == 'undefined' || viewSelection != false) {
      map.addControl(new GMapTypeControl());
    } // if
        
    // SET MAP POSITION
    if (typeof(bounds) != 'undefined') {
      map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
    } else if (typeof(point) != 'undefined') {
      map.setCenter(point, 13);
    } else {
      map.setCenter(new GLatLng(47.724545,13.557129), 6); // AUSTRIA :)
    } // if-elseif-else
    
    // SET MARKERS
    if (typeof(marker_max) != 'undefined') {
      for (i = 1; i <= marker_max; i++) {
        eval("map.addOverlay(marker_"+i+");");
      } // for
    } // if
    if (typeof(marker_f_max) != 'undefined') {
      for (i = 1; i <= marker_f_max; i++) {
        eval("map.addOverlay(marker_f_"+i+");");
      } // for
    } // if
    if (typeof(marker_me) != 'undefined') {
      map.addOverlay(marker_me);
    } // if
    
    // add marker on click event handler
    if (document.getElementById("hidden_location")) {
      GEvent.addListener(global_map, "click", 
        function(marker, point) {
          doOnClick(marker, point);
        }
      );
    } // if

    restoreControlMarker();
    
    if (typeof(waypoints) != 'undefined') {
      directions = new GDirections(global_map, {preserveViewport: true, locale:"de"});
      global_map.disableDoubleClickZoom();
    } // if
    
    if (typeof(linepoints) != 'undefined') {
      polyline = new GPolyline();
      global_map.disableDoubleClickZoom();
    } // if
    
    document.body.onunload = GUnload;
    
  } // if
  return;
} // function


function addFriendsToMap(friends_max) {
  for(i= 1; i <= friends_max; i++ ) {
    eval("global_map.addOverlay(marker_f_"+i+")");
  }
  document.getElementById("hide_friends").style.display = "inline";
  document.getElementById("show_friends").style.display = "none";
  return;
}


function removeFriendsFromMap(friends_max) {
  for(i= 1; i <= friends_max; i++ ) {
    eval("global_map.removeOverlay(marker_f_"+i+")");
  }
  document.getElementById("show_friends").style.display = "inline";
  document.getElementById("hide_friends").style.display = "none";
  return;
}


function restoreControlMarker() {
  if (typeof(location_complete) != 'undefined') {
    marker = new GMarker(point, {draggable: true});
    GEvent.addListener(marker, "dragstart", function(){
     global_map.closeInfoWindow();
    });
    GEvent.addListener(marker, "dragend", function(){
     marker_pos = marker.getPoint();
     tmp_long = marker_pos.lng();
     tmp_lat = marker_pos.lat();
     document.getElementById("location_longitude").value = tmp_long;
     document.getElementById("location_latitude").value = tmp_lat;
     document.getElementById(hidden_field).value = "";
     global_map.setCenter(marker_pos);
     marker.openInfoWindowHtml("<strong>"+location_complete+"</strong>")
    });
    global_map.setCenter(point, 13);
    global_map.addOverlay(marker);
    marker.openInfoWindowHtml("<strong>"+location_complete+"</strong>");
  } // if
  return;
}