window.addEvent('domready', function(){

	if($('cwrap')){
		
		var NewDirections = new Element('div',{
			'id': 'directions'
		}).inject($('cwrap'), 'top');
	}

	var map;
	var gdir;
	var geocoder = null;

	if (GBrowserIsCompatible()) {
		function initialize(){
			gdir = new GDirections(map, document.getElementById("directions"));
		 	GEvent.addListener(gdir, "load", onGDirectionsLoad);
		 	GEvent.addListener(gdir, "error", handleErrors);
			
		}
		var map = new GMap2(document.getElementById("gmaps"));
		map.addMapType(G_PHYSICAL_MAP);
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(47.41812804, 13.68217349), 13);
		// Create our "tiny" marker icon
		var tinyIcon = new GIcon();
			tinyIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
			tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
			tinyIcon.iconSize = new GSize(12, 20);
			tinyIcon.shadowSize = new GSize(22, 20);
			tinyIcon.iconAnchor = new GPoint(6, 20);
			tinyIcon.infoWindowAnchor = new GPoint(5, 1);
		var point = new GLatLng(47.41812804, 13.68217349);
		var html= "<div style='font-family:Arial;font-size:12px;'><b>Hotel Almfrieden****<br />- Wander- und Langlaufhotel<br />- Romantikchalet</b><br /><br />Fam. Schrempf und Fam. Pilz<br />Leiten 47<br />A-8972 Ramsau am Dachstein</div>";
		var marker = new GMarker(point, tinyIcon);
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindowHtml(html);
		});
		map.addOverlay(marker);
	}

	$('submit_anreiseform').addEvent('submit', function(e){
		e.stop();
		gdir.load("from: " + $('fromAddress').value + " to: " + "Leiten 47, A-8972 Ramsau am Dachstein", { "locale": "de" });
	});
	$('fromAddress').addEvent('focus', function(){
		if($('fromAddress').value == "Strasse, Ort, Land"){
			$('fromAddress').value = "";
		}
	});
	$('fromAddress').addEvent('blur', function(){
		if($('fromAddress').value == ""){
			$('fromAddress').value = "Strasse, Ort, Land";
		}
	});

	function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("Bitte geben Sie den Startort für Ihre Route möglichst genau ein.\n\n z.B.: Leiten 47, 8972 Ramsau am Dachstein, Österreich");
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("Die Route konnte nicht berechnet werden");
	else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("Bitte geben Sie den Startort für Ihre Route möglichst genau ein.\n\n z.B.: Leiten 47, 8972 Ramsau am Dachstein, Österreich");
	else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	 alert("The given key is either invalid or does not match the domain for which it was given.");
	else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("Die Route konnte nicht berechnet werden");
	else alert("An unknown error occurred.");
	}
	function onGDirectionsLoad(){
		marker.remove();
	 // Use this function to access information about the latest load()
	 // results.

	 // e.g.
	 // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	 // and yada yada yada...
	}

	initialize();

	/*if($('gmaps_wrap')){
		var myMApEffect = new Fx.Morph('gmaps_wrap', {duration: 400, transition: Fx.Transitions.Sine.easeOut});
		$('gmaps_wrap').addEvent('mouseenter', function(){
			myMApEffect.start({
			    'height': 500
			});
		});
		$('gmaps_wrap').addEvent('mouseleave', function(){
			myMApEffect.start({
			    'height': 200
			});
		});
	}*/
});

