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(23, 10);
  icon.shadowSize = new GSize(37, 34);
  icon.iconAnchor = new GPoint(9, 10);
  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 tamariki_icon = createGIcon("http://www.tamariki.at/templates/tamariki/pix/marker/tamariki_marker_google_style.png");
var tourstart_icon = createGIcon("http://www.google.com/intl/en_ALL/mapfiles/dd-start.png");
var green_icon = createGIcon("http://www.tamariki.at/templates/tamariki/pix/map_marker_green.png");
var blue_icon = createGIcon("http://www.tamariki.at/templates/tamariki/pix/marker/friends_marker.png");
tamariki_icon.iconSize = new GSize(19, 34);
tamariki_icon.iconAnchor = new GPoint(10, 35);
tamariki_icon.shadow = "http://www.google.com/intl/en_ALL/mapfiles/shadow50.png";


function loadMap() {
  if (GBrowserIsCompatible()) {

    
    // INIT MAP
    global_map = new GMap2(document.getElementById("map1"));
    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
    
    //CREATE GENERAL EWINDOW
    ew = new EWindow(map, E_STYLE_1);
		map.addOverlay(ew);
    
    // CREATE EWINDOWS FOR FRIENDS
    if (typeof(marker_f_max) != 'undefined') {
    	for (i = 1; i <= marker_f_max; i++) {
				eval("ew"+i+" = new EWindow(map, E_STYLE_7);");
   		 	eval("map.addOverlay(ew"+i+");");
    	} // for
    } // if
    
    // CREATE MY EWINDOW
    if (typeof(marker_me) != 'undefined') {
			ewme = new EWindow(map, E_STYLE_7);
			map.addOverlay(ewme);
		} // if

    // SET MARKERS
		if (typeof(marker) != 'undefined') {
      map.addOverlay(marker);
    } // if
    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+");");
        eval("ew"+i+".openOnMap(point_f_"+i+",html_f_"+i+");");
      } // for
    } // if
    if (typeof(marker_me) != 'undefined') {
      map.addOverlay(marker_me);
      ewme.openOnMap(point_me,html_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
    
    //CLOSE EWINDOW
    GEvent.addListener(map, "click", function(marker,point) {
		  if (point) {
		    ew.hide();
		  }
		});
 
    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

// This function just makes a pretty table for the EWindow contents
function pretty(a,b) {
  return '<div class="img"><img width="40" height="40" src="/blob/tn80x70_' + a +'" /><p><a href="/user/' + b +'">' + b + '</a></p></div>';
}

function stadtland(a,b) {
  return a + b;
}
    
function createMarker(point,html,icon, no_clickevent) {
  var marker = new GMarker(point,icon);
  // ========== Open the EWindow instead of a Google Info Window ==========
	if (!no_clickevent) {
		GEvent.addListener(marker, "click", function() {
      ew.openOnMarker(marker,html);
      map.setCenter(point, 6);
    });
	} 
  return marker;
}

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;
}
