$(document).ready(function(){
	$('select[name=plaatsfilter]').bind('change', function(){
		$(window).attr('location', $(this).val()); 
	});
	$('.toggle').each(function(){
			$(this).next().hide();
	});
	$('.toggle').bind('click', function(e){
		e.preventDefault();
		if($(this).next().css('display') == 'none'){
			$(this).next().slideDown('fast');	
		}else{
			$(this).next().slideUp('fast');
		}
	});
	
	$('a.meel').each(function(i) {
		var text = $(this).text();
		var address = text.replace(" op ", "@");
		var address = address.split(' punt ').join('.');
		$(this).attr('href', 'mailto:' + address);
		$(this).text(address);
	});
	
	$('.movielink').click(function(e){
		if($('#'+$(this).attr('rel')).css('display') == 'none'){
			$('#'+$(this).attr('rel')).show();
		}else{
			$('#'+$(this).attr('rel')).hide();
		}
		e.preventDefault();
	});

	$(".ajaxformulier").unbind('submit').submit(function(){
		if($(this).submitted != true){
		$(this).submitted = true;		
			var form = $(this);
			var data = $(this).serialize();
			$(this).find('input, textarea, checkbox, radio, select').each(function(){
				if($(this).attr('title')){
					ar = $(this).attr('name').split('[]');
					naam = ar[0];
					data += '&veldnamen['+encodeURIComponent(naam)+']=' + encodeURIComponent($(this).attr('title'))
				}
			});
			$.ajax({
				type: 	$(this).attr('method'),
				url: 	$(this).attr('action'),
				data: 	data,
				success: function(msg){
					form.submitted = false;
					if(form.attr('target')){
						$(form.attr('target')).html(msg);
					}
				},
				error: function(xhr, ajaxOptions, thrownError){
					alert(xhr.status);
					alert(thrownError);
				}
			});
		}
		return false;
	});	
	
	$('.ajaxformulier .renew').click(function(e){
		$captcha = $('.captcha');
		$newsrc = $captcha.attr('src')+'1';
		$captcha.attr('src',$newsrc);
		e.preventDefault();
	});
	
	$("a.fancyajax").fancybox({
		'speedIn'		:	600, 
		'type'			:	'ajax', 
		'speedOut'		:	200
	});
	
	$("a.lighbox").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200
	});
});
