//////////////////////////////////////////////////
//////////			LOADER				//////////
//////////////////////////////////////////////////

			var mapa; 	// obiekt globalny
			var dymek; 	// okno z informacjami
			var markerBounds = new google.maps.LatLngBounds();
			var markery = [];
			
			/* by NucleON */
			var markersArray = new Array();
			var linesArray = new Array();
			/* NucleON end */
						
			function mapaStart()  
			{  
				var f = new google.maps.StyledMapType(naszaWisla,{name: "Wisła Warszawska"});
				var opcjeMapy = {
					zoom: 12,
    center: new google.maps.LatLng(52.235369, 21.00723),
    panControl: false,
    streetViewControl: false,
    scaleControl: false,
    zoomControl: true,
    	zoomControlOptions: {style: google.maps.ZoomControlStyle.SMALL},
    mapTypeControl: false,
    	mapTypeControlOptions: {
      mapTypeIds: ['wisla_warszawska']
    },
    scaleControl: true,
    mapTypeId: google.maps.MapTypeId.TERRAIN
				};
				mapa = new google.maps.Map(document.getElementById("mapka"), opcjeMapy); 			
				dymek = new google.maps.InfoWindow({maxWidth: 200});
				//mgr = new MarkerManager(map, { trackMarkers: true });
				mapa.mapTypes.set('wisla_warszawska', f);
  				mapa.setMapTypeId('wisla_warszawska');
				wczytajMarkery(0);

				
				pokazLinie();

				/* by NucleON */
				fnCheckAll();
				/* NucleON end */
				
			}  
			
			function pokazLinie()
			{
				var flightPlanCoordinates = [
    				new google.maps.LatLng(52.307429056485674, 20.901317596435547),
    				new google.maps.LatLng(52.308058799778266, 20.928783416748047),
    				new google.maps.LatLng(52.310367781878, 20.938396453857422),
    				new google.maps.LatLng(52.29525225869139, 20.958309173583984),
    				new google.maps.LatLng(52.29210254185819, 20.967578887939453),
    				new google.maps.LatLng(52.29042260129759, 20.974445343017578),
    				new google.maps.LatLng(52.281601868071434, 20.968608856201172),
    				new google.maps.LatLng(52.27488013068053, 20.964488983154297),
    				new google.maps.LatLng(52.27298945834894, 20.969295501708984),
    				new google.maps.LatLng(52.27151887966843, 20.97616195678711),
    				new google.maps.LatLng(52.270888616727646, 20.990581512451172),
    				new google.maps.LatLng(52.260172775665936, 21.00482940673828),
    				new google.maps.LatLng(52.22485521518378, 21.03435516357422),
    				new google.maps.LatLng(52.222331456635885, 21.04053497314453),
    				new google.maps.LatLng(52.20844822057699, 21.027488708496094),
    				new google.maps.LatLng(52.19413974159753, 21.025428771972656),
    				new google.maps.LatLng(52.18866763506749, 21.029376983642578),
    				new google.maps.LatLng(52.18172129908778, 21.023883819580078),
    				new google.maps.LatLng(52.169509957662804, 21.045856475830078),
    				new google.maps.LatLng(52.166561890233744, 21.046886444091797),
    				new google.maps.LatLng(52.13327730056333, 21.07675552368164),
    				new google.maps.LatLng(52.12948380634616, 21.07950210571289),
    				new google.maps.LatLng(52.12568998912527, 21.084308624267578),
    				new google.maps.LatLng(52.106926923415784, 21.103191375732422),
    				new google.maps.LatLng(52.101865868257214, 21.104564666748047),
    				new google.maps.LatLng(52.0946950569013, 21.117267608642578),
    				new google.maps.LatLng(52.09258577535003, 21.10696792602539)
  				];
  				var flightPath = new google.maps.Polyline({
    				path: flightPlanCoordinates,
    				strokeColor: "#000000",
    				strokeOpacity: 1.0,
    				strokeWeight: 2
  				});
				
				var flightPlanCoordinates2 = [
    				new google.maps.LatLng(52.37602883991884, 20.827503204345703),
    				new google.maps.LatLng(52.381257812715745, 20.830078125),
    				new google.maps.LatLng(52.385040311941175, 20.82956314086914),
    				new google.maps.LatLng(52.38168742091965, 20.838489532470703),
    				new google.maps.LatLng(52.385040311941175, 20.87179183959961),
    				new google.maps.LatLng(52.38399256084953, 20.881404876708984),
    				new google.maps.LatLng(52.38357345345041, 20.892391204833984),
    				new google.maps.LatLng(52.37895253000267, 20.905609130859375),
    				new google.maps.LatLng(52.369310952782655, 20.915908813476562),
    				new google.maps.LatLng(52.36365078582036, 20.917282104492188),
    				new google.maps.LatLng(52.34540753654635, 20.92620849609375),
    				new google.maps.LatLng(52.34520828772749, 20.919857025146484),
    				new google.maps.LatLng(52.35045139542743, 20.916767120361328),
    				new google.maps.LatLng(52.354016353467514, 20.912303924560547),
    				new google.maps.LatLng(52.37414248511109, 20.897541046142578),
    				new google.maps.LatLng(52.378124695208044, 20.874195098876953),
    				new google.maps.LatLng(52.37791511415524, 20.85153579711914),
    				new google.maps.LatLng(52.37245517662917, 20.837631225585938),
    				new google.maps.LatLng(52.37602883991884, 20.827503204345703)
  				];
  				var flightPath2 = new google.maps.Polyline({
    				path: flightPlanCoordinates2,
    				strokeColor: "#00FF00",
    				strokeOpacity: 1.0,
    				strokeWeight: 2
  				});
				
				var flightPlanCoordinates3 = [
    				new google.maps.LatLng(52.30664448892854, 20.948567390441895),
    				new google.maps.LatLng(52.309108352026065, 20.951786041259766),
    				new google.maps.LatLng(52.30460034936721, 20.959768295288086),
    				new google.maps.LatLng(52.29987143823677, 20.972728729248047),
    				new google.maps.LatLng(52.29630211453001, 20.986976623535156),
    				new google.maps.LatLng(52.290737595005695, 21.001052856445312),
    				new google.maps.LatLng(52.285807687024075, 21.00663185119629),
    				new google.maps.LatLng(52.27215438604768, 21.014528274536133),
    				new google.maps.LatLng(52.269423221073986, 21.016416549682617),
    				new google.maps.LatLng(52.25598028671048, 21.026973724365234),
    				new google.maps.LatLng(52.23673598420239, 21.04482650756836),
    				new google.maps.LatLng(52.229902301977944, 21.051177978515625),
    				new google.maps.LatLng(52.226432491437954, 21.054439544677734),
    				new google.maps.LatLng(52.22381418280505, 21.058902740478516),
    				new google.maps.LatLng(52.22234197323592, 21.063709259033203),
    				new google.maps.LatLng(52.22170049458683, 21.06679916381836),
    				new google.maps.LatLng(52.221385010200436, 21.069717407226562),
    				new google.maps.LatLng(52.221385010200436, 21.080703735351562),
    				new google.maps.LatLng(52.21981807184751, 21.090831756591797),
    				new google.maps.LatLng(52.21729402701764, 21.097698211669922),
    				new google.maps.LatLng(52.20824835508076, 21.112117767333984),
    				new google.maps.LatLng(52.17878456775253, 21.14267349243164),
    				new google.maps.LatLng(52.17478440582055, 21.14370346069336),
    				new google.maps.LatLng(52.1735158579721, 21.14619255065918),
    				new google.maps.LatLng(52.170146925462866, 21.148595809936523),
    				new google.maps.LatLng(52.16898353137633, 21.148681640625),
    				new google.maps.LatLng(52.162460593330586, 21.13348960876465),
    				new google.maps.LatLng(52.16814650107714, 21.12370491027832),
    				new google.maps.LatLng(52.170989182507434, 21.122331619262695),
    				new google.maps.LatLng(52.172252538177574, 21.120786666870117),
    				new google.maps.LatLng(52.18194233622542, 21.110401153564453),
    				new google.maps.LatLng(52.1850998804949, 21.106281280517578),
    				new google.maps.LatLng(52.19793825086294, 21.099071502685547),
    				new google.maps.LatLng(52.20171539256484, 21.097869873046875),
    				new google.maps.LatLng(52.20550273384939, 21.09598159790039),
    				new google.maps.LatLng(52.21307644807518, 21.091175079345703),
    				new google.maps.LatLng(52.21540089925979, 21.083965301513672),
    				new google.maps.LatLng(52.216873338933375, 21.074352264404297),
    				new google.maps.LatLng(52.217073165628314, 21.062335968017578),
    				new google.maps.LatLng(52.21528520486094, 21.049118041992188),
    				new google.maps.LatLng(52.225275827663275, 21.043624877929688),
    				new google.maps.LatLng(52.230217725853215, 21.04156494140625),
    				new google.maps.LatLng(52.23284617099531, 21.039676666259766),
    				new google.maps.LatLng(52.23526420307733, 21.037616729736328),
    				new google.maps.LatLng(52.23726160849132, 21.034870147705078),
    				new google.maps.LatLng(52.23915380439046, 21.032466888427734),
    				new google.maps.LatLng(52.24283284326017, 21.02731704711914),
    				new google.maps.LatLng(52.24630662744462, 21.02156639099121),
    				new google.maps.LatLng(52.250820563198644, 21.015987396240234),
    				new google.maps.LatLng(52.267217157292414, 21.001996994018555),
    				new google.maps.LatLng(52.28496760534678, 20.990495681762695),
    				new google.maps.LatLng(52.29126782967609, 20.977277755737305),
    				new google.maps.LatLng(52.29651733222359, 20.963544845581055),
    				new google.maps.LatLng(52.30103140682224, 20.954790115356445),
    				new google.maps.LatLng(52.30606458195414, 20.948009490966797)
  				];
  				var flightPath3 = new google.maps.Polyline({
    				path: flightPlanCoordinates3,
    				strokeColor: "#FF0000",
    				strokeOpacity: 1.0,
    				strokeWeight: 2
  				});
				
				
				
				
				var flightPlanCoordinates4 = [
					new google.maps.LatLng(52.2136023525097, 21.0922908782959),
					new google.maps.LatLng(52.2136023525097, 21.0922908782959),
					new google.maps.LatLng(52.21612660712861, 21.09675407409668),
					new google.maps.LatLng(52.218966222111995, 21.087656021118164),
					new google.maps.LatLng(52.2204385435938, 21.078214645385742),
					new google.maps.LatLng(52.22054370754621, 21.070661544799805),
					new google.maps.LatLng(52.22180565555089, 21.060190200805664),
					new google.maps.LatLng(52.224644907449935, 21.053667068481445),
					new google.maps.LatLng(52.22885087287482, 21.049375534057617),
					new google.maps.LatLng(52.2360000997402, 21.04233741760254),
					new google.maps.LatLng(52.24052034014666, 21.03959083557129),
					new google.maps.LatLng(52.24325328542475, 21.03529930114746),
					new google.maps.LatLng(52.26227412509487, 21.016159057617188),
					new google.maps.LatLng(52.28013157513134, 21.006546020507812),
					new google.maps.LatLng(52.29609214535315, 20.988693237304688),
					new google.maps.LatLng(52.29189255277229, 20.975990295410156),
					new google.maps.LatLng(52.28454230760411, 20.989723205566406),
					new google.maps.LatLng(52.27067852708942, 21.00139617919922),
					new google.maps.LatLng(52.256495174559696, 21.007747650146484),
					new google.maps.LatLng(52.240835688576325, 21.029977798461914),
					new google.maps.LatLng(52.2346334247983, 21.03753089904785),
					new google.maps.LatLng(52.22927144750417, 21.04353904724121),
					new google.maps.LatLng(52.22590673891199, 21.043710708618164),
					new google.maps.LatLng(52.22222629691692, 21.049718856811523),
					new google.maps.LatLng(52.21823004306726, 21.056928634643555),
					new google.maps.LatLng(52.21675764836974, 21.069974899291992),
					new google.maps.LatLng(52.217388680645534, 21.077356338500977),
					new google.maps.LatLng(52.215600732579105, 21.086111068725586),
					new google.maps.LatLng(52.2136023525097, 21.0922908782959)
				];
				
  				var flightPath4 = new google.maps.Polyline({
    				path: flightPlanCoordinates4,
    				strokeColor: "#FF8A0D",
    				strokeOpacity: 1.0,
    				strokeWeight: 2
  				});
				
				
				
				var flightPlanCoordinates5 = [
					new google.maps.LatLng(52.1631924311314, 21.150569915771484),
					new google.maps.LatLng(52.15561021529722, 21.16292953491211),
					new google.maps.LatLng(52.14254892668945, 21.174602508544922),
					new google.maps.LatLng(52.135806117266945, 21.183185577392578),
					new google.maps.LatLng(52.128008471364694, 21.185245513916016),
					new google.maps.LatLng(52.118312197617946, 21.191768646240234),
					new google.maps.LatLng(52.10798123761478, 21.20687484741211),
					new google.maps.LatLng(52.09132015855133, 21.221981048583984),
					new google.maps.LatLng(52.081193931677035, 21.217174530029297),
					new google.maps.LatLng(52.07423081775409, 21.21236801147461),
					new google.maps.LatLng(52.075707932681794, 21.202754974365234),
					new google.maps.LatLng(52.0835147282892, 21.208248138427734),
					new google.maps.LatLng(52.09891332083613, 21.20138168334961),
					new google.maps.LatLng(52.10270941733637, 21.195545196533203),
					new google.maps.LatLng(52.11156571943228, 21.185588836669922),
					new google.maps.LatLng(52.11578238794444, 21.180782318115234),
					new google.maps.LatLng(52.13306655935828, 21.16567611694336),
					new google.maps.LatLng(52.15624211595189, 21.14370346069336),
					new google.maps.LatLng(52.158769628869045, 21.13546371459961),
					new google.maps.LatLng(52.1631924311314, 21.150569915771484)
				];
				
  				var flightPath5 = new google.maps.Polyline({
    				path: flightPlanCoordinates5,
    				strokeColor: "#36D167",
    				strokeOpacity: 1.0,
    				strokeWeight: 2
  				});
				
				

				
  				flightPath.setMap(mapa);
  				flightPath2.setMap(mapa);
				flightPath3.setMap(mapa);
				flightPath4.setMap(mapa);
				flightPath5.setMap(mapa);
				
				/* by NucleON */
				linesArray.push(flightPath);
				linesArray.push(flightPath2);
				linesArray.push(flightPath3);
				linesArray.push(flightPath4);
				linesArray.push(flightPath5);
				/* NucleON end */
				
			}
			
			function wczytajMarkery(opt)
			{
				var c = 0;
				if(opt == 0)
				{
					jx.load('/mapa/mar.xml', function(xml)
					{
						markery = xml.getElementsByTagName("marker");
						for(var i=0; i<markery.length; i++)
						{
							//markery.kategoria = markery[i].attributes.getNamedItem("ikona").nodeValue;
							var lat			=	parseFloat(markery[i].attributes.getNamedItem("lat").nodeValue);
							var lon			=	parseFloat(markery[i].attributes.getNamedItem("lon").nodeValue);
							var ikona_url	=	markery[i].attributes.getNamedItem("ikona").nodeValue;
							var nazwa		=	markery[i].attributes.getNamedItem("nazwa").nodeValue;
							var opis		=	markery[i].attributes.getNamedItem("opis").nodeValue;
							var pid			=	parseFloat(markery[i].attributes.getNamedItem("PID").nodeValue);
							var marker		=	dodajMarker(lat,lon,ikona_url,nazwa,opis,pid);
							
							/* by NucleON */
							markersArray.push(marker);
							/* NucleON end */
							
							c++;
						}
					},'xml','get');
					//alert(c);
				}
				else
				{
					jx.load('/mapa/mar.xml', function(xml)
					{
						markery = xml.getElementsByTagName("marker");
						for(var i=0; i<markery.length; i++)
						{
							if(opt == markery[i].attributes.getNamedItem("ikona").nodeValue)
							{
								//markery.kategoria = markery[i].attributes.getNamedItem("ikona").nodeValue;
								var lat			=	parseFloat(markery[i].attributes.getNamedItem("lat").nodeValue);
								var lon			=	parseFloat(markery[i].attributes.getNamedItem("lon").nodeValue);
								var ikona_url	=	markery[i].attributes.getNamedItem("ikona").nodeValue;
								var nazwa		=	markery[i].attributes.getNamedItem("nazwa").nodeValue;
								var opis		=	markery[i].attributes.getNamedItem("opis").nodeValue;
								var pid			=	parseFloat(markery[i].attributes.getNamedItem("PID").nodeValue);
								var marker		=	dodajMarker(lat,lon,ikona_url,nazwa,opis,pid);
								
								/* by NucleON */
							    markersArray.push(marker);
							    /* NucleON end */
							}
						}
					},'xml','get');
				}
			}
			
			function ukryj()
			{
				//mapa.setMap(null);
				/*
				for (var k = 0; k < markery.length; k++) {
					markery[k].setMap(null);
				}
				*/
			}


				
			function dodajMarker(lat,lon,ikona_url,nazwa,opis,pid)
			{
                var rozmiar = new google.maps.Size(10,10);   
                var punkt_startowy = new google.maps.Point(0,0);   
                var punkt_zaczepienia = new google.maps.Point(5,5);   
                   
                var ikona = new google.maps.MarkerImage(ikona_url, rozmiar, punkt_startowy, punkt_zaczepienia); 
				
				var marker	=	new google.maps.Marker(
					{
						position: new google.maps.LatLng(lat,lon),
						title: nazwa,
						icon: ikona,
						map: mapa
					}
				);
				marker.txt	=	'<div id="MarkerTitle"><b>'+nazwa+'</b></div><br/><div id="MarkerOpis">'+opis+' <a href="./?f=otworz_artykul&id='+pid+'">więcej >></a></div><br/><img src="/mapa/co.png" height="16px" width="16px" alt="" align="left"/><div id="kompas"> '+lat+'°N, '+lon+'°E</div>';
				
				google.maps.event.addListener(marker,"click",function()
				{
					dymek.setPosition(marker.getPosition());
					dymek.setContent(marker.txt);
					dymek.open(mapa);
				});
				return marker;
			}
			
/* by NucleON */

function fnHideMarkers(par) {
  if (markersArray) {
    for (var i in markersArray) {
	  if(par=="" || markery[i].attributes.getNamedItem("ikona").nodeValue==par){
        markersArray[i].setMap(null);
	  }
    }
  }
}

function fnShowMarkers(par) {
  if (markersArray) {
    for (var i in markersArray) {
		if(par=="" || markery[i].attributes.getNamedItem("ikona").nodeValue==par){
			markersArray[i].setMap(mapa);
		}	
    }
  }
}

function fnHideLines(par) {
	if (linesArray) {
		for (var i in linesArray) {
			if (par=="" || linesArray[i].strokeColor.toUpperCase()==par.toUpperCase()) {
				linesArray[i].setMap(null);
			}
		}
	}
}


function fnShowLines(par) {
	if (linesArray) {
		for (var i in linesArray) {
			if (par=="" || linesArray[i].strokeColor.toUpperCase()==par.toUpperCase()) {
				linesArray[i].setMap(mapa);
			}
		}
	}
}

function fnCheckAll() {
        document.chkform.chk1.checked = true;
		document.chkform.chk2.checked = true;
		document.chkform.chk3.checked = true;
		document.chkform.chk4.checked = true;
		document.chkform.chk5.checked = true;
		document.chkform.chk6.checked = true;
		document.chkform.chk7.checked = true;
}

function fnCheckboxHandler() {
	if (document.chkform.chk1.checked == true){
		fnShowMarkers("ico.png");
	}else{
		fnHideMarkers("ico.png");
	}
	if (document.chkform.chk2.checked == true){
		fnShowMarkers("ico_b.png");
	}else{
		fnHideMarkers("ico_b.png");
	}
	if (document.chkform.chk3.checked == true){
		fnShowLines("#FF0000");
	}else{
		fnHideLines("#FF0000");
	}
	if (document.chkform.chk4.checked == true){
		fnShowLines("#00FF00");
	}else{
		fnHideLines("#00FF00");
	}
	if (document.chkform.chk5.checked == true){
		fnShowLines("#000000");
	}else{
		fnHideLines("#000000");
	}
	
	if (document.chkform.chk6.checked == true){
		fnShowLines("#FF8A0D");
	}else{
		fnHideLines("#FF8A0D");
	}
	if (document.chkform.chk7.checked == true){
		fnShowLines("#36D167");
	}else{
		fnHideLines("#36D167");
	}
}

/* NucleON end */

			
//////////////////////////////////////////////////
//////////			MAP STYLE			//////////
//////////////////////////////////////////////////

var naszaWisla = [
  {
    featureType: "water",
    elementType: "geometry",
    stylers: [
      { visibility: "on" },
      { saturation: 28 },
      { lightness: -8 },
      { gamma: 1.06 }
    ]
  },{
    featureType: "road.highway",
    elementType: "geometry",
    stylers: [
      { visibility: "on" },
      { lightness: 65 },
      { saturation: -100 },
      { gamma: 9.99 }
    ]
  },{
    featureType: "road.arterial",
    elementType: "geometry",
    stylers: [
      { gamma: 5.23 },
      { visibility: "on" },
      { saturation: -98 },
      { lightness: -8 }
    ]
  },{
    featureType: "road.local",
    elementType: "geometry",
    stylers: [
      { visibility: "on" },
      { saturation: -59 },
      { invert_lightness: true },
      { lightness: 98 },
      { gamma: 1.09 }
    ]
  },{
    featureType: "road.local",
    elementType: "labels",
    stylers: [
      { visibility: "on" },
      { saturation: -69 },
      { lightness: 59 }
    ]
  },{
    featureType: "road.arterial",
    elementType: "labels",
    stylers: [
      { saturation: -79 },
      { gamma: 1.31 },
      { visibility: "on" },
      { lightness: 34 }
    ]
  },{
    featureType: "road.highway",
    elementType: "labels",
    stylers: [
      { visibility: "on" },
      { saturation: -68 },
      { lightness: 61 },
      { gamma: 2.08 }
    ]
  },{
    featureType: "poi",
    stylers: [
      { visibility: "simplified" }
    ]
  },{
    featureType: "landscape.man_made",
    stylers: [
      { visibility: "on" },
      { hue: "#ff0000" },
      { invert_lightness: true },
      { lightness: 78 },
      { saturation: -98 },
      { gamma: 1.21 }
    ]
  },{
    featureType: "landscape.natural",
    elementType: "geometry",
    stylers: [
      { visibility: "on" },
      { lightness: 3 },
      { gamma: 1.21 },
      { saturation: -79 }
    ]
  }
];

