var map = null;
var geocoder = null;

function showtime(lijn) {
	tmpPars = 'ajax=time&lijn=' + lijn +'&';
	tmpPars = tmpPars + $('frmtijden').serialize();
//	alert(tmpPars);

	var myAjax = new Ajax.Updater('vertrektijden', '/', {method: 'post', parameters: tmpPars, evalScripts: true});
}		
		
function showvertrektijden(lijn) {
	tmpPars = 'ajax=vertrek&lijn=' + lijn;
	var myAjax = new Ajax.Updater('vertrektijden', '/', {method: 'post', parameters: tmpPars, evalScripts: true});
	
	if($('vertrektijden').style.display == 'none') {
		$('div_vertrektijden').toggle();
		$('vertrektijden').toggle();
	}
}		

function initialize() {
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder(); 
		map = new GMap2(document.getElementById("map_canvas"));
		
		map.setCenter(new GLatLng(51.693, 5.30), 13);
    map.addControl(new GMapTypeControl());		
//		map.addControl(new GSmallMapControl());
		
		// Controllers
		/*var mapTypeControl = new GMapTypeControl();
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
		var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
		map.addControl(mapTypeControl, topRight);
		GEvent.addListener(map, "dblclick", function() {
			map.removeControl(mapTypeControl);
			map.addControl(new GMapTypeControl(), bottomRight);
		});
		map.addControl(new GSmallMapControl(), bottomRight);*/
		//- Controllers
		
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);

		// Creates a marker whose info window displays the letter corresponding
		// to the given index.
		function createMarker(point, vestiging) {
			// Create a lettered icon for this point using our icon class
			var letteredIcon = new GIcon(baseIcon);
			letteredIcon.image = "http://www.drt.nl/fileadmin/images/maps/" + vestiging + ".png";

			// Set up our GMarkerOptions object
			markerOptions = { icon:letteredIcon };
			var marker = new GMarker(point, markerOptions);
			GEvent.addListener(marker, "click", function() {
			 marker.openInfoWindowHtml(myHtml);
			});
			return marker;
		}
	}
}

function placeMarker(address, title, url, image) {
	setTimeout("doPlaceMarker('" + address + "', '" + title + "', '" + url + "', '" + image + "')", 3000);
}

function doPlaceMarker(address, title, html, image) {
	var icon = new GIcon();
	//alert( "http://www.drt.nl/fileadmin/images/maps/" + image + ".png" );
	icon.image = "http://www.drt.nl/fileadmin/images/maps/" + image + ".png";
	icon.shadow = "http://www.royalgrass.eu/_pgTemplates/roottemplate/images/shadow.png";
	icon.iconSize = new GSize(14, 23);
	icon.shadowSize = new GSize(30, 30);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	
	if (address == 'STATIONDENBOSCH') {
			point = new GLatLng(51.690620, 5.293650);
			
			var marker = new GMarker(point, { title: title, icon: icon } );
			
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(html);
			});
			
			map.addOverlay(marker);
	} else {
		if (geocoder) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
					} else {
						var marker = new GMarker(point, { title: title, icon: icon } );
						
						GEvent.addListener(marker, "click", function() {
							marker.openInfoWindowHtml(html);
						});
						
						map.addOverlay(marker);
					}
				}
			);
		}			
	}
	
}