// --------------------------------------------------
// google map routing callback
// --------------------------------------------------
// compute directions
function setDirections( fromAddress, toAddress )
{
	gdir.load( "from: " + fromAddress + " to: " + toAddress, {"locale": "de_DE" } );
}

// error handler
function handleErrors()
{
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("Adresse konnte nicht gefunden werden.\n Vielleicht ist sie zu neu\n, oder sie ist falsch.\n");
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		alert("Adresse konnte nicht gefunden werden.\n Der genaue Grund ist leider unbekannt.\n");
	else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		alert("Es wurde eine leere Adresse mitgegeben.\n Deshalb konnte keine Abfrage durchgeführt werden.\n");
	else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		alert("Der Lizenzschlüssel ist falsch oder passt nicht zur angegebenen URL. \n");
	else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		alert("Adresse konnte nicht richtig verarbeitet werden.\n");
	else alert("Unbekannter Fehler.");
}


// --------------------------------------------------
// switch languages
// --------------------------------------------------
function switchLang()
{
	var newUrl= $( "#langSelect :selected" ).val();
	$( "#langSelect" ).attr( "action", newUrl );
	document.langSelect.submit();
}


// --------------------------------------------------
// init
// --------------------------------------------------
$(document).ready( function()
{
    // init google maps
	if ( $("#map_canvas").length > 0 )
	{
		if( GBrowserIsCompatible() )
		{
			// map init
			var map= new GMap2( document.getElementById( "map_canvas" ) );
			map.setCenter( new GLatLng( 47.6337501, 8.6532578 ), 13 );
			
			// map controls
			map.enableScrollWheelZoom();
			var mapControl= new GMapTypeControl();
			map.addControl( mapControl );
			map.addControl( new GLargeMapControl() );
			map.addControl( new GOverviewMapControl() );
			
			// directional search
			gdir= new GDirections( map, document.getElementById( "map_route" ) );
			GEvent.addListener( gdir, "load", onGDirectionsLoad );
			GEvent.addListener( gdir, "error", handleErrors );
		}
	}
	
	// init lightbox
	$("a.zoomimg").lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.8,
		imageLoading: '/global/img/lightbox/loading.gif',
		imageBtnClose: '/global/img/lightbox/close.gif',
		imageBtnPrev: '/global/img/lightbox/prev.gif',
		imageBtnNext: '/global/img/lightbox/next.gif',
		containerResizeSpeed: 350,
		txtImage: '',
		txtOf: ' / '
	});

	// page unload callback
	$(window).unload( function ()
	{
		GUnload();
	});
});
