var map, geocoder

// creates a marker whose info window displays the letter corresponding to the given index.
function createMarker( point, index ) {

	// create a lettered icon for this point using our icon class
	var letter = String.fromCharCode( "A".charCodeAt( 0 ) + index );
	var letteredIcon = new GIcon( baseIcon );
	letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";

	// set up our GMarkerOptions object
	markerOptions = { icon:letteredIcon };
	var marker = new GMarker( point, markerOptions );

	GEvent.addListener( marker, "click",
		function() {
			marker.openInfoWindowHtml( "Marker <b>" + letter + "</b>" );
			}
		);

	return marker;
	}

function makeIcon ( image ) {
	var icon = new GIcon();
	icon.image = image;
//	icon.shadow = "images/shadow.png";
	icon.iconSize = new GSize( 30, 30 );
//	icon.shadowSize = new GSize( 24, 16 );
	icon.iconAnchor = new GPoint( 15, 15 );
//	icon.infoShadowAnchor = new GPoint( 0, 0 );
	icon.infoWindowAnchor = new GPoint( 15, 1 );
	return icon;
	}

function showAddress( address, info, iconFilename, tag ) {
	if ( geocoder ) {
		geocoder.getLatLng( address,
			function( point ) {
				if ( !point ) {
					alert( address + " kunne ikke findes" );
					}
				else {

					// no filename, use standard icon
					if( ! iconFilename ) {
						var marker = new GMarker( point, {title:tag} );
					}

					// filename is just a path, use standard icon
					else if( String( iconFilename ).substr( String( iconFilename ).length - 1, 1 ) == "/" ) {
						var marker = new GMarker( point, {title:tag} );
					}

					// real filename, use custom icon
					else {
						var ic = makeIcon( iconFilename );
						var marker = new GMarker( point, {icon:ic, title:tag} );
						}

					map.addOverlay( marker );
					GEvent.addListener( marker, "click",
						function() {
							marker.openInfoWindowHtml( info );
							}
						);
					}
				}
			);
		}
	}

function gmap_initialize( markers ) {
	if ( GBrowserIsCompatible() ) {
		map = new GMap2( document.getElementById( "gmd_canvas" ) );
		geocoder = new GClientGeocoder();
		map.setCenter( new GLatLng(56.26392, 9.501785), 6 ); // nice map of Denmark
		map.addControl( new GLargeMapControl() );
		map.addControl( new GMapTypeControl() );

		// set markers
		if( markers ) {
			markers.reverse();
			do {
				showAddress( markers.pop(), markers.pop(), markers.pop(), markers.pop() );
				}
				while ( markers.length > 0 );
			}

/*		var bounds = map.getBounds();
		map.setCenter( bounds.getCenter() );
		map.setZoom( map.getBoundsZoomLevel( bounds ) );
*/
		}
	}


