var map, Map = Class.create();
Map.prototype = {
	initialize: function(){
		this.map = new GMap2($('map'));
		this.map.addControl(new GSmallMapControl());
		this.map.addControl(new GMapTypeControl());
		
		this.directions_plan = false;
		
		this.set_icon();
	},

	plan: function(){
		address = $('route_address').value;
		city = $('route_city').value;
		
		if(address == "" || city == ""){
			alert('U dient zowel uw adres als uw woonplaats in te vullen');
			return false
		}
		
		if(address != '') address += ', '

		$('form').hide();
		$('route').show();

		this.directions_plan = new GDirections(this.map, $('directions'));
		
		GEvent.addListener(this.directions_plan, "error", function(er){			
			if(map.directions_plan.getStatus().code == G_GEO_UNKNOWN_ADDRESS){
	     alert("Uw locatie kan niet gevonden worden. Specificeer uw locatie of probeer een omliggende straat.");
	     
	     	$('form').show();
				$('route').hide();
			}
	  			
		});
		
		this.directions_plan.load('from: ' + address + city + ' to: 52.630641,4.988694');
		
		
	},
	
	print: function(){
		print_window = window.open('/print_plan.html', 'route', 'width=600,height=400,scrollbars=yes,toolbar=no,location=no');
	},
	
	set_icon: function(){
		var icon = new GIcon();
		icon.image = "/images/page/map_marker.png";
		icon.iconSize = new GSize(46, 61);
		icon.iconAnchor = new GPoint(23, 60);

		point = new GLatLng(52.61568,4.742585);

		this.map.setCenter(point, 11);
		this.map.addOverlay(new GMarker(point, icon));
	},
	
	redo: function(){
		this.map = new GMap2($('map'));
		this.map.addControl(new GSmallMapControl());
		this.set_icon();
		
		$('form').show();
		$('route').hide();
	}
}