var smallmap;
var gdir;
var geocoder = null;
var addressMarker;
var directions;

var showMaps = function(initLoc) {
	if(GBrowserIsCompatible()) {
		smallmap = new GMap2(document.getElementById('map'));
	
		smallmap.setCenter(new GLatLng(51.067871,4.355006),16);
		smallmap.addControl(new GLargeMapControl());
		//smallmap.addControl(new GSmallMapControl());
		smallmap.addControl(new GMapTypeControl());
		smallmap.enableDoubleClickZoom();
		smallmap.enableContinuousZoom();
		smallmap.enableScrollWheelZoom();
		
		geocoder = new GClientGeocoder();
		
		if(initLoc) {
			addAddress(initLoc);	
			showAddress(initLoc);
		}
	}
};



var createMarker = function(point, txt) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(txt);
	});
	
	return marker;
};

var setDirections = function(fromAddress, toAddress, locale) {
	gdir.load("from: " + fromAddress + " to: " + toAddress, {"locale": locale});
};


var showAddress = function(address) {
	if(geocoder) {
		geocoder.getLatLng(address, function(point) {
			if(point) {
				//map.setCenter(point, 14);
				smallmap.panTo(point);
			}
		});
	}
};

var addAddress = function(address,info) {
	if(geocoder) {
		geocoder.getLatLng(address, function(point) {							 
			if(point) {
				var marker = new GMarker(point);
				smallmap.addOverlay(marker);
				if(info) {
					GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowHtml(info);
					});
				}
			}
		});
	}
};
