var maxStap = 1;
var step = null;
var ignoreStep = false;
document.createElement('header');
document.createElement('footer');
document.createElement('nav');
document.createElement('article');
document.createElement('section');
document.createElement('aside');

$(document).ready(function(){
	$('#savedstep').each(function() {
		maxStap = parseInt($(this).val());
	});

	// flash inladen
	// als een div aangemaakt wordt met als class "js_flash",
	// en als inhoud het absolute pad naar de flash en de variable
	// wordt deze automatisch ingeladen
	$('.js_flash').each(function(){
		slideshowvars = $(this).find('.js_flashlink').html();
        //strip HTML comment from flash vars
		slideshowvars = slideshowvars.replace(/^<!--/, "");
		slideshowvars = slideshowvars.replace(/-->$/, "");
		slideshowheight = $(this).css('height');
		slideshowwidth = $(this).css('width');
		var altcontent = $(this).html();
		$(this).html('');
		$(this).flash({
	    	src: slideshowvars,
	    	width: slideshowwidth,
	    	height: slideshowheight,
			wmode: 'transparent',
			allowFullScreen: 'true'
		},
		{
			version: '9', // flash versie checken (9 of hoger)
			update: false // niet upgraden (maar alt. inhoud tonen)
		});
		if (0 == $(this).find('embed').length && 0 == $(this).find('object').length) // niet juiste versie of geen flash, dan inhoud weer tonen
		{
			$(this).html(altcontent);
			$('.js_navblokken').addClass('hide');
		}
	});

	// png fix op document
	// edaarna colorboxinladen (ivm conflict)
    if (typeof $().colorbox == 'function')
    {
		/**
		 *	-- Gebruik --
		 *	Geef een anchor de class .js_colorbox en de href de locatie van de afbeelding
		 *	Voor een slideshow:
		 *	Geef meerdere anchor's met .js_colorbox dezelfde rel="" waarde
		 *	Voorbeeld slideshow:
		 *	<a class="js_colorbox" rel="testblaat" href="/public/img/video2.jpg">klik</a>
		 *	<a class="js_colorbox" rel="testblaat" href="/public/img/banner.jpg">klik</a>
		 */
		//set
		$('.js_colorbox').colorbox({
			transition:'elastic'
		});

		/**
		* Html tonen in colorbox:
		* <a class="js_htmlcolorbox" rel="idvanjehtmldiv">Klik</a>
		*/
		$('.js_htmlcolorbox').click(function(){
			var targetid = $(this).attr('rel');
			if (typeof targetid == 'undefined' || targetid == '') return ;

			$(this).colorbox({
				open: true,
				inline:true,
				transition:'none',
				href:"#" + targetid
			});
		});

		$('.js_gggcolorbox').change(function(){
			if( 'on' == $(this).val() && true === $(this).attr('checked') ) {
				$('.js_lberrorsafterthis').find('.js_errormelding').remove();
				$('.js_lberrorsafterthis').find('.error').removeClass('error');
				var targetid = $(this).attr('rel');
				if (typeof targetid == 'undefined' || targetid == '') return ;

				$(this).colorbox({
					open: true,
					inline:true,
					transition:'none',
					href:"#"+targetid,
					onClosed:function(){
						if( 0 < $('#'+targetid).find('input').length ) {
							$(this).attr('checked','');
						}
						else {
							$(this).attr('checked','checked');
						}
					}
				});
			}
		});


		/**
		* Contact form tonen in colorbox:
		* Verschil met htmlcolorbox is
		* dat deze de pagina herlaadt als hij sluit
		* (om form te resetten)
		* <a class="js_contactcolorbox" rel="idvanjehtmldiv">Klik</a>
		*/
		$('.js_contactcolorbox').click(function(){
			var targetid = $(this).attr('rel');
			if (typeof targetid == 'undefined' || targetid == '') return ;

			$(this).colorbox({
				open: true,
				inline:true,
				transition:'none',
				href:"#" + targetid,
				onClosed:function(){
					// pagina herladen
					if(ajaxFormChanged) {
						window.location.href = window.location.href;
					}
				}
			});
		});

		/**
		* Youtube movie tonen in colorbox:
		 *	Voor een slideshow:
		 *	Geef meerdere anchor's met .colorbox dezelfde rel="" waarde
		 *	Voorbeeld slideshow:
		* <a class="js_youtubecolorbox" rel="testblaat" href="http://www.youtube.com/v/[movie-id]">Klik</a>
		*/
		$('.js_youtubecolorbox').colorbox({
			iframe:true,
			innerWidth: 640,
			innerHeight:505,
			transition:'elastic'
		});
    }

	//## Klapblokken ##

	if (0 < $('.js_uitklapblokken').length)
	{
		$('.js_uitklaplink').click(function ()
		{
			var obj = $(this).parents('.js_uitklapblok:first').find('.js_uitklapdetail:first');

			if (!$(this).hasClass('js_keepothers')) //andere blokken sluiten
			{
				$(this).parents('.js_uitklapblokken').find('.js_uitklapdetail').each(function(){
					if (!$(this).hasClass('js_dontclose')) //dit blok niet altijd open houden
					{
						$(this).slideUp();
						$(this).find('.js_uitklaplink').removeClass('open');
					}
				})
			}

			//overal active verwijderen
			$(this).parents('.js_uitklapblokken').find('.js_uitklaplink').removeClass('active');

			if (obj.css('display')=='none') //geklikt item openen
			{
				obj.slideDown('fast', function(){$(this).css('display', 'block');}); //callback zodat het in IE8 nog steeds werkt
				$(this).addClass('active');
				$(this).addClass('open');
			}
			else //geklikt item sluiten
			{
				obj.slideUp('fast');
				$(this).removeClass('open');
			}
		});
	}

	// toelichting + holder
	$('.js_toelichtinglink').click(function() {
		$(this).parents('p').find('.js_toelichtingholder').fadeIn('fast');
	});
	$('.js_toelichtingholder').click(function() {
		$(this).fadeOut('fast');
	});

	// slideshow
	if (typeof $().slideshow == 'function') {
		$('.js_slideshow').slideshow({
			fadeInTime:500,
			fadeOutTime:500,
			refreshTime:1000
		});
	}

	//field hints
	$(".js_hintfield").each(function(i) {
        var beginStyle = $(this).attr("style");
		$(this).addClass("js_hint");
		$(this).attr("spellcheck",false);
		$(this).val($(this).attr("title"));

        $(this).bind("focus", function(e) {
            if ($(this).val() == $(this).attr("title")) {
                $(this).val("");
				$(this).removeClass("js_hint");
				$(this).attr("spellcheck",true);
            }
        });
        $(this).bind("blur", function(e) {
            if ($(this).val() == "") {
				$(this).addClass("js_hint");
				$(this).val($(this).attr("title"));
				$(this).attr("spellcheck",false);
            } else {
				$(this).removeClass("js_hint");
			}

        });
    });

	//submit form link
	$('.js_submitform').click(function(){
		$(this).parents('form:first').submit();
		return false;
	})

	// styled file uploads
	$('.js_file input[type=file]').change(function(){
		$(this).parent().find('.js_filename').html($(this).val());
	})


	//AJAX FORMS automatisch
	if (typeof $().ajaxForm == 'function')
	{
		$('form.js_ajaxform').each(function(){
			$(this).append('<input type="hidden" name="ajax_post" value="oke" />');
			var form = $(this);
			$(this).ajaxForm({
				dataType: 'json',
				beforeSerialize: function(){
					form.find('.js_hint').val('');
				},
				beforeSubmit: function(){
					if( form.hasClass('js_lightboxform') ) {
						$('.js_lberrorsafterthis').find('.js_errormelding').remove();
					}
					else {
						$('#js_errorsafterthis').find('.js_errormelding').remove();
					}
					form.find('.error').removeClass('error');

					//vereiste velden
					form.find('.js_required').each(function(){
						if ($(this).val().replace(' ', '') == '' || $(this).hasClass('js_hint')) //leeg of bevat nog de hint
						{
							return false;
							$(this).addClass('js_formerror');
						}
						else
							$(this).removeClass('js_formerror');
					});
					form.find('.js_required.email').each(function(){
						var regex = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
						if (!regex.test($(this).val()))
						{
							return false;
							$(this).addClass('js_formerror');
						}
					});
				},
				success: function(response){
					if (response.success)
					{
						form.html('<p>'+response.message+'</p>');

						if ( typeof _gaq == 'object' )
							_gaq.push(['_trackPageview', location.pathname + '-bedankt']);
						else if ( typeof pageTracker == 'object' )
							pageTracker._trackPageview( location.pathname + '-bedankt' );

						if( form.hasClass('js_lightboxform') ) {
							$.colorbox({
								open: true,
								inline:true,
								transition:'none',
								href:"#" + form.parent().parent().attr('id'),
								onClosed:function(){
									if( 0 < $('#'+targetid).find('input').length ) {
										$(this).attr('checked','');
									}
									else {
										$(this).attr('checked','checked');
									}
								},
								innerHeight: form.parent().height()+80
							});
						}
					}
					else if (response.message)
					{
						if(response.errors) {
							for(var i in response.errors) {
								response.message += "<br/>"+response.errors[i];
								$('#'+i).addClass('error');
								$('.'+i).addClass('error');
							}
						}

						if( form.hasClass('js_lightboxform') ) {
							$('.js_lberrorsafterthis').prepend($('<p class="js_errormelding errormelding popup left">'+response.message+'<span class="errormeldingbottom">&nbsp;</span></p>'));
							$.colorbox({
								open: true,
								inline:true,
								transition:'none',
								href:"#" + form.parent().parent().attr('id'),
								onClosed:function(){
									if( 0 < $('#'+targetid).find('input').length ) {
										$(this).attr('checked','');
									}
									else {
										$(this).attr('checked','checked');
									}
								},
								innerHeight: form.parent().height()+80
							});
						}
						else {
							$('#js_errorsafterthis').prepend($('<p class="js_errormelding errormelding left kolom_3">'+response.message+'<span class="errormeldingbottom">&nbsp;</span></p>'));
						}
						$('.js_errmsg').each(function() {
							var rel = $(this).attr('rel');
							$('#'+rel).addClass('error');
							$('.'+rel).addClass('error');
							var relShort = rel.substr(5);
							form.find('input[name='+relShort+']').parent('p').addClass('error');
						});
						window.location = "#js_errorsafterthis";
					}

					if(response.ggglid) {
						if( 1 == response.ggglid ) {
							$('#ggglidworden1ingevuld').show();
						}
						else if( 2 == response.ggglid ) {
							$('#ggglidworden2ingevuld').show();
						}
					}
					form.find('.js_hint').trigger('blur');
				}
			})
		})
	}

	$('.js_itemfilter').change(function() {
		$(this).append('<input type="hidden" name="filtername" value="'+$(this).attr('name')+'" />');
		$(this).closest('form').submit();
	});

	$('.js_meerderereizen').click(function() {
		var form = $(this).closest('form');
		$.ajax({
			type: 'POST',
			url: '/public/ajax/ect-setreizen.php',
			dataType: 'json',
			data: '&meerderereizen='+$(this).attr('rel')+'&'+form.serialize(),
			success: function(json)
			{
				window.location = '/reisaanbod';
			}
		});
	});

	$('.js_stap1dialog').click(function() {
		var stapLink = $(this);
		$('.js_toelichtingholderstap').fadeOut('fast',function(){
			if( 'ja' == stapLink.attr('rel') ) {
				if ( step ) {
					ignoreStep = true;
					step.click();
					step = null;
				}
				else {
					ignoreStep = false;
				}
			}
		});
	});

	// tabs //
	$('.js_tabcontent').hide();
	$('.js_tabcontent:first').show();
	$('.js_tabs').find('a').click(function() {
		$('#js_errorsafterthis').find('.js_errormelding').remove();
		$('.error').removeClass('error');

		if( !ignoreStep && 'block' == $('.js_stap1').css('display') && 1 == $('span.bestemming').length ) {
			$('.js_toelichtingholderstap').fadeIn('fast');
			step = $(this);
		}
		else {
			var toShow = $(this).attr('rel');
			$('.js_tabcontent.active').each(function(){
				var form = $(this).find('form');
				var versturen = 1 == $('#versturen').length ? '&versturen=1' : '';
				$('#reserveeroverzicht').html('');

				if( isNaN(parseInt(toShow.substring(4))) ) {
					$('.js_tabs').find('a').removeClass('active');
					$('#'+toShow+'tab').addClass('active');
					$('#'+toShow+'index').addClass('active');

					$('.js_tabcontent').slideUp();
					$('.js_tabcontent').removeClass('active');
					setTimeout( function()
					{
						$('.js_'+toShow).slideDown();
						$('.js_'+toShow).addClass('active');
						if( 1 == $('#stap1aantalpersonen').val() ) {
							$('.js_tweedepersoon').addClass('hidden');
						}
						else {
							$('.js_tweedepersoon').removeClass('hidden');
						}
					},400);
				}
				else if( toShow.substring(4) > maxStap+1 ) {
					alert('U dient eerst stap '+(maxStap+1)+' in te vullen.');
				}
				else if( toShow.substring(4) > form.find('input[name=stap]').val() ) {
					$.ajax({
						type: 'POST',
						url: form.attr('action'),
						dataType: 'json',
						data: form.serialize(),
						success: function(json)
						{
							if (json.success) {
								if( ('/public/ajax/ecrgs-reserveerstappen.php' == form.attr('action') && 'stap3' == toShow) || ('/public/ajax/ecr-reserveerstappen.php' == form.attr('action') && 'stap3' == toShow) || ('/public/ajax/ect-reserveerstappen.php' == form.attr('action') && 'stap8' == toShow) ) {
									$.ajax({
										type: 'POST',
										url: form.attr('action'),
										dataType: 'json',
										data: versturen+'&overzicht=1&stap='+toShow.substring(4),
										success: function(json)
										{
											if(json.finished) {
												$('#reserveeroverzicht').closest('form').html(json.html);
												$('#controleafronden').html('Bedankt voor uw reservering');
											}
											else {
												$('#reserveeroverzicht').html(json.html);
											}

											if(!json.success) {
												$('.js_errmsg').each(function() {
													var rel = $(this).attr('rel');
													$('#'+rel).addClass('error');
													$('.'+rel).addClass('error');
													var relShort = rel.substr(5);
													//form.find('input[name='+relShort+']').addClass('error');
													form.find('input[name='+relShort+']').parent('p').addClass('error');
												});
											}
										}
									});
								}

								$('.js_tabs').find('a').removeClass('active');
								$('#'+toShow+'tab').addClass('active');
								$('#'+toShow+'index').addClass('active');
								maxStap = Math.max(maxStap,toShow.substring(4));

								// namen weergeven
								var p1naam = $('#p1voornaam').val()+' '+$('#p1achternaam').val();
								$('.js_persoon1naam').each(function(){
									if( 0 < $.trim(p1naam).length ) {
										$(this).text(' ('+$.trim(p1naam)+')');
									}
									else {
										$(this).text(' ');
									}
								});
								var p2naam = $('#p2voornaam').val()+' '+$('#p2achternaam').val();
								$('.js_persoon2naam').each(function(){
									if( 0 < $.trim(p2naam).length ) {
										$(this).text(' ('+$.trim(p2naam)+')');
									}
									else {
										$(this).text(' ');
									}
								});

								$('.js_tabcontent').slideUp();
								$('.js_tabcontent').removeClass('active');
								setTimeout( function()
								{
									$('.js_'+toShow).slideDown();
									$('.js_'+toShow).addClass('active');
									if( 1 == $('#stap1aantalpersonen').val() ) {
										$('.js_tweedepersoon').addClass('hidden');
									}
									else {
										$('.js_tweedepersoon').removeClass('hidden');
									}
								},400);
							}
							else {
								// foutmeldingen tonen
								if( json.message ) {
									$('#js_errorsafterthis').prepend($('<p class="js_errormelding errormelding left kolom_3">'+json.message+'<span class="errormeldingbottom">&nbsp;</span></p>'));
								}
								$('.js_errmsg').each(function() {
									var rel = $(this).attr('rel');
									$('#'+rel).addClass('error');
									$('.'+rel).addClass('error');
									var relShort = rel.substr(5);
									//form.find('input[name='+relShort+']').addClass('error');
									form.find('input[name='+relShort+']').parent('p').addClass('error');
								});
							}
						}
					});
				}
				else {
					$.ajax({
						type: 'POST',
						url: form.attr('action'),
						dataType: 'json',
						data: form.serialize(),
						success: function(json)
						{
							if( ('/public/ajax/ecrgs-reserveerstappen.php' == form.attr('action') && 'stap3' == toShow) || ('/public/ajax/ecr-reserveerstappen.php' == form.attr('action') && 'stap3' == toShow) || ('/public/ajax/ect-reserveerstappen.php' == form.attr('action') && 'stap8' == toShow) ) {
								$.ajax({
									type: 'POST',
									url: form.attr('action'),
									dataType: 'json',
									data: form.serialize()+versturen+'&overzicht=1&stap='+toShow.substring(4),
									success: function(json)
									{
										if(json.finished) {
											$('#reserveeroverzicht').closest('form').html(json.html);
											$('#controleafronden').html('Bedankt voor uw reservering');
										}
										else {
											$('#reserveeroverzicht').html(json.html);
										}

										if( json.message ) {
											$('#js_errorsafterthis').prepend($('<p class="js_errormelding errormelding left kolom_3">'+json.message+'<span class="errormeldingbottom">&nbsp;</span></p>'));
										}
										$('.js_errmsg').each(function() {
											var rel = $(this).attr('rel');
											$('#'+rel).addClass('error');
											$('.'+rel).addClass('error');
											var relShort = rel.substr(5);
											//form.find('input[name='+relShort+']').addClass('error');
											form.find('input[name='+relShort+']').parent('p').addClass('error');
										});
									}
								});
							}

							$('.js_tabs').find('a').removeClass('active');
							$('#'+toShow+'tab').addClass('active');
							$('#'+toShow+'index').addClass('active');

							if (json.success) {
								if( '' == versturen && ( ('/public/ajax/ecrgs-reserveerstappen.php' == form.attr('action') && 'stap3' == toShow) || ('/public/ajax/ecr-reserveerstappen.php' == form.attr('action') && 'stap3' == toShow) || ('/public/ajax/ect-reserveerstappen.php' == form.attr('action') && 'stap8' == toShow) ) ) {
									$.ajax({
										type: 'POST',
										url: form.attr('action'),
										dataType: 'json',
										data: versturen+'&overzicht=1&stap='+toShow.substring(4),
										success: function(json)
										{
											$('#reserveeroverzicht').html(json.html);

											$('#js_errorsafterthis').prepend($('<p class="js_errormelding errormelding left kolom_3">'+json.message+'<span class="errormeldingbottom">&nbsp;</span></p>'));
											$('.js_errmsg').each(function() {
												var rel = $(this).attr('rel');
												$('#'+rel).addClass('error');
												$('.'+rel).addClass('error');
												var relShort = rel.substr(5);
												//form.find('input[name='+relShort+']').addClass('error');
												form.find('input[name='+relShort+']').parent('p').addClass('error');
											});
										}
									});
								}
							}

							$('.js_tabcontent').slideUp();
							$('.js_tabcontent').removeClass('active');
							setTimeout( function()
							{
								$('.js_'+toShow).slideDown();
								$('.js_'+toShow).addClass('active');
								if( 1 == $('#stap1aantalpersonen').val() ) {
									$('.js_tweedepersoon').addClass('hidden');
								}
								else {
									$('.js_tweedepersoon').removeClass('hidden');
								}
							},400);
						}
					});
				}
			});
		}
	});

	$('#stap1aantalpersonen').change(function() {
		if( 1 == $(this).val() ) {
			$('.js_tweedepersoon').addClass('hidden');
		}
		else {
			$('.js_tweedepersoon').removeClass('hidden');
		}
	});

	$('.js_showsubitem').change(function() {
		if( 'p1ciz' == $(this).attr('id') || 'p1pgb' == $(this).attr('id') ) {
			if( 'ja' == $('#p1ciz').val() || 'ja' == $('#p1pgb').val() ) {
				$('#'+$(this).attr('rel')).show();
			}
			else {
				$('#'+$(this).attr('rel')).hide();
			}
		}
		else if( 'p2ciz' == $(this).attr('id') || 'p2pgb' == $(this).attr('id') ) {
			if( 'ja' == $('#p2ciz').val() || 'ja' == $('#p2pgb').val() ) {
				$('#'+$(this).attr('rel')).show();
			}
			else {
				$('#'+$(this).attr('rel')).hide();
			}
		}
		else if( 'p1reisverzekeringextra' == $(this).attr('rel') || 'p2reisverzekeringextra' == $(this).attr('rel') ) {
			if( 'kortlopend' == $(this).val() ) {
				$('#'+$(this).attr('rel')).show();
			}
			else {
				$('#'+$(this).attr('rel')).hide();
			}
		}
		else if( ( 'post' == $(this).val() && true == $(this).attr('checked') ) || ( 'on' == $(this).val() && true == $(this).attr('checked') ) || 'ja' == $(this).val() || 'begeleid' == $(this).val() || 'tehuis' == $(this).val() || 'machtiging' == $(this).val() ) {
			$('#'+$(this).attr('rel')).show();
			$('#'+$(this).attr('rel')+'2').hide();
		}
		else {
			$('#'+$(this).attr('rel')).hide();
			$('#'+$(this).attr('rel')+'2').show();
		}
	});

	$('.js_changetogether').change(function() {
		var rel = $(this).attr('rel');
		var val = $(this).val();
		$('input[rel="'+rel+'"]').each(function() {
			$(this).val(val);
		});
	});

	// reserveren overzicht //
	$('.js_coloring').each(function(){
		$(this).find('p:odd').addClass('even');
	});



	// multiform //
	$('.js_formcontent').hide();
	$('.js_formcontent').find('input').each(function(){
		$(this).attr('disabled','disabled');
	});

	$('.js_formcontent.first').show();
	$('.js_formcontent.first').find('input').each(function(){
		$(this).attr('disabled','');
	});
	$('.js_multiselect.first').attr('checked','checked');

	$('.js_multiselect').click(function() {
		$('.js_multiselect').attr('checked','');
		$(this).attr('checked','checked');
		var toShow = $(this).attr('id');
		$('.js_formcontent').slideUp();
		setTimeout( function()
		{
			$('.js_'+toShow).slideDown();
			$('.js_'+toShow).find('input').each(function(){
				$(this).attr('disabled','');
			});
		},400);
	});

	$(".js_next").click(function(){
		// breedte van de ul bepalen aan de hand van li's (sudoslider doet dat niet goed)
		var ul = $(this).siblings(".js_detailthumbslider").find("ul"); // juiste ul bepalen aan de hand van positie knop
		var ulbreedte = 0;

		ul.find("li").each(function(){
			ulbreedte += Math.round($(this).width());
		});
		// ul iets grotere breedte geven, zodat li's passen
		ul.css('width', ulbreedte+10);

		// sliden
		var divbreedte = 488;
		if(!ul.hasClass('animating') && ulbreedte > divbreedte){ // alleen scrollen als dat niet nog bezig is en niet alles in beeld is

			// status op animating zetten middels class aan ul
			ul.addClass('animating');

			// nog niet bijna aan het einde? Dan hele 350pixels scollen (iets minder als breedte)
			if(ul.css('margin-left').replace('px','') > 820 - ulbreedte)
			{
				ul.animate(
					{marginLeft: '-=350px'},
					750,
					function() {
   						ul.removeClass('animating');
  					});

			}
			else // anders scrollen naar het einde
			{
				ul.animate(
					{marginLeft: divbreedte + 5 - ulbreedte + 'px'},
					500,
					function() {
   						ul.removeClass('animating');
  					});
			}
		}
	});

	$(".js_prev").click(function(){

		// juiste ul bepalen aan de hand van positie knop
		var ul = $(this).siblings(".js_detailthumbslider").find("ul");

		// sliden
		if(!ul.hasClass('animating')){ // alleen scrollen als dat niet nog bezig is

			// status op animating zetten middels class aan ul
			ul.addClass('animating');

			// nog niet bijna aan het einde? Dan hele 350pixels scollen (iets minder als breedte)
			 if(ul.css('margin-left').replace('px','') <= -410)
			{
				ul.animate(
						{marginLeft: '+=350px'},
						750,
						function() {
							ul.removeClass('animating');
						});
			}
			else // anders scrollen naar 0
			{
				ul.animate(
					{marginLeft: '0px'},
					500,
					function() {
   						ul.removeClass('animating');
  					});
			}
		}
	});

	// laatste x pagina's opslaan
    var cLastPages = $.cookie('lastpages');
    var lastPages = new Array();
    if (cLastPages) {
        lastPages = cLastPages.split("\\");
    }
    lastPages.push(document.location);
    while(10 < lastPages.length) {
        lastPages.shift();
    }
    var joined = lastPages.join("\\");
	var date = new Date();
    date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
    $.cookie('lastpages', joined, {path: '/', expires: date});

    $('.js_lastpagesfield').each( function() {
        $(this).attr('value',joined);
    });

	$('.js_styleswitch').click(function() {
		switchStylestyle(this.getAttribute("rel"));

		return false;
	});
	var c = $.cookie('style');
    if (c) switchStylestyle(c);

	function switchStylestyle(styleName) {
		$('link[@rel*=style][title*=font]').each(function(i) {
			this.disabled = true;
			if (this.getAttribute('title') == 'font '+styleName) {
				this.disabled = false;
				$('.js_styleswitch').removeClass('active');

			}
		});
		$('.js_styleswitch').each( function() {
			if ( styleName == $(this).attr('rel') ) {
				$(this).addClass('active');
			}
		});
		$.cookie('style', styleName, {path: '/', expires: date});
	}

	$('.js_pijleroverride').click(function() {
		$.ajax({
			dataType: 'json',
			type: 'GET',
			url: '/public/ajax/pijleroverride.php?pijleroverride='+$(this).attr('rel'),
			success: function(response)
			{
				window.location.href = window.location.href;
			}
		});
	});

	$('.js_ectreserveren').click(function() {
		var id = $(this).attr('rel');
		var datum = $(this).attr('data-datum');
		var data = '&id='+id;
		if(typeof datum != 'undefined') {
			data += '&datum='+datum;
		}
		$.ajax({
			type: 'POST',
			url: '/public/ajax/ect-reserveren.php',
			dataType: 'json',
			data: data,
			success: function(json)
			{
				window.location.href = json.redirecturl;
			}
		});
	});

	$('.js_ectverwijderen').click(function() {
		var elem = $(this);
		var id = $(this).attr('rel');
		$.ajax({
			type: 'POST',
			url: '/public/ajax/ect-reserveren.php',
			dataType: 'json',
			data: '&verwijder='+id,
			success: function(json)
			{
				//elem.closest('p').remove();
				window.location = window.location;
			}
		});
	});
});



/*
//slide an element up without causing blinking flash content

function slideUp(object, speed, slideTime)
{
    if (parseInt(speed) == NaN) return false;
    if (object.jquery == undefined) object = $(object);
	if (object.height() <= 0) return true;
    object.css('overflow', 'hidden');
    var ppf = (object.height() / speed * 20);
    var orgh = object.height();
    var timeout = setInterval(function(){
        object.height(object.height() - ppf);
        if (object.height() <= 0){
            object.hide();
            object.height(orgh);
            clearInterval(timeout);
        }
    }, 10);
    return true;
}

//slide an element down without causing blinking flash content
function slideDown(object, speed)
{
    if (parseInt(speed) == NaN) return false;
    if (object.jquery == undefined) object = $(object);
    object.css('overflow', 'hidden');
    var ppf = (object.height() / speed * 20);
    var orgh = object.height();
    object.height(0);
    object.show();
    var timeout = setInterval(function(){
        object.height(object.height() + ppf);
        if (object.height() >= orgh){
            object.height(orgh);
            clearInterval(timeout);
        }
    }, 10);
    return true;
}
 */
