//	map tilenames additional tile layer

var mapGlobals=new Object;

function createMap()
{
	CustomGetTileUrl=function(a,b)
	{
		return '/cgi-bin/return_tile.cgi?tm='+Math.random()+'&id='+fl_id+'&z='+b+'&x='+a.x+'&y='+a.y;
	}
		
	if (GBrowserIsCompatible())
	{
		mapGlobals.map=new GMap2(document.getElementById('map'));
		mapGlobals.map.addControl(new GSmallMapControl());
		mapGlobals.map.addControl(new GMapTypeControl());
//		mapGlobals.map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,7)));
//		mapGlobals.map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7,7)));
		mapGlobals.map.addControl(new GOverviewMapControl());
		mapGlobals.map.addControl(new GScaleControl());
		
		var mapTypes = mapGlobals.map.getMapTypes();
		for (var i = 0; i < mapTypes.length; i++) {
			mapTypes[i].getMinimumResolution = function() {
				return 7;
			}
			mapTypes[i].getMaximumResolution = function() {
				return 11;
			}
		}		
		
//		mapGlobals.map.zoomLevelOffset = 8;
//		mapGlobals.map.numZoomLevels = 5;
//		var controlHtml='<div id="toggleButton" onClick="javascript:setTilenameVisibility(mapGlobals.tilenameOverlay.isVisible)">&nbsp;</div>';
//		mapGlobals.map.addControl(new HtmlControl(controlHtml), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7,35)));

		var copyright=new GCopyright(1,new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180)),0,"c2006 Ebeling Data");
		var copyrightCollection = new GCopyrightCollection('Tilename layer: ');
		copyrightCollection.addCopyright(copyright);
		var tilelayer=new GTileLayer(new GCopyrightCollection(),0,17);
		tilelayer.getOpacity = function() {return 0.5;} 
		tilelayer.getTileUrl=CustomGetTileUrl;
		mapGlobals.tilenameOverlay=new GTileLayerOverlay(tilelayer);
		mapGlobals.map.setCenter(new GLatLng(58.88194208135912, 25.46630859375),7,G_NORMAL_MAP);
		mapGlobals.tilenameOverlay.isVisible=true;
		mapGlobals.map.addOverlay(mapGlobals.tilenameOverlay);		
//		setTilenameVisibility();
	}
	else
	{
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
}

function setTilenameVisibility()
{
	if (mapGlobals.tilenameOverlay.isVisible)
	{
		document.getElementById('toggleButton').innerHTML='<b>Hide</b> tilenames';
		mapGlobals.map.addOverlay(mapGlobals.tilenameOverlay);
	}
	else
	{
		document.getElementById('toggleButton').innerHTML='<b>Show</b> tilenames';
		mapGlobals.map.removeOverlay(mapGlobals.tilenameOverlay);
	}
	mapGlobals.tilenameOverlay.isVisible=!mapGlobals.tilenameOverlay.isVisible;
}


function HtmlControl(html)
{
	this.html=html
}
HtmlControl.prototype=new GControl();
HtmlControl.prototype.initialize=function(map)
{
	var container=document.createElement("div");
	var extra=document.createElement("div");
	extra.innerHTML=this.html;
	container.appendChild(extra);
	map.getContainer().appendChild(container);
	return container;
}
HtmlControl.prototype.getDefaultPosition=function()
{
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,7));
}

