var map		= Object();
var tooltip	= Object();

function GoogleMapsLoad() {

	if (GBrowserIsCompatible()) {
	
		// map aanmaken
		map = new GMap2(document.getElementById("google_maps_div"));
		map.setCenter(new GLatLng(50.882676, 5.85228), 10);
		
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
		
		tooltip						= document.createElement("div");
		map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);
		tooltip.style.visibility		="hidden";
	}
	
}


function GoogleMapsFindStreet(street){
	
	if (GBrowserIsCompatible()) {
		// straat zoeken
		if(street){
			
			// locatie bepalen
			var geo = new GClientGeocoder(); 
			geo.getLocations(street,	function (result){
											if (result.Status.code == G_GEO_SUCCESS){
												var p	= result.Placemark[0].Point.coordinates;
												map.addOverlay(new GMarker(new GLatLng(p[1],p[0])));
						
												// map centreren op straatmarker
												map.setCenter(new GLatLng(p[1],p[0]),13);
											}
										}
				
			);
			
		}
	}
}



function createMarker(point, message) {
	
	// basis icoon object aanmaken
	var baseIcon				= new GIcon();
	baseIcon.iconSize			= new GSize(18, 20);
	baseIcon.iconAnchor			= new GPoint(9, 20);
	baseIcon.infoWindowAnchor	= new GPoint(9, 20);
	var customIcon				= new GIcon(baseIcon);
	
	// custom image instellen
	customIcon.image	= "http://80.101.92.140/regiobranding/funda_test/img/funda_oranje_huisje.png";
	
	// array met custom marker options
	markerOptions		= {icon:customIcon};
	
	// marker object aanmaken
	var marker			= new GMarker(point, markerOptions);
	
	// tooltip
	marker.tooltip		= '<div class="tooltip"><nobr>'+message+'</nobr></div>';
	
	// onclick listener voor de marker
	GEvent.addListener(marker, "click", function() {
		//window.location = gotoURL;
	});
	
	// rollover listener voor de marker
	GEvent.addListener(marker, "mouseover", function() {
		//marker.setImage("http://www.zichtopmaastricht.nl/googlemaps/img/icoon_0.png");
		showTooltip(marker);
	});
	
	// rollout listener voor de marker
	GEvent.addListener(marker, "mouseout", function() {
		//marker.setImage(customIcon.image);
		tooltip.style.visibility="hidden";
	});
	
	// output
	return marker;
}








function showTooltip(marker) {
	tooltip.innerHTML			= marker.tooltip;
	var point					= map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	var offset					= map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor					= marker.getIcon().iconAnchor;
	var width					= marker.getIcon().iconSize.width;
	var height					= tooltip.clientHeight;
	var pos						= new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	
	pos.apply(tooltip);
	tooltip.style.visibility	= "visible";
}
