var mapa;
var markery=[];

function otworzMarker(id){
	if(markery.length-1<id)
		return;
	if(markery[id].opis!="")
		markery[id].openInfoWindowHtml(markery[id].opis);
}

function initialize_map() {

	function dodajMarker(nazwa, wspolrzedne, opcje, chmurka, dodatki, klasa_css){
		var marker = new GMarker(wspolrzedne, opcje);
		marker.txt = nazwa;
		var tekst;
		if(chmurka==null){
			GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(marker.txt);});
			marker.opis = marker.txt;
		}	
		else{
			GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(chmurka);});
			marker.opis = chmurka;
			//marker.openInfoWindowHtml(chmurka);
		}	
		if(dodatki!=null){
			mapa.addOverlay(new Etykietka(dane));
		}
		else{
			mapa.addOverlay(marker);
		}
		marker.klasa_li = klasa_css;
		if(dodatki==null){
			markery.push(marker);
		}	
		return marker;
	}
	
	function Etykietka(dane){
		this.tekst = dane[0];
		this.punkt = dane[1];
		this.klasa = dane[2];
	};
	
	Etykietka.prototype = new GOverlay();

	Etykietka.prototype.initialize = function(mapa){
		var kontener = document.createElement("div");
		kontener.className = this.klasa;
		kontener.style.position = 'absolute';
		var span = document.createElement("span");
		span.innerHTML = this.tekst;
		kontener.appendChild(span);
		mapa.getPane(G_MAP_MAP_PANE).appendChild(kontener);
		
		this.mapa = mapa;
		this.kontener = kontener;	
	};

	Etykietka.prototype.remove = function()	{
		this.kontener.parentNode.removeChild(this.kontener);
	};

	Etykietka.prototype.copy = function(){
		return new Etykietka(this.punkt,this.tekst,this.klasa);
	};

	Etykietka.prototype.redraw = function(wymus){
		if (!wymus)
			return;
		this.kontener.style.top = (mapa.fromLatLngToDivPixel(this.punkt).y+3)+'px';
		this.kontener.style.left = mapa.fromLatLngToDivPixel(this.punkt).x+'px';
	}


	if (GBrowserIsCompatible()) {
		mapa = new GMap2(document.getElementById("map"));
		mapa.setCenter(new GLatLng(50.07, 19.25786), 11);
		mapa.setMapType(G_NORMAL_MAP);
		//Skala
		//mapa.addControl(new GScaleControl());
		//Pasek zoom
		mapa.addControl(new GLargeMapControl()); 
		// dodanie minimapy  
		//mapa.addControl(new GOverviewMapControl());
		// dodajemy kontrolkę
		//mapa.addControl(new GMapTypeControl());
		//Zoom z kólka myszy
		//mapa.enableScrollWheelZoom();
		
		//Kontroler na mapie
		mapa.hideControls();  
		GEvent.addListener(mapa, "mouseover", function(){mapa.showControls();});  
		GEvent.addListener(mapa, "mouseout", function(){mapa.hideControls();}); 
		
		//Wzor ikony ze wszystkimi parametrami
		var ikona_wzor = new GIcon();  
		ikona_wzor.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";  
		ikona_wzor.shadow = "http://labs.google.com/ridefinder/images/mm_20_green.png";  
		ikona_wzor.iconSize = new GSize(12, 20);  
		ikona_wzor.infoWindowAnchor = new GPoint(6,20);  
		ikona_wzor.iconAnchor = new GPoint(6,20);    
		ikona_wzor.shadowSize = new GSize(22, 20);
		

		//Ikony tworzone na podstawie wzoru
		var ikona = new GIcon(ikona_wzor);  
		ikona.image = "http://www.google.com/intl/en_ALL/mapfiles/marker.png";  
		ikona.shadow = "http://www.google.com/intl/en_ALL/mapfiles/shadow50.png";
		ikona.iconSize = new GSize(20, 34);  
		ikona.infoWindowAnchor = new GPoint(10,34);  
		ikona.iconAnchor = new GPoint(10, 34); 
		ikona.shadowSize = new GSize(37, 34);

		var chmurka=1;
		
		chmurka="<div class='opis_chm'><h2>Centrum Biznesu<br />Małopolski Zachodniej</h2>ul. Unii Europejskiej 10, 32-600 Oświęcim</div>";
		var m=dodajMarker('Oświęcim', new GLatLng(50.03125,19.25786), {title: 'Oświęcim', icon: ikona}, chmurka, null, '');
		m.openInfoWindowHtml(chmurka);


		// odswiezPasekBoczny();
	}
}
