var a = [];
var i = [];

$(document).ready(
	function()
	{
		bindForm();
		makeMap();
		

	}
);

function makeMap()
{
if ($('#map').length > 0)
{
        $('#map').gmap(	{
        					'center': new google.maps.LatLng(52.0426606750, 5.8736160278), 
        					'zoom': 9,
        					'callback': function(map) 
        								{
								            $(map).click(	function(event) 
								            				{
								            					$("#map").gmap('clearMarkers');
												                $('#map').gmap('addMarker', {'position': event.latLng, 'title': '', 'bound': false})
												                							                
												                $("input[name=sLat]").val(event.latLng.lat());
												                $("input[name=sLong]").val(event.latLng.lng());
											                }
											);
										}
			            }
		);
}


if ($('#groepmap').length > 0)
{
        $('#groepmap').gmap(	{
        					'center': new google.maps.LatLng(52.0426606750, 5.8736160278), 
        					'zoom': 9,
        					'callback': function(map) 
        								{
        								//	if ($("input[name=sLat]").val() != '' && $("input[name=sLong]").val() != '')
        								//	{
        										var pos = new google.maps.LatLng($("input[name=sLat]").val(), $("input[name=sLong]").val());
        									
        									
												var x = $('#groepmap').gmap("addMarker", {	
																					'bounds': false,
																					'position': pos, 
																					'animation': google.maps.Animation.DROP
																				}
												);
										//	}
        								//	else
        								//	{
									            $(map).click(	function(event) 
									            				{
									            					$("#groepmap").gmap('clearMarkers');
													                $('#groepmap').gmap('addMarker', {'position': event.latLng, 'title': '', 'bound': false})
													                							                
													                $("input[name=sLat]").val(event.latLng.lat());
													                $("input[name=sLong]").val(event.latLng.lng());
												                }
												);
										//	}
										}
			            }
		);
}

if ($('#groepenmap').length > 0)
{
		var i = 0;		
		var map;
		var myOptions = {
							zoom:9,
							center: new google.maps.LatLng(52.0426606750, 5.8736160278),
							mapTypeId: google.maps.MapTypeId.ROADMAP
						};

		map = new google.maps.Map(document.getElementById('groepenmap'), myOptions);				
	
		var infowindow = new google.maps.InfoWindow(aMarkers[i][1]);
	
		for (var i = 0; i < aMarkers.length; i++)
		{
			a[i] = new google.maps.Marker({position: aMarkers[i][0], map: map, html: aMarkers[i][1]});
		}
		
		for (var i = 0; i < a.length; i++) 
		{
			var marker = a[i];
			google.maps.event.addListener(marker, 'click', function () {
					infowindow.setContent(this.html);
					infowindow.open(map, this);
			});
		}
		
		drawDeelgebieden(map);		
}

}

function drawDeelgebieden(map)
{
	var gebiedA =
	[
	new google.maps.LatLng(52.249665,5.4039),
	new google.maps.LatLng(52.271519,5.52887),
	new google.maps.LatLng(52.320232,5.556335),
	new google.maps.LatLng(52.362183,5.61676),
	new google.maps.LatLng(52.437595,5.806274),
	new google.maps.LatLng(52.516221,5.861206),
	new google.maps.LatLng(52.52207,5.877686),
	new google.maps.LatLng(52.475253,5.924377),
	new google.maps.LatLng(52.485289,5.955963),
	new google.maps.LatLng(52.477762,5.965576),
	new google.maps.LatLng(51.979805,5.689545),
	new google.maps.LatLng(51.977268,5.61676),
	new google.maps.LatLng(52.011091,5.585175),
	new google.maps.LatLng(52.009401,5.52063),
	new google.maps.LatLng(52.046579,5.50827),
	new google.maps.LatLng(52.054179,5.561829),
	new google.maps.LatLng(52.103975,5.553589),
	new google.maps.LatLng(52.078662,5.517883),
	new google.maps.LatLng(52.075286,5.472565),
	new google.maps.LatLng(52.086257,5.460205),
	new google.maps.LatLng(52.097226,5.487671),
	new google.maps.LatLng(52.112409,5.487671),
	new google.maps.LatLng(52.135174,5.506897),
	new google.maps.LatLng(52.168036,5.458832),
	new google.maps.LatLng(52.222752,5.39566),
	new google.maps.LatLng(52.248403,5.4039)
	];
	
	var polygonA = new google.maps.Polygon({
	paths: gebiedA,
	strokeColor: "#FF0000",
	strokeOpacity: 0.8,
	strokeWeight: 2,
	fillColor: "#FF0000",
	fillOpacity: 0.35
	});
	
	polygonA.setMap(map);
	
	//var marker = new google.maps.Marker({position:new google.maps.LatLng(52.08246,6.067886),	map: map});
	
	var gebiedB =
	[
	new google.maps.LatLng(52.476925,5.967636),
	new google.maps.LatLng(52.509535,6.028748),
	new google.maps.LatLng(52.477344,6.090546),
	new google.maps.LatLng(52.431734,6.120071),
	new google.maps.LatLng(52.407446,6.110458),
	new google.maps.LatLng(52.399067,6.131058),
	new google.maps.LatLng(52.381467,6.121445),
	new google.maps.LatLng(52.372665,6.079559),
	new google.maps.LatLng(52.36428,6.076813),
	new google.maps.LatLng(52.355474,6.094666),
	new google.maps.LatLng(52.352957,6.076813),
	new google.maps.LatLng(52.318133,6.06514),
	new google.maps.LatLng(52.312257,6.080933),
	new google.maps.LatLng(52.3047,6.081619),
	new google.maps.LatLng(52.299661,6.101532),
	new google.maps.LatLng(52.258912,6.126938),
	new google.maps.LatLng(52.251346,6.122818),
	new google.maps.LatLng(52.247142,6.138611),
	
	new google.maps.LatLng(52.247142,6.152344),
	new google.maps.LatLng(52.239574,6.144104),
	new google.maps.LatLng(52.231585,6.144104),
	new google.maps.LatLng(52.224435,6.159897),
	new google.maps.LatLng(52.230323,6.18187),
	new google.maps.LatLng(52.181511,6.183929),
	new google.maps.LatLng(52.146552,6.17157),
	new google.maps.LatLng(52.08246,6.067886),
	new google.maps.LatLng(52.0432,5.931244),
	new google.maps.LatLng(52.015317,5.920944),
	
	new google.maps.LatLng(52.016585,5.914764),
	new google.maps.LatLng(51.98451,5.913477),

	new google.maps.LatLng(51.936222,5.955276),
	new google.maps.LatLng(51.926222,5.955276),
	new google.maps.LatLng(51.980228,5.690918)
	];
//	new google.maps.LatLng(51.983929,5.90601),	
	var polygonB = new google.maps.Polygon({
	paths: gebiedB,
	strokeColor: "#00FF00",
	strokeOpacity: 0.8,
	strokeWeight: 2,
	fillColor: "#00FF00",
	fillOpacity: 0.35
	});
	
	polygonB.setMap(map);
	
	var gebiedC = [
	new google.maps.LatLng(52.247142,6.152344),
	new google.maps.LatLng(52.239574,6.144104),
	new google.maps.LatLng(52.231585,6.144104),
	new google.maps.LatLng(52.224435,6.159897),
	new google.maps.LatLng(52.230323,6.18187),
	new google.maps.LatLng(52.181511,6.183929),
	new google.maps.LatLng(52.146552,6.17157),
	new google.maps.LatLng(52.08246,6.067886),
	new google.maps.LatLng(52.0432,5.931244),
	new google.maps.LatLng(52.015317,5.920944),
	new google.maps.LatLng(52.016585,5.914764),
	new google.maps.LatLng(51.98451,5.913477),
	new google.maps.LatLng(51.936328,5.956135),
	new google.maps.LatLng(51.89302,6.001968),
	new google.maps.LatLng(51.894292,6.036301),
	new google.maps.LatLng(51.945535,6.074753),
	new google.maps.LatLng(51.99841,6.153717),
	new google.maps.LatLng(52.038977,6.236115),
	new google.maps.LatLng(52.166351,6.606903),
	new google.maps.LatLng(52.178985,6.494293),
	new google.maps.LatLng(52.242097,6.411896),
	new google.maps.LatLng(52.238733,6.340485),
	new google.maps.LatLng(52.232846,6.186676)
	];
	
	var polygonC = new google.maps.Polygon({
	paths: gebiedC,
	strokeColor: "#0000FF",
	strokeOpacity: 0.8,
	strokeWeight: 2,
	fillColor: "#0000FF",
	fillOpacity: 0.35
	});
	
	polygonC.setMap(map);
	
	var gebiedD = [
	
	new google.maps.LatLng(51.936328,5.956135),
	new google.maps.LatLng(51.89302,6.001968),
	new google.maps.LatLng(51.894292,6.036301),
	new google.maps.LatLng(51.945535,6.074753),
	new google.maps.LatLng(51.99841,6.153717),
	new google.maps.LatLng(52.038977,6.236115),
	new google.maps.LatLng(52.166351,6.606903),
	new google.maps.LatLng(52.173932,6.645355),
	new google.maps.LatLng(52.131802,6.665955),
	new google.maps.LatLng(52.116626,6.757965),
	new google.maps.LatLng(52.076974,6.738739),
	new google.maps.LatLng(52.071065,6.698914),
	new google.maps.LatLng(52.037287,6.686554),
	new google.maps.LatLng(51.992491,6.829376),
	new google.maps.LatLng(51.965423,6.82251),
	new google.maps.LatLng(51.956115,6.799164),
	new google.maps.LatLng(51.896834,6.725006),
	new google.maps.LatLng(51.916321,6.683807),
	new google.maps.LatLng(51.852746,6.466827),
	new google.maps.LatLng(51.870556,6.39267),
	new google.maps.LatLng(51.828988,6.405029),
	new google.maps.LatLng(51.851898,6.300659),
	new google.maps.LatLng(51.903613,6.156464),
	new google.maps.LatLng(51.892597,6.104279),
	new google.maps.LatLng(51.842566,6.16333),
	new google.maps.LatLng(51.862924,6.064453),
	new google.maps.LatLng(51.834929,5.957336),
	new google.maps.LatLng(51.826442,5.944977)
	]
	
	var polygonD = new google.maps.Polygon({
	paths: gebiedD,
	strokeColor: "#00FFFF",
	strokeOpacity: 0.8,
	strokeWeight: 2,
	fillColor: "#00FFFF",
	fillOpacity: 0.35
	});
	
	polygonD.setMap(map);
	
	var gebiedE = [
	
	
	new google.maps.LatLng(51.977268,5.61676),
	new google.maps.LatLng(51.979805,5.689545),
	new google.maps.LatLng(51.926328,5.956135),
	new google.maps.LatLng(51.826442,5.944977),
	
	new google.maps.LatLng(51.82814,5.94223),
	new google.maps.LatLng(51.841929,5.871849),
	new google.maps.LatLng(51.841293,5.860176),
	new google.maps.LatLng(51.828292,5.832367),
	new google.maps.LatLng(51.834018,5.825157),
	new google.maps.LatLng(51.885816,5.63736),
	
	new google.maps.LatLng(51.92225,5.615387),
	new google.maps.LatLng(51.918862,5.500031),
	new google.maps.LatLng(51.923943,5.141602),
	new google.maps.LatLng(51.965423,5.181427),
	
	new google.maps.LatLng(51.961192,5.214386),
	new google.maps.LatLng(51.978113,5.240479),
	new google.maps.LatLng(51.955268,5.321503),
	new google.maps.LatLng(51.971346,5.392914),
	new google.maps.LatLng(51.988263,5.438232),
	new google.maps.LatLng(51.978959,5.498657),
	new google.maps.LatLng(51.958654,5.552216),
	new google.maps.LatLng(51.952729,5.626373),
	new google.maps.LatLng(51.973038,5.625)
	
	
	]
	
	var polygonE = new google.maps.Polygon({
	paths: gebiedE,
	strokeColor: "#FF00FF",
	strokeOpacity: 0.8,
	strokeWeight: 2,
	fillColor: "#FF00FF",
	fillOpacity: 0.35
	});
	
	polygonE.setMap(map);
	
	var gebiedF = [
	
	new google.maps.LatLng(51.825169,5.94223),
	new google.maps.LatLng(51.769964,5.989609),
	new google.maps.LatLng(51.746163,5.951157),
	new google.maps.LatLng(51.742337,5.940857),
	new google.maps.LatLng(51.778037,5.890732),
	new google.maps.LatLng(51.775063,5.865326),
	new google.maps.LatLng(51.758065,5.866013),
	new google.maps.LatLng(51.75424,5.756836),
	new google.maps.LatLng(51.772089,5.730743),
	new google.maps.LatLng(51.776338,5.708084),
	new google.maps.LatLng(51.818378,5.640793),
	new google.maps.LatLng(51.828564,5.486984),
	new google.maps.LatLng(51.810737,5.458832),
	new google.maps.LatLng(51.821774,5.408707),
	new google.maps.LatLng(51.757215,5.357208),
	new google.maps.LatLng(51.738935,5.270004),
	new google.maps.LatLng(51.73851,5.124435),
	new google.maps.LatLng(51.754665,5.141602),
	new google.maps.LatLng(51.772939,5.135422),
	new google.maps.LatLng(51.787382,5.09697),
	new google.maps.LatLng(51.780586,5.07843),
	new google.maps.LatLng(51.796726,5.046844),
	new google.maps.LatLng(51.819652,5.000839),
	new google.maps.LatLng(51.818378,5.026932),
	new google.maps.LatLng(51.840869,5.029678),
	new google.maps.LatLng(51.845535,4.998093),
	new google.maps.LatLng(51.861228,4.998093),
	new google.maps.LatLng(51.859107,5.059891),
	new google.maps.LatLng(51.889206,5.113449),
	new google.maps.LatLng(51.923943,5.141602),
	
	
	new google.maps.LatLng(51.918862,5.500031),
	new google.maps.LatLng(51.92225,5.615387),
	new google.maps.LatLng(51.885816,5.63736),
	new google.maps.LatLng(51.834018,5.825157),
	new google.maps.LatLng(51.828292,5.832367),
	new google.maps.LatLng(51.841293,5.860176),
	new google.maps.LatLng(51.841929,5.871849),
	new google.maps.LatLng(51.82814,5.94223)
	
	
	
	
	]
	
	var polygonF = new google.maps.Polygon({
	paths: gebiedF,
	strokeColor: "#FFFF00",
	strokeOpacity: 0.8,
	strokeWeight: 2,
	fillColor: "#FFFF00",
	fillOpacity: 0.35
	});
	
	polygonF.setMap(map);
}

function bindForm()
{

	$("#hint").submit(
		function(e)
		{
			e.preventDefault();
			alert('De quiz wordt nu gecontroleerd, dit kan enkele momenten duren (dit venster wegdrukken om te checken)');			
			$.post("/ajax/hint.php", $(this).serialize(), function(data){
				if (data != 'FOUT')
				{
					document.location.href = data;
				}
				else
				{
					alert('Niet alle antwoorden zijn goed!');
				}
			 });
		}
	)
}
