	$(document).ready(function(){
	
		// initialize
		replace_submit('#frm');
		replace_submit('#news-search');
		replace_submit('#form-narrowdown');
		replace_submit('#faq-search');
		replace_submit('#faq-ask');
		replace_submit('#site-search');
		replace_submit('#location-search');
		replace_submit('#location-widget');
		replace_submit('#search');
		replace_submit('#locatiezoeker');
		replace_submit('#telefoonzoeker');
		replace_submit('.user-content form');
		replace_submit('#login');
		init_staf();
		init_faq();
		init_site_search();
		init_location_search();
		init_news_search();
		init_portals();
		init_mainNavigation();
		init_inschrijfformulier();
		init_print('#print');
		init_print('#print-location');
		init_markRead();
		Carousel.init($('.cta.v5'))
		
		// Fix alignment issue
		fixAligment();
		
		// fix PNGs for IE<=6
		if (window.DD_belatedPNG) {
			DD_belatedPNG.fix('#logo,.logo,.icon,#splash_button');
		}
		
		// Open links in a new window
		$('a[rel=external]').each(function() {
			this.target = '_blank';
		});
		
		// Scrollabel menu
		$('#mijnkoberOpen').click(function(event) {
			$('#slider-menu .viewport').css('overflow', 'hidden');
			$('#menu-container').css('overflow', 'hidden');
			$('#main-menu .fade-left').show();
			$('#main-menu .fade-right').show();
			$('#menu2').css('visibility', 'visible');
		});
		$('#mijnkoberClose').click(function(event) {
			$('#slider-menu .viewport').css('overflow', 'hidden');
			$('#menu-container').css('overflow', 'hidden');
			$('#main-menu .fade-left').show();
			$('#main-menu .fade-right').show();
			$('#menu1').css('visibility', 'visible');
		});
		if ($('.overview').hasClass('open') == true) {
			$('#menu2').css('visibility', 'visible');
			$('#slider-menu').tinycarousel({
				callback: function(element, index){
					$(this).animation = true;
					if (element.id == 'menu1') 	{ $('#menu2').css('visibility', 'hidden'); }
					else 						{ $('#menu1').css('visibility', 'hidden'); }
					$('#slider-menu .viewport').css('overflow', 'visible');
					hideFade();
				},
				display: 1,
				start: 2
			});
		}
		else {
			$('#slider-menu').tinycarousel({
				callback: function(element, index){
					if (element.id == 'menu1') 	{ $('#menu2').css('visibility', 'hidden'); }
					else 						{ $('#menu1').css('visibility', 'hidden'); }
					$('#slider-menu .viewport').css('overflow', 'visible');
					hideFade();
				},
				display: 1
			});
		}
		
		// Make comment headers clickable and toggle contents
		$('.commentform-container .header').click(function(event) {
			event.preventDefault();
			$('.comment-form').find('div.submit').hide();
			
			if($('.comment-form').hasClass('open')) {
				$('.comment-form').find('div.submit').hide();
				$('.comment-form').slideUp(500, function() { 
					$('.comment-form').removeClass('open'); 
				});
			} else {
				$('.comment-form').slideDown(500, function() { 
					$('.comment-form').addClass('open');
					$('.comment-form').find('div.submit').show(); 
				});
			}
			return false;
		});
		$('.commentform-container').find('form div.submit').click(function(){ $(this).closest('form').submit(); });
		$('.commentform-container .h-pot').css('display', 'none');
		
		// Make the .xitem element clickable
		$('.xitem:has(a:not(.email))').not('.noclick').css({ cursor: 'pointer' }).click(function() {		
			if ($(this).find('a').attr('target') == '_blank') {
				window.open($(this).find('a').attr('href'));
			} else {
				document.location = $(this).find('a').attr('href');
			}			
			return false;
		}).hover(function() {
			$(this).addClass('hover');
		},
			function() { $(this).removeClass('hover');
		});
		
		$('.xitem a.stopprop').click( function (event) { event.stopPropagation();  } )
		
		// Een mouseup event op de li omdat het door de animatie mogelijk is om de mousedown en mouseup event
		// op een verschillende element te krijgen en dat is geen click event.
		$('#portals li').css({ cursor: 'pointer' }).mouseup(function() {
			document.location = $(this).find('a').attr('href');
		});
	
		// Remove margin from last element in .user-content
		//$('.user-content *:last-child').css({ 'margin-bottom': 0 });
		
		// Initialize photo album carousel
		$('#photo-album').tinycarousel({ display: 3 });
		$('#photo-album.wide').tinycarousel({ display: 4 });
		
		
		// Initialize photo album lightbox
		$('#photo-album li a, #photoalbum a, #marktplaats-visuals a').fancybox({
			centerOnScroll: true,
			titlePosition: 'inside',
			titleFormat: function(title, currentArray, currentIndex, currentOpts) {
				return  '<span>'+(currentIndex + 1) + ' van ' + currentArray.length +'</span>&nbsp;&nbsp;'+ title;
			}
		});
		
		
	

		// Input fields description
		$('form:not(.empty)').find("input[value!=][type=text]:not(.post),textarea:not(.post)")
		.focus(function () {
			$(this).addClass('focus');		
			if(!$(this).attr("startvalue")) {  
				$(this).attr("startvalue", $(this).val());
			} 
			if($(this).val() == $(this).attr("startvalue")) {
				$(this).val('');	
			}
			//if ($(this).attr('id') == 'login_password') {
			//	$(this).attr('type', 'password');
			//}
		}).blur(function () {
			if($(this).val() == '') {
				$(this).removeClass('focus');
				$(this).val($(this).attr("startvalue"));
				$(this).css('color', '#808080');
			}
		}).keypress(function () {
			$(this).css( { color: '#00257a' });
		});
		$('#loginmain .user-content input.error').keypress(function () {
			$(this).removeClass('error');
		});
		
		if ($('#big_player').length && swfobject.hasFlashPlayerVersion("9")) {
			flowplayer("big_player", "/swf/flowplayer.unlimited-3.2.5.swf", {
				key: ['b44e5f1a7605ac425aa','1189e7090c02ba922c9'],
				canvas: {
					background: '#000000',
					backgroundGradient: 'none'
				},
				plugins: {
					controls: {
						autoHide: "always",
						url: '/swf/flowplayer.controls-netvlies.swf',
						progressColor: '#E00034',
						buttonOverColor: '#E00034',
						volumeColor: "rgb(224, 0, 52, 1)",
						volumeGradient: 'none',
						backgroundColor: "rgba(0, 37, 122, 1)",
						backgroundGradient: 'none',
						volume: true,
						sliderBorder: "1px solid rgb(255, 255, 255, 1)"
					}
				},
				playlist: [
					// this first jpg clip works as a splash image
					{
						url: '/img/kober-movie-canvas-big.png'
					},
					// second clip is a video. when autoPlay is set to false the splash screen will be shown
					{
						autoPlay: false, 
						scaling: 'fit'
					}
				],
				play: {	url: '/img/play.png',
						width: 87,
						height: 73
				}
			});
		} else {
			if($("#big_player[data-youtube]").length) {
				$('#big_player').attr('href', $('#big_player').attr('data-youtube') ).css({ 'background': 'url(/img/on_youtube.gif) center center' });
			}
		}

		if ($('#player').length && swfobject.hasFlashPlayerVersion("9")) {
			flowplayer("player", { src : "swf/flowplayer.unlimited-3.2.5.swf", wmode: 'transparent'	}, {
				key: ['b44e5f1a7605ac425aa','1189e7090c02ba922c9'],
				canvas: {
					background: '#000000',
					backgroundGradient: 'none'
				},
				plugins: {
					controls: {
						autoHide: "always",
						url: 'flowplayer.controls-netvlies.swf',
						progressColor: '#E00034',
						buttonOverColor: '#E00034',
						volumeColor: "rgb(224, 0, 52, 1)",
						volumeGradient: 'none',
						backgroundColor: "rgba(0, 37, 122, 1)",
						backgroundGradient: 'none',
						volume: false,
						sliderBorder: "1px solid rgb(255, 255, 255, 1)"
					}
				},
				playlist: [
					// this first jpg clip works as a splash image
					{
						url: $('#player').attr('rel')
					},
					// second clip is a video. when autoPlay is set to false the splash screen will be shown
					{
						autoPlay: false, 
						scaling: 'fit'
					}
				],
				play: {	url: '/img/play.png',
					width: 87,
					height: 73
				}
			});
		} else {
			if($("#player[data-youtube]").length) { 
				$('#player').attr('href', $('#player').attr('data-youtube') ).css({ 'background': 'url(/img/on_youtube.gif) center center' });
			}
		}
		
		/**
		 *
		 * Maps tonen
		 * 
		 */		 		 		 		
		if ($('#location-gmap').length) {
			/**
			 *
			 * - het rel attribuut van de div #location-gmap is de zoomfactor [optioneel]
			 * - als in de div #location-gmap een link met de class "kml_url" bevat wordt die KML geladen
			 *
			 */			 			 			 			 			
			opts = {
				zoom: $('#location-gmap').attr('rel'),
				kml: $('#location-gmap').find('a.kml_url').attr('href'),
				markers: [],
				scrollwheel: false
			};
			
			/**
			 *
			 * Standaard zoom optie instellen
			 * 
			 */			 			 			 			
			if (opts.zoom == undefined) {
				opts.zoom = 10;
			} else {
				opts.zoom = parseInt(opts.zoom);
			}
			
			/**
			 *
			 * Controleren of er markers geplaatst zijn
			 * 
			 */			 			 			 			
			$('#location-gmap a.gmap_marker').each(function() {
				opts.markers.push({ latlng: new google.maps.LatLng($(this).attr('width'), $(this).attr('height')), title: $(this).attr('title'), icon: $(this).attr('rel') });
			});
			
			init_maps(opts);
		}


	});
	
	/*
	 * GOOGLE MAPS
	 */
	 var kmlviewport = false;
	 var currentzoom;
	function init_maps(opts) {
		$("#location-map").show();
		kmlLayer = null;
		overlay = null; 
						
		var latlng = new google.maps.LatLng(51.582617,4.653053);
		var myOptions = {
			zoom: opts.zoom,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			streetViewControl: true,
			scrollwheel: scrollwheel
		};
		
		var map = new google.maps.Map(document.getElementById("location-gmap"), myOptions);
		
		
		/**
		 *
		 * KML laden
		 * 
		 */		 		 		 		
		if (opts.kml != undefined) {
			load_kml(opts.kml, map, true);
			
			currentzoom = map.getZoom();
			/**
			 * 
			 * Bij zoomen opnieuw de KML ophalen
			 * 
			 */			 			 	 					
			google.maps.event.addListener(map, 'zoom_changed', function() {				
	
				// alleen een nieuwe KML ophalen als we van zoomlevel 13 naar 14 of andersom gaan
				if(currentzoom == 12 && map.getZoom() > 12) {
					load_kml(opts.kml, map, false);
				} else if ( currentzoom == 13  && map.getZoom() < 13 ) {
					load_kml(opts.kml, map, false);
				} else if (map.getZoom() > 16 ) {
					map.setZoom(16);
				}
				currentzoom = map.getZoom();
			});
				
		/**
		 *
		 * Anders, markers laden
		 * 
		 */		 		 		 		
		} else if (opts.markers.length) {
			for (var i = 0; i < opts.markers.length; ++i) {
				make_marker (opts.markers[i], map);
			}	
		}
		
		/**
		 *
		 * Bij zoomen de overlay verplaatsen
		 * 
		 */		 		 		 		
		google.maps.event.addListener(map, 'zoom_changed', function() {
			//overlay.zoom_changed();
			//
		});
		
		overlay = new location_overlay(map);
				
		$('#location-gmap a').live('click', function() {
			$(this).attr('target', '_self');
		});
	}
	
	/**
	 *
	 * Fadeouts in menu verbergen
	 * 
	 */	
	function hideFade() {
		//$('#main-menu .fade-left').hide();
		//$('#main-menu .fade-right').hide();
		$('#menu-container').css('overflow', 'visible');
	}
	
	function make_marker(marker, map) {

		/**
		 *
		 * Marker aanmaken
		 * 
		 */		 		 		 		
		var marker_obj = new google.maps.Marker({
			position: marker.latlng,       
			map: map,       
			icon: marker.icon, 
			infoWindow: marker.title
		});

		/**
		 *
		 * Map centreren
		 * 
		 */		 		 		 		
		map.setCenter(marker.latlng);
		
		/**
		 *
		 * Klik event toevoegen
		 * 
		 */		 		 		 							
		google.maps.event.addListener(marker_obj, 'click', function(event) {
			overlay.show(marker_obj.getPosition(), marker_obj.infoWindow);
		});
	}
	
	/**
	 *
	 * KML inladen
	 * 
	 */	 	 	 	
	function load_kml(kml, map, set_center) {
		/**
		 *
		 * Type markers bepalen
		 * 
		 */		 		 		 		
		var marker = 'small';
		if (map.getZoom() > 12) {
			marker = 'big';
		}
		
		/**
		 *
		 * Als de map verder als zoom level 13 is ingezoomd en de KML wordt voor de eerste keer geladen, 
		 * dan wordt na inladen de kaart opnieuw gecentreerd, zodat op de locatie detail de kaart goed 
		 * geladen wordt. Dit is zo gedaan, omdat de optie "preserveViewport" op false zetten een 
		 * foutmelding oplevert
		 * 
		 */
		 
		if(set_center == null ) {
			set_center = false;
		}
		
		if(kmlLayer != null) { 
			kmlLayer.setMap(null); 
		} 
		
		/**
		 *
		 * KML laden
		 * 
		 */		 		 		 		
		kmlLayer = new google.maps.KmlLayer(kml+'&marker=' + marker, { preserveViewport:true, suppressInfoWindows: true });
		kmlLayer.setMap(map);
		 
		/**
		 *
		 * Opnieuw centreren, hierbij wachten op het event "metadata_changed" omdat dan de data geladen is		 
		 * 
		 */		 		 	
		  		
		if (set_center) {
			google.maps.event.addListener(kmlLayer, 'metadata_changed', function() {
			   
				map.fitBounds(kmlLayer.getDefaultViewport());
				
				/**
				 * Hier nog een keer de KML laden om de grootte van de icons
				 * te fixen als het zoom level groter dan 12 blijkt te zijn.
				 * @TODO: Mits mogelijk dit wat netter herschrijven				 				 
				 */
				if (map.getZoom() > 12) {
					marker = 'big';
					
					kmlLayer = new google.maps.KmlLayer(kml+'&marker=' + marker, { preserveViewport:true, suppressInfoWindows: true });
					kmlLayer.setMap(map);
				}
				
			});
		}
		
		/**
		 *
		 * Klik event toevoegen
		 * 
		 * Inhoud van het event.featureData object:
		 * 
		 * {   
		 * 		author: {     
		 *			email: "nobody@google.com",     
		 *			name: "Mr Nobody",     
		 *			uri: "http://example.com"   
		 *		},   
		 *		description: "description",   
		 *		id: "id",   
		 *		infoWindowHtml: "html",   
		 *		name: "name",   
		 *		snippet: "snippet" 
		 * }	 		 		 
		 * 
		 */		 		 		 							
		google.maps.event.addListener(kmlLayer, 'click', function(event) {
			var content = '<strong>' + event.featureData.name + '</strong><br />' + event.featureData.description;
			
			overlay.show(event.latLng, content, event.pixelOffset);
		});
	}
	
	/**
	 *
	 * Overlay voor de custom infowindow
	 * 
	 */	 	 	 	
	function location_overlay(map) {	
		this.map_ = map;    
		this.div_ = null;   
		this.latlng_ = null; 
		
		this.setMap(map); 
	}  

	// Google maps zaken in deze if gezet. Onzin om deze altijd te laden!
	if (typeof(google) != "undefined") {
		location_overlay.prototype = new google.maps.OverlayView();

		/**
		 *
		 * Op de onAdd van de overlay de DIV aanmaken die als infowindow
		 * wordt gebruikt en op de map pane zetten
		 *
		 */	 	 	 	 			
		location_overlay.prototype.onAdd = function() {
			// Note: an overlay's receipt of onAdd() indicates that
			// the map's panes are now available for attaching
			// the overlay to the map via the DOM.
			// Create the DIV and set some basic attributes.
			var div = document.createElement('DIV');
			div.id = 'gmap-infowindow';

			// Set the overlay's div_ property to this DIV
			this.div_ = div;

			$(this.div_).html('<div class="top"></div><div class="content"></div><div class="bot"></div><div class="arrow"></div><div class="close"></div>');
			$('.close', $(this.div_)).click(function() {
				overlay.hide();
			});

			// We add an overlay to a map via one of the map's panes.
			// We'll add this overlay to the overlayImage pane.
			var panes = this.getPanes();
			panes.overlayLayer.appendChild(div);
			panes.overlayLayer.style.zIndex = 9999;
		}

		/**
		 *
		 * Verplichte draw functie
		 *
		 */
		location_overlay.prototype.draw = function() {
			if (this.latlng_) {
				overlay.position();
			}
		}

		/**
		 *
		 * Bij verwijderen van de overlay de div ook echt verwijderen
		 *
		 */
		location_overlay.prototype.onRemove = function() {
			this.div_.parentNode.removeChild(this.div_);
			this.div_ = null;
			this.latlng_ = null;
		}

		/**
		 *
		 * Verbergen van de overlay
		 *
		 */
		location_overlay.prototype.hide = function() {
			if (this.div_) {
				$(this.div_).hide();
				this.latlng_ = null;
			}
		}

		/**
		 *
		 * Tonen van de overlay
		 *
		 */
		location_overlay.prototype.show = function(latLng, content, pixelOffset) {
			if (this.div_) {
				this.latlng_ = latLng;

				$('.content', $(this.div_)).html(content);

				overlay.position(pixelOffset);
				$(this.div_).show();

				this.map_.panTo(this.latlng_);
			}
		}

		/**
		 *
		 * Positioneren van de DIV
		 *
		 */
		location_overlay.prototype.position = function(pixelOffset) {
			if (pixelOffset == undefined) {
				pixelOffset = new google.maps.Size(0, -32);
			}

			var overlayProjection = this.getProjection();
			var position = overlayProjection.fromLatLngToDivPixel(this.latlng_);

			var x_pos = position.x;
			var y_pos = position.y - ($(this.div_).height() / 2);

			if (this.map_.getZoom() > 13) {
				x_pos += 6;
				y_pos += (pixelOffset.height /2);
			} else {
				y_pos += (pixelOffset.height /8);
			}

			this.div_.style.left = x_pos + 'px';
			this.div_.style.top = y_pos + 'px';
		}
		
	} 
	
	
	/*
	 * PRINT
	 */
	
	function init_print(obj) {
	
		if (window.print && $(obj).length) {
			$(obj).css({ visibility: 'visible' }).click(function() {
				if($(this).hasClass('disabled')){
					return true;
				}
				window.print();
				return false;
			});
		}
	
	}

	/*
	 * Portals
	 */
	
	function init_portals() {

		$('body:not(.home) #portals li p').hide();

		// Portal slides sub pages
		$('body:not(.home) #portals li').hover(
			function(){
				$(this).find('p').show();
				$(this).stop().animate({ top: 0 }, 500, 'easeOutBounce');
			},
			function() {
				$(this).stop().animate({ top: ($(this).hasClass('active')) ? 55 : 60 }, 500, 'easeOutBounce', function() {
					$(this).find('p').hide();
				});	
			}
		);
		
		// Portal slides homepage
		$('body.home #portals li:not(.active)').hover(
			function(){
				$('body.home #portals li.active').stop().animate({ top: 10 }, 500, 'easeOutBounce');
				$(this).stop().animate({ top: 0 }, 500, 'easeOutBounce');
			},
			function() {
				$('body.home #portals li.active').stop().animate({ top: 0 }, 500, 'easeOutBounce');
				$(this).stop().animate({ top: 10 }, 500, 'easeOutBounce');	
			}
		);
	}
	
	/*
	 * Replace standard submit buttons with custom buttons
	 */
	 
	function replace_submit(tObj) {
		var obj = $(tObj);
		
		obj.find('input.submit').css({ position: 'absolute', top: '-10000px', left: '-10000px', bottom: 'auto', right: 'auto' });
		obj.find('div.submit').css({display: 'block'}).click(function() {
			$(this).closest('form').submit();
			return false;
		});
	
	}
	
	/*
	 * Send to a friend form
	 */
	 
	function init_staf() {
	 
		var obj = $('#staf');
	 
	 	obj.show().find('p.error,input.submit').hide()
		 
		obj.find('a').click(function() {
			if (obj.hasClass('open')) {					
				obj.find('form div.submit').hide(0, function() {
					obj.find('form').slideUp({
						duration: 500,
						complete: function() {
							obj.removeClass('open');
						}
					});
				});
			} else {
				obj.find('form').slideDown({
					duration: 500,
					//easing: 'easeOutBounce',
					complete: function() {
						obj.addClass('open');	
						obj.find('form div.submit').show();
					}
				});
			}
			return false;
		});
		
		obj.find('form div.submit').click(function(){
			$(this).closest('form').submit();
		});
		
		obj.find('form').submit(function() {
		
			var error = 0;
			naam = $(this).find('input[name=naam]');
			email = $(this).find('input[name=email]');
			naam_ontvanger = $(this).find('input[name=naam_ontvanger]');
			email_ontvanger = $(this).find('input[name=email_ontvanger]');
			
			email_pattern = /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i;
			
			if (naam.val() == '' || naam.val() == 'Uw naam') {
				naam.addClass('error');
				error+=1;
			} else {
				naam.removeClass('error');
				error-1;
			}
			
			if (naam_ontvanger.val() == '' || naam_ontvanger.val() == 'Naam ontvanger') {
				naam_ontvanger.addClass('error');
				error+=1;
			} else {
				naam_ontvanger.removeClass('error');
				error-1;
			}
			
			if (!email.val().match(email_pattern)) {
				email.addClass('error');
				error+=1;
			} else {
				email.removeClass('error');
				error-1;
			}
			
			if (!email_ontvanger.val().match(email_pattern)) {
				email_ontvanger.addClass('error');
				error+=1;
			} else {
				email_ontvanger.removeClass('error');
				error-1;
			}
			
			if (error>0) {
				obj.find('form p').show();
			} else {
				obj.find('form p').hide();
				
				$.ajax({
					type: 'POST',
					url: '/ajax/staf.php',
					data: obj.find('form').serialize(),
					success: function() {
						obj.find('form p').removeClass('error').text('Deze pagina is doorgestuurd.').show();
						obj.find('form .inner').hide();
					}
				});
			}

			return false;
		});
	}
	
	/*
	 * Frequentyly Askes Questions
	 */
	 
	function init_faq() {
		
		var obj = $('#faq');
		
		obj.find('a.question').click(function() {
			$(this).parent().find('.wrap').not(':animated').slideToggle({
				duration: 600,
				easing: 'easeOutExpo'
			}).parent().toggleClass('active', 500);
			return false;
		});
		
		obj.find('.showall').toggle(function() {
			$(this).text('Minder veelgestelde vragen').parent().parent().find('li').show();
		}, function() {
			$(this).text('Meer veelgestelde vragen').parent().parent().find('li:not(.show)').hide();
		});
		
		// open faq item when find through search: url contains hash with faq id
		if ($('#faq').length) {
			var hash = window.location.hash.replace('#', '');
			if (hash != '') {
				$('#faq').find('a[name='+hash+']').parent().toggleClass('active', 500).find('.wrap').show();
			}
		}
	}
	
	/*
	 * Site search options
	 */
	 
	function init_site_search() {
	
		var obj = $('#site-search');
		
		if (!obj.find('.options input:checked').length) obj.find('.narrowdown').addClass('inactive');
		
		obj.find('.narrowdown a').click(function() {
			obj.find('.narrowdown').toggleClass('inactive');
			return false;
		});
	}
	
	/*
	 * Location search options
	 */
	 	
	function init_location_search() {
		var obj = $('#location-search, #form-narrowdown');

		obj.find('.options').each(function() {
			if (!$(this).find('input:checked').length) $(this).closest('.narrowdown').addClass('inactive');
		});

		obj.find('.narrowdown a').click(function() {
			$(this).closest('.narrowdown').toggleClass('inactive');
			return false;
		});
	}
	
	/*
	 * Location news  options
	 */
	 	
	function init_news_search() {

		var obj = $('#news-search');

		obj.find('.options').each(function() {
			if (!$(this).find('input:checked').length) $(this).closest('.narrowdown').addClass('inactive');
		});

		obj.find('.narrowdown a').click(function() {
			$(this).closest('.narrowdown').toggleClass('inactive');
			return false;
		});
	}

	/*
	 * Add functionalities to the main navigation
	 */

	function init_mainNavigation() {
		// Make entire li clickable
		$('#nav-main ul.sub li').find('a').each(function () {
			$(this).parent().css({ cursor: 'pointer' }).click(function() {
				document.location = $(this).find('a:first').attr('href');
				return false;
			});
		});
	
		// add hover effect (mainly for ie6)
		$('#nav-main li.root').hover(function() {
			$(this).find('.container').show();	
		}, function() {
			$(this).find('.container').hide();
		});
	}

	/*
	 * Fixes the centered background 1px bug
	 */
	

	
	function fixAligment() {
		var obj = $('body');
		var doc_width = $(document).width() + obj.css('margin-left');
		var margin_left = (doc_width % 2 == 1) ? -1 : 0;
		obj.css('margin-left', margin_left);
	}

	function init_markRead() {
		$('#mark_read').click(function() {
			var home_id = $(this).attr('rel');

			$.ajax({
				type: 'POST',
				url: '/ajax/home.php',
				data: 'home_id='+home_id,
				success: function() {
					$('#uitgelicht').hide('slow');
				}
			});
		});
	}
	
	function init_inschrijfformulier() {
		if ($('.adres_gelijk').length) {
			$('.adres_gelijk').click(function() {
				if($("input[name=adres_gelijk]:checked").val() == 'nee') {
				    
					$('.adres_flip').removeClass('hidden');
				} else {
                    $('.adres_flip').addClass('hidden');
				}
			});
		}
		if ($('#kent_kober_via').length) {
            $('#kent_kober_via').change(function() {
                
                if ($('#kent_kober_via').val() == 'Link op internet, namelijk' || $('#kent_kober_via').val() == 'Anders, namelijk') {
					$('#anders').removeClass('hidden');
				} else {
                    $('#anders').addClass('hidden');
				}
			});
		}
	}

	jQuery.fn.txReplaceFormPassword = function(options) {
		var options = jQuery.extend( {
		show_text: 'Password'
		},options);
		
		function trim(txt) {
		return txt.replace(/^\s+|\s+$/g, '');
		}
		
		return this.each(function() {
		if (jQuery(this).val().length == 0) {
		
		var $pos = jQuery(this).position();
		var $style = jQuery(this).attr('style');
		var $class = jQuery(this).attr('class');
		var $size = jQuery(this).attr('size');
		var $id = jQuery(this).attr('id');
		var $name = jQuery(this).attr('name');
		
		jQuery(this).hide();
		jQuery(this).after('&lt;input type="text" id="txgrpl-' + $id + '" name="txgrpl-' + $name + '" size="' + $size + '" style="' + $style + '" value="' + options.show_text + '" rel="' + $id + '" title="' + options.show_text + '" /&gt;');
		
		$('#txgrpl-' + $id).focus(function() {
		$(this).hide();
		var $id = $(this).attr('rel');
		$('#' + $id).show().focus();
		});
		}
		
		jQuery(this).blur(function() {
		if (trim(jQuery(this).val()) == '' || jQuery(this).val() == undefined) {
		var $id = jQuery(this).attr('id');
		jQuery(this).hide();
		$('#txgrpl-' + $id).show();
		}
		});
		});
	};
	
	
	

var Carousel = {};
	
	(function(context) {
		
		context.init = function(obj) {
			
			context.parent = obj;
			context.parent.find('.cta-slide:first').clone().appendTo(context.parent.find('.slide-container')).removeClass('active');
			context.len = context.parent.find('.cta-slide').length;
			context.parent.find('.slide-container').width(context.len*200);
			context.parent.find('.text').html('1 van ' + (context.len -1));
			
			context.parent.find('.next').click(function(e) {
				idx = context.parent.find('.cta-slide').index(context.parent.find('.cta-slide.active'))+1;
				3			
				if(idx ==  context.len) {
					context.parent.find('.slide-container').stop().css({marginLeft: 0});
					idx = 1;
				}
				
				context.parent.find('.cta-slide:eq('+(idx)+')').addClass('active').siblings().removeClass('active');
				context.slide(idx);	
				e.preventDefault();	
			})
			context.parent.find('.prev').click(function(e){ 
				idx = context.parent.find('.cta-slide').index(context.parent.find('.cta-slide.active'));
				if(idx == 0 ) {
					idx	= context.len - 2
					m = (context.len - 1) *200;
					context.parent.find('.slide-container').stop().css({marginLeft: 0 - m});
				} else {
					idx = idx - 1;
				}
				
				context.parent.find('.cta-slide:eq('+(idx)+')').addClass('active').siblings().removeClass('active');
				context.slide(idx);
				e.preventDefault();
			}) 
	
			obj.mouseleave(function() {
				context.interval = setTimeout(function() { context.autoslide() }, 2000 );
			}).mouseover(function() { 
				clearTimeout(context.interval);
			})
			
			context.interval = setTimeout(function() { context.autoslide() }, 2000 );
		};
		
		context.autoslide = function() { 
			
			clearTimeout(context.interval);
			idx = context.parent.find('.cta-slide').index(context.parent.find('.cta-slide.active'))+1;

			if(idx ==  context.parent.find('.cta-slide').length) {
				context.parent.find('.slide-container').stop().css({marginLeft: 0});
				idx = 1;
			}
	
			context.parent.find('.cta-slide:eq('+(idx)+')').addClass('active').siblings().removeClass('active');
			
			context.slide(idx)
			context.interval = setTimeout(function() { context.autoslide() }, 3000 );
			
		}
		
		context.slide = function(idx) {
			y = context.len-1; 
			(idx+1 == context.len) ? x = 1 : x = idx +1
			context.parent.find('.text').html( x +' van ' + y);
			
			$obj = 	context.parent.find('.cta-slide:eq('+(idx)+')');
			position = ($obj.outerWidth() * idx) * -1;			
			context.parent.find('.slide-container').stop().animate({ marginLeft: position },500);
			context.parent.find('.carousel-link').attr('href', context.parent.find('.cta-slide.active .slide-link').attr('href') );

		};
	
	})(Carousel);
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
