function getMap()
{
	window.bounds = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34);
	
	if(othermap[0] != '')
	{
		/*
		if(othermap.length > 3)
		{
			window.bounds = new OpenLayers.Bounds(othermap[3], othermap[4], othermap[5], othermap[6]);	

			var maxres = 2;
			if(othermap[2] < 1000) maxres = 10;
			
			maxres = Math.round(20000000/2/(othermap[1]*othermap[2]));

			var options = { 
				projection: "EPSG:900913", 
				units: "m",
				maxResolution: maxres,
				maxExtent: window.bounds,
				restrictedExtent: window.bounds,
				numZoomLevels: 3,
				controls: []
			};
			
			var boundsimage = window.bounds;
		}
		else
		{
			var options = { 
				projection: "EPSG:900913", 
				units: "m",
				maxResolution: 50000,
				maxExtent: window.bounds,
				restrictedExtent: window.bounds,
				numZoomLevels: 3,
				controls: []
			};
			
			othermap[0] = 'images/maps/'+othermap[0];
			
		    var max = 14000000;
		    if(othermap[1] >= othermap[2])
		    {
				var otherside = max * othermap[2] / othermap[1];
				var boundsimage =  new OpenLayers.Bounds(-max, -otherside, max, otherside);
			}
			else
			{
				var otherside = max * othermap[1] / othermap[2];
				var boundsimage =  new OpenLayers.Bounds(-otherside, -max, otherside, max);
			}
			
		}
	
	    map = new OpenLayers.Map('map', options);
	    

		
		
	    
        var graphic = new OpenLayers.Layer.Image(
                            'Karte',
                            othermap[0],
                            boundsimage,
                            new OpenLayers.Size(othermap[1], othermap[2]),
                            options);
	                                
		map.addLayer(graphic);
		*/

		var myHeight = myWindowHeight();
		var myWidth = myWindowWidth();
	
		var resolutions = new Array();
		var numZoomLevel = 3;
		var boundsimage;
		
		if(othermap.length > 3)
		{
			boundsimage = new OpenLayers.Bounds(othermap[3], othermap[4], othermap[5], othermap[6]);
	
			var difWidth = othermap[5]-othermap[3];
			var difHeight = othermap[6]-othermap[4];
			
			window.bounds = new OpenLayers.Bounds(othermap[3]-(difWidth/2), othermap[4]-(difHeight/2), othermap[5]+(difWidth/2), othermap[6]+(difHeight/2));
	
			resolutions[0] = Math.max( difWidth / myWidth , difHeight / myHeight ) ;  // exakte bildschirmgröße
			resolutions[2] = difWidth / othermap[1]; // exakte bildgröße
			resolutions[1] = (resolutions[0]+resolutions[2])/2; // genau dazwischen
		}
		else
		{
	
			// mach bild halb so groß wie gesamte karte
		    var max = 10018754;
		    if(othermap[1] >= othermap[2])
		    {
		    	var mapWidth = max;
				var mapHeight = mapWidth * othermap[2] / othermap[1];
			}
			else
			{
				var mapHeight = max;
				var mapWidth = mapHeight * othermap[1] / othermap[2];
			}
			
			var boundsimage =  new OpenLayers.Bounds(-mapWidth, -mapHeight, mapWidth, mapHeight);
	
			resolutions[0] = Math.max( (2 * mapWidth / myWidth , 2 * mapHeight / myHeight) );  // exakte bildschirmgröße
			resolutions[2] = 2 * mapWidth / othermap[1] // exakte bildgröße
			resolutions[1] = ((resolutions[0]+resolutions[2])/2); // genau dazwischen
			
	
			if(window.trymorezoom)
			{
				numZoomLevel = 10;
				var steps = (resolutions[2]-resolutions[1])/5;
				
				for(var i=3; i<10; i++)
				{
					resolutions[i] = resolutions[2] + ((i-2) * steps);
				}
			}
			
			
			othermap[0] = 'images/maps/'+othermap[0];
		}

/*
		var done = false;
		done = getMapResolutions();
		
		while (!done) setTimeout(foo(), 100);
*/		
		var options = { 
			projection: "EPSG:900913", 
			units: "m",
//				maxResolution: 50000,
			resolutions: resolutions,
			maxExtent: boundsimage,
			restrictedExtent: window.bounds,
			numZoomLevels: numZoomLevel,
			controls: []
		};
		
		
	
	    map = new OpenLayers.Map('map', options);
	    
	    
        var graphic = new OpenLayers.Layer.Image(
                            'Karte',
                            othermap[0],
                            boundsimage,
                            new OpenLayers.Size(othermap[1], othermap[2]),
							options);
	                                
		map.addLayer(graphic);
		
	}
	else
	{
		var options = { 
			projection: "EPSG:900913", 
			units: "m", 
			maxResolution: 156543.0339, 
			maxExtent: window.bounds,
			numZoomLevels: 18,
			controls: []
		}; 
	
	    map = new OpenLayers.Map('map', options); 
		
		var mapmat2 = new Array();
		mapmat2[mapmat2.length] = getMapLayer(mapsfromdb[0]);
		if(mapsfromdb[1] != '') mapmat2[mapmat2.length] = getMapLayer(mapsfromdb[1]);
		
		map.addLayers(mapmat2);
		if(window.mapmat) mapmat = mapmat2;
		
		//map.addControl( new OpenLayers.Control.LayerSwitcher() );
	}
	
//	map.addControl( new OpenLayers.Control.PanZoom() );
	map.addControl( new OpenLayers.Control.Navigation() );
}

/*
function getMapResolutions()
{
	var myHeight = myWindowHeight();
	var myWidth = myWindowWidth();

	if(othermap.length > 3)
	{
		boundsimage = new OpenLayers.Bounds(othermap[3], othermap[4], othermap[5], othermap[6]);

		var difWidth = othermap[5]-othermap[3];
		var difHeight = othermap[6]-othermap[4];
		
		window.bounds = new OpenLayers.Bounds(othermap[3]-(difWidth/2), othermap[4]-(difHeight/2), othermap[5]+(difWidth/2), othermap[6]+(difHeight/2));

		resolutions[0] = Math.max( difWidth / myWidth , difHeight / myHeight ) ;  // exakte bildschirmgröße
		resolutions[2] = difWidth / othermap[1]; // exakte bildgröße
		resolutions[1] = (resolutions[0]+resolutions[2])/2; // genau dazwischen
	}
	else
	{

		// mach bild halb so groß wie gesamte karte
	    var max = 10018754;
	    if(othermap[1] >= othermap[2])
	    {
	    	var mapWidth = max;
			var mapHeight = mapWidth * othermap[2] / othermap[1];
		}
		else
		{
			var mapHeight = max;
			var mapWidth = mapHeight * othermap[1] / othermap[2];
		}
		
		var boundsimage =  new OpenLayers.Bounds(-mapWidth, -mapHeight, mapWidth, mapHeight);

		resolutions[0] = Math.max( (2 * mapWidth / myWidth , 2 * mapHeight / myHeight) );  // exakte bildschirmgröße
		resolutions[2] = 2 * mapWidth / othermap[1] // exakte bildgröße
		resolutions[1] = ((resolutions[0]+resolutions[2])/2); // genau dazwischen
		

		if(window.trymorezoom)
		{
			numZoomLevel = 10;
			var steps = (resolutions[2]-resolutions[1])/5;
			
			for(var i=3; i<10; i++)
			{
				resolutions[i] = resolutions[2] + ((i-2) * steps);
			}
		}
		
		
		othermap[0] = 'images/maps/'+othermap[0];
	}
	return true;
}
*/

function getMapLayer(map)
{
	switch(map)
	{
		case 'googlehybrid': return new OpenLayers.Layer.Google( "Google Hybrid", { type: G_HYBRID_MAP, 'sphericalMercator': true });
		case 'googlekarte': return new OpenLayers.Layer.Google( "Google Karte", { type: G_NORMAL_MAP, 'sphericalMercator': true });
		case 'googlesatellit': return new OpenLayers.Layer.Google( "Google Satellit", { type: G_SATELLITE_MAP, 'sphericalMercator': true });
		case 'virtualearthhybrid': return new OpenLayers.Layer.VirtualEarth( "Virtual Earth Hybrid", { type: VEMapStyle.Hybrid, 'sphericalMercator': true });
		case 'virtualearthkarte': return new OpenLayers.Layer.VirtualEarth( "Virtual Earth Karte", { type: VEMapStyle.Road, 'sphericalMercator': true });
		case 'virtualearthsatellit': return new OpenLayers.Layer.VirtualEarth( "Virtual Earth Satellit", { type: VEMapStyle.Aerial, 'sphericalMercator': true });
	}
	
	return null;
}

function includeMapJS(maps)
{
	if(othermap[0] == '')
	{
		var text0 = maps[0].substr(0, 4);
		var text1 = maps[1].substr(0, 4);
		
		if(text0 == 'goog' || text1 == 'goog') document.write('<'+'script src="js/gmapkey.js" type="text/javascript">' + '<' + '/script>');
		
		if(text0 == 'virt' || text1 == 'virt') document.write('<'+'script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js" type="text/javascript">' + '<' + '/script>');
	}
}

function changeMapSize()
{
	var _map = document.getElementById("map");
	if(_map.style.height == '300px') _map.style.height = '800px';
	else _map.style.height = '300px';
}

/* Rundet eine Zahl auf eine bestimmte Stellenzahl */
function roundNumber(Wert, Stellen)
{
	if (Wert == 0)
		return 0
	else
		with (Math) {
			// Bereinigung der Stellenzahl
			Stellen = floor(abs(Stellen))
			if (Stellen == 0) { Stellen = 1 }
	
			var Exponent = round(log(abs(Wert)) * LOG10E)
			if (abs(Wert) < pow(10, Exponent)) { Exponent-- }
			var Potenz = pow(10, 1 + Exponent - Stellen)
			return ((Wert < 0) ? "-" : "") + round(abs(Wert) / Potenz) * Potenz
		}
}