function goMap24()
{
	M24.init({
/*		appKey: "FJX6b65233be3379326c7fb3fc358db8X13",*/
		appKey: "FJXf893962bb200d11cfd518c81f52f9X13",
		mapArea: "maparea",
		width: 710,
		height: 500
	});

	addLocationWithTooltip();
}

function addLocationWithTooltip()
{
	var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl(map);
	mrcContainer.push(
		new Map24.Webservices.MRC.DeclareMap24Location({
			MapObjectID: "myLocation",
			Description: "none",
			Coordinate: new Map24.Coordinate(431.768, 3045.992),
			LogoURL: "http://www.kleintierpraxis-wygand.de/img/dot_orange.png",
			SymbolID: 20100,
			Events: new Array(
				new Map24.Webservices.MapObjectEvent({
					ID: "OnMouseOver",
					Commands: new Map24.Webservices.CommandsArray(
						new Map24.Webservices.MRC.DeclareMap24HTMLObject({
							MapObjectID: "myTooltip",
							Coordinate: new Map24.Coordinate(431.768, 3045.992),
							HTML: "<div style=\"width:220px;height:200px;overflow:hidden;font-family:arial;font-size:11;padding:0px;margin:0px;border:1px;background-color:#fffffe;\">"+
							"<div style=\"align:right;padding-top:7px;padding-right:5px;\">"+
							"<a href=\"control:disable\"><img src=\"http://devnet.map24.com/files/tooltip/tooltip_close.gif\" /></a>"+
							"</div>"+
							"<div style=\"padding-left:10px;align:left\"></div><div style=\"padding-left:10px;padding-top:3;padding-right:10x\">"+
							"<b>Kleintierpraxis Wygand</b>"+
							"<p>Am Kreuzeck 5-7<br />"+
							"Sankt Augustin</p>"+
							"<p><img src='http://www.kleintierpraxis-wygand.de/img/aussenansicht_mini.png' /></p>"+
							"</div>"+
							"</div>",
							Orientation: new Map24.Webservices.MapObjectOrientation({
								'Vertical':'TOP',
								'Horizontal':'RIGHT',
								'HOffset':0,
								'VOffset':0
							})
						}),
						new Map24.Webservices.MRC.ControlMapObject({
							Control: 'ENABLE',
							MapObjectIDs: 'myTooltip'
						})
					)
				}),
				new Map24.Webservices.MapObjectEvent({
					ID: "OnMouseOut",
					Commands: new Map24.Webservices.CommandsArray(
						new Map24.Webservices.MRC.ControlMapObject({
							Control: 'DISABLE',
							MapObjectIDs: 'myTooltip'
						})
					)
				})
			)
		})
	);
	
	new Map24.Webservices.MRC.DeclareMap24HTMLObject({
							MapObjectID: "myTooltip",
							Coordinate: new Map24.Coordinate(431.768, 3045.992),
							HTML: "<div style=\"width:220px;height:200px;overflow:hidden;font-family:arial;font-size:11;padding:0px;margin:0px;border:1px;background-color:#fffffe;\">"+
							"<div style=\"align:right;padding-top:7px;padding-right:5px;\">"+
							"<a href=\"control:disable\"><img src=\"http://devnet.map24.com/files/tooltip/tooltip_close.gif\" /></a>"+
							"</div>"+
							"<div style=\"padding-left:10px;align:left\"></div><div style=\"padding-left:10px;padding-top:3;padding-right:10x\">"+
							"<b>Kleintierpraxis Wygand</b>"+
							"<p>Am Kreuzeck 5-7<br />"+
							"Sankt Augustin</p>"+
							"<p><img src='http://www.kleintierpraxis-wygand.de/img/aussenansicht_mini.png' /></p>"+
							"</div>"+
							"</div>",
							Orientation: new Map24.Webservices.MapObjectOrientation({
								'Vertical':'TOP',
								'Horizontal':'RIGHT',
								'HOffset':0,
								'VOffset':0
							})
						})
	
						new Map24.Webservices.MRC.ControlMapObject({
							Control: 'ENABLE',
							MapObjectIDs: 'myTooltip'
						});

	mrcContainer.push(
		new Map24.Webservices.MRC.ControlMapObject({
			Control: 'ENABLE',
			MapObjectIDs: 'myLocation'
		})
	);

	mrcContainer.push(
		new Map24.Webservices.MRC.SetMapView({
			Coordinates: new Map24.Coordinate(431.750333, 3045.992),
			ClippingWidth: new Map24.Webservices.ClippingWidth({
				MinimumWidth: 1000
			})
		})
	);

	map.Webservices.sendRequest(mrcContainer);
}

var currentRouteID = "";

function startRouting(start, dest){
	M24.calculateRouteAddr({
		start: start,
		destination: dest,
		showRoute: true,
		onRoute: onRoute,
		language: "de"
	});
}

function startRoutingShortest(start, dest){
	M24.calculateRouteAddr({
		start: start,
		destination: dest,
		showRoute: true,
		onRoute: onRoute,
		language: "de",
		mode: "Shortest"
	});
}

function onRoute(routeRes){
	if(currentRouteID != '' && currentRouteID != 'undefined')
	removeRoute(currentRouteID);

	currentRouteID = routeRes.Info.RouteID;

	var res= new String("");
	res += "<h4>Routenbeschreibung</h4><table >";
	res += "<tr><td colspan='3'>Gesamtzeit: "+routeRes.TotalTime+" Minuten</td></tr>";
	res += "<tr><td colspan='3'>Gesamtdistanz: "+routeRes.TotalLength+" "+routeRes.TotalLengthUnit+"</td></tr>";

	for(var i=0; i < routeRes.RouteSegments.length;i++)
	{
		var segment = routeRes.RouteSegments[i];
		var sDirection = "";

		if(segment.Direction == "Straight") sDirection = "Geradeaus";
		if(segment.Direction == "Left") sDirection = "Links";
		if(segment.Direction == "Right") sDirection = "Rechts";

		res += "<tr><td>"+sDirection+" </td><td>"+segment.Description+"</td>";
		res += "<td>"+segment.CurrentTime+"<br/>"+ segment.CurrentLength+" "+segment.CurrentLengthUnit+"</td>"
		res += "</tr>";
	}

	res += "</table><p><small><a href='#top'>[Zum Seitenanfang]</a></small></p>";

	var resDiv = document.getElementById("resultDiv");
	resDiv.innerHTML = res;
}

function removeRoute(routeID){
	M24.removeObj(routeID);
}

function removeCurrentRoute(){
	removeRoute(currentRouteID);
	document.getElementById("resultDiv").innerHTML = "";
}

