var map;
var maplogohref='http://www.besuperhero.pl';
var baseIcon = new GIcon();
baseIcon.iconSize=new GSize(25,25);
baseIcon.iconAnchor=new GPoint(16,19);
baseIcon.infoWindowAnchor=new GPoint(20,4);
baseIcon.shadow='show/map/markers/shadow.png';
baseIcon.shadowSize=new GSize(37,25);

var clickedPixel; 

// === functions that perform the context menu options ===
function contextCentreHere(){
	var point = map.fromContainerPixelToLatLng(clickedPixel);
	map.setCenter(point);
	contextmenu.style.visibility="hidden"; // hide the context menu
}
function contextLinkHere(){
	var point = map.fromContainerPixelToLatLng(clickedPixel);
	meet=1;
	addMeeting(point);
	contextmenu.style.visibility="hidden"; // hide the context menu
}
function contextNeighborhood(){
	var point = map.fromContainerPixelToLatLng(clickedPixel);
	document.getElementById('but_mynei').className='buttonselect';
	neighborhooda=point;
	myNeighborhood('0.5',neighborhooda);
	contextmenu.style.visibility="hidden"; // hide the context menu
}
// === create the context menu div ===
var contextmenu = document.createElement("div");
contextmenu.style.visibility="hidden";
contextmenu.style.background="#ffffff";
contextmenu.style.border="1px solid #8888FF";
contextmenu.innerHTML='<div class="context"><a href="javascript:contextNeighborhood()">Co tu jest?<\/a><\/div>'
	+ '<div class="context"><a href="javascript:contextLinkHere()">Link dla znajomych<\/a><\/div>'
	+ '<div class="context"><a href="javascript:contextCentreHere()">Wyśrodkuj mapę tutaj<\/a><\/div>';

function init(){
	if(GBrowserIsCompatible()){
		handleResize();
		addArrows(0,0,0,240);
		createDiv('map_msg',1,'none');

		map=new GMap2(document.getElementById("map"));
		var customUI = map.getDefaultUI();
		customUI.controls.scalecontrol=false;
		map.setUI(customUI); 
		//map.setUIToDefault();

		map.addControl(new MapLogo());
		map.setCenter(new GLatLng(centerlat,centerlon),startZoom);

		var MapTypes=map.getMapTypes();
		map.addMapType(mapMapnik); 
		MapTypes[4].getAlt=function(){return"OSM - Open Street Map";}

		map.enableGoogleBar();

		var mapScaleControl = new GScaleControl();
		var bottomLeft = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(3,40));
		map.addControl(mapScaleControl, bottomLeft);

		geocoder=new GClientGeocoder();
		gdir=new GDirections(map,document.getElementById('chdirection'));

		showUserPoint();
		showPlace();

		if(mod==1){showCrime();}
		else if(mod==2){MZK();}

		map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);

		//contextmenu
		map.getContainer().appendChild(contextmenu);
		GEvent.addListener(map,"singlerightclick",function(pixel,tile){
			clickedPixel = pixel;
			var x=pixel.x;
			var y=pixel.y;
			if (x > map.getSize().width - 120) { x = map.getSize().width - 120 }
			if (y > map.getSize().height - 100) { y = map.getSize().height - 100 }
			var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));  
			pos.apply(contextmenu);
			contextmenu.style.visibility = "visible";
		});
		GEvent.addListener(map, "click", function() {
			contextmenu.style.visibility="hidden";
		});
	}
	else{alert("Przepraszamy, ale Google Maps API nie jest kompatybilne z twoją przeglądarką.");}
}
window.onload=init;
window.onunload=GUnload;
