
$(document).ready(function()
{
	
	$("a.high-contrast").click(function()
	{
		if($("#cssHighContrast").attr("rel") == "alternate stylesheet")
		{
			$("#cssHighContrast").attr("rel", "stylesheet");
			$("#cssHighContrast").attr("disabled", false);
			intValue = 1;
			
			//-- gekleurde menu blokken bovenaan in wit zetten
			for (var i = 0; i < 5; i++)
			{
				if ($('#menu_blok_' + i))
				{
					$('#menu_blok_' + i).attr('src', strPath + 'images/menu_blok_hoog_contrast.png');
				}
			}
			if ($('#right_film'))
			{
				$('#right_film').attr('src', strPath + 'images/icon_film_hoogcontrast.png');
			}
			if ($('#right_podcast'))
			{
				$('#right_podcast').attr('src', strPath + 'images/icon_podcast_hoogcontrast.png');
			}
			if ($('#high_contrast_out'))
			{
				$('#high_contrast').css('display', 'none');
				$('#high_contrast_out').css('display', 'inline');
			}
		}
		else
		{
			$("#cssHighContrast").attr("rel", "alternate stylesheet");
			$("#cssHighContrast").attr("disabled", true);
			intValue = 0;
			
			//-- witte menu blokken bovenaan in kleur zetten
			for (var i = 0; i < 5; i++)
			{
				if ($('#menu_blok_' + i))
				{
					$('#menu_blok_' + i).attr('src', strPath + 'images/menu_blok_' + i + '.png');
				}
			}
			if ($('#right_film'))
			{
				$('#right_film').attr('src', strPath + 'images/icon_film.png');
			}
			if ($('#right_podcast'))
			{
				$('#right_podcast').attr('src', strPath + 'images/icon_podcast.png');
			}
			if ($('#high_contrast_out'))
			{
				$('#high_contrast').css('display', 'inline');
				$('#high_contrast_out').css('display', 'none');
			}
		}
		$.post(strPath + "ajax_utilities.php", "type=high-contrast&value=" + intValue);

	});

	$("a.font-size-small").click(function()
	{
		$("#body").css("fontSize","10px");
		$.post(strPath + "ajax_utilities.php", "type=font-size&value=1");
	});
	$("a.font-size-medium").click(function()
	{
		$("#body").css("fontSize","11px");
		$.post(strPath + "ajax_utilities.php", "type=font-size&value=2");
	});
	$("a.font-size-large").click(function()
	{
		$("#body").css("fontSize","12px");
		$.post(strPath + "ajax_utilities.php", "type=font-size&value=3");
	});

});


function InitializeGoogleMaps(strMapId)
{
	var LatLng = new google.maps.LatLng(50.85074309341152, 2.885456085205078 );

	var myOptions = {
		zoom: 13,
		center: LatLng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		//mapTypeId: google.maps.MapTypeId.HYBRID,
		disableDefaultUI: true,
		navigationControl: true,
		mapTypeControl: true,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		scaleControl: false
	};

	return new google.maps.Map(document.getElementById(strMapId), myOptions);
}


function CreateMarker(googlemaps, objMarker, strInfoWidth, strInfoHeight)
{
	//-- Breedte en hoogte van infowindow
	if(typeof(strInfoWidth) == 'undefined')
	{
		var strInfoWidth = 300;
	}
	if(typeof(strInfoHeight) == 'undefined')
	{
		var strInfoHeight = 150;
	}
	
	if(objMarker.icon !== undefined)
	{
		var Pin = new google.maps.MarkerImage(strPath + 'images/' + objMarker.icon, new google.maps.Size(42, 63));
	}
	else
	{
		var Pin = new google.maps.MarkerImage(strPath + 'images/marker.png', new google.maps.Size(21, 32));
	}
	var Marker = new google.maps.Marker({
		position: new google.maps.LatLng(objMarker.lat, objMarker.lng),
		map: googlemaps,
		icon: Pin
	});

	var InfoWindow = new google.maps.InfoWindow({
		content: "<iframe src='" + strPath + "address-google-maps.php?addressno=" + objMarker.addressno + "&map=1' frameborder='0' width='" + strInfoWidth + "px' height='" + strInfoHeight + "px'></iframe>", size: new google.maps.Size(300,150)
	});

	google.maps.event.addListener(Marker, 'click', function(){
		InfoWindow.open(googlemaps, Marker);
	});
	
	return Marker;
	
}

function CreateMarkers(googlemaps, arrMarkers, strInfoWidth, strInfoHeight)
{
	//-- Breedte en hoogte van infowindow
	if(typeof(strInfoWidth) == 'undefined')
	{
		var strInfoWidth = 300;
	}
	if(typeof(strInfoHeight) == 'undefined')
	{
		var strInfoHeight = 150;
	}
	
	var arrReturn = Array();
	var GlobalLngLat = new google.maps.LatLngBounds();
	var intGoogleMapsInterval = 0.003;

	for(var i = 0; i < arrMarkers.length; i++)
	{
		var objMarker = arrMarkers[i];
		
		arrReturn.push(CreateMarker(googlemaps, objMarker, strInfoWidth, strInfoHeight));
		
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat + intGoogleMapsInterval, objMarker.lng));
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat, objMarker.lng + intGoogleMapsInterval));
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat - intGoogleMapsInterval, objMarker.lng));
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat, objMarker.lng - intGoogleMapsInterval));
	}

	if(arrMarkers.length >= 1)
	{
		googlemaps.fitBounds(GlobalLngLat);
	}
	
	return arrReturn;
	
}


//-- submitten contact formulier
function CheckFormContact()
{
	var fielderrors = "no";
		
	var arrElementen = Array();
	var arrFields = $("#frmContact").serializeArray();
	for (var i = 0; i < arrFields.length; i++)
	{
		arrElementen[arrElementen.length] = arrFields[i].name;
	}
	
	var params = MakeParameters(arrElementen);
		
	$.ajax({
		type: "POST",
		url: strPath + "ajax_form.php",
		data: params + "&form-type=contact",
		dataType: "html",
		complete: function(html){
			//alert(html.responseText);
			
			var arrObjecten = eval(html.responseText);

			for(i = 0; i < arrObjecten.length; i++)
			{
				var	arrObject = arrObjecten[i];
				
				var fieldname = arrObject.element;
												
				$('#' + fieldname + '-message').html("");

				if(arrObject.value == 0)
				{
					$('#' + fieldname + '-message').append(html_entity_decode(arrObject.message)).hide();
					$('#' + fieldname + '-message').fadeIn('fast');
					fielderrors = "yes";
					$("#" + arrObject.element).addClass("form-error");
				}
				else
				{
					$('#' + fieldname + '-message').html("");
				}
			}

			//-- als er geen errors zijn => submitten
			if (fielderrors == "no")
			{
				$('#frmContact').hide();
				//$('#contactfields').fadeOut('fast');
				//$('#contactBottom').fadeOut('fast');
				$('#successmsg').fadeIn('fast');
			}
		}
	});
}

//-- gebruikt bij submitten van formulieren (om velden mee te geven naar ajax)
function MakeParameters(arr)
{
	var strParameters = "";
	var ampersant = "";

	//--Parameters maken met de inhoude van de velden
	for(var i=0;i<arr.length;i++)
	{
		
		if(document.getElementById(arr[i]))
		{			
			//-- bij checkbox => kijken of checkbox aangevinkt staat
			if (arr[i] == "newsletter")
			{
				if (document.getElementById(arr[i]).checked == 1)
				{
					fieldvalue = "on";
				}
				else
				{
					fieldvalue = "off";
				}
			}
			else
			{
				fieldvalue = document.getElementById(arr[i]).value;
			}
			strParameters += ampersant + arr[i] + "=" + fieldvalue;
			ampersant = "&";
		}
	}
	return strParameters;
}

function html_entity_decode(str)
{
	try
	{
		var  tarea=document.createElement('textarea');
		tarea.innerHTML = str;
		return tarea.value;
		tarea.parentNode.removeChild(tarea);
	}
	catch(e)
	{
		//for IE add<div id="htmlconverter" style="display:none;"></div> to the page
		document.getElementById("htmlconverter").innerHTML = '<textarea id="innerConverter">' + str + '</textarea>';
		var content = document.getElementById("innerConverter").value;
		document.getElementById("htmlconverter").innerHTML = "";
		return content;
	}
}


//you tube filmpjes
function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}


//-- submitten contact formulier
function CheckFormReservation()
{
	var fielderrors = "no";
		
	var arrElementen = Array();
	var arrFields = $("#frmContact").serializeArray();
	for (var i = 0; i < arrFields.length; i++)
	{
		arrElementen[arrElementen.length] = arrFields[i].name;
	}
	
	var params = MakeParameters(arrElementen);
		
	$.ajax({
		type: "POST",
		url: strPath + "ajax_form.php",
		data: params + "&form-type=reservation",
		dataType: "html",
		complete: function(html){
			//alert(html.responseText);
			
			var arrObjecten = eval(html.responseText);

			for(i = 0; i < arrObjecten.length; i++)
			{
				var	arrObject = arrObjecten[i];
				
				var fieldname = arrObject.element;
												
				$('#' + fieldname + '-message').html("");

				if(arrObject.value == 0)
				{
					$('#' + fieldname + '-message').append(html_entity_decode(arrObject.message)).hide();
					$('#' + fieldname + '-message').fadeIn('fast');
					fielderrors = "yes";
					$("#" + arrObject.element).addClass("form-error");
				}
				else
				{
					$('#' + fieldname + '-message').html("");
				}
			}

			//-- als er geen errors zijn => submitten
			if (fielderrors == "no")
			{
				$('#contactfields').css('display', 'none');
				$('#successmsg').fadeIn('fast');
			}
		}
	});
}

$(function() {
	$('#date').datepick();
});

function showDate(date) {
	alert('The date chosen is ' + date);
}

