$.fn.mauritshuisFancybox = function (opts) {
	var opts = $.extend({
		transitionIn: 'elastic',
		transitionOut: 'elastic',
		titlePosition: 'over'
	}, opts);
	return $(this).fancybox(opts);
};

$(document).ready(function () {
	$('#font-size').fontsizer();
	$('.search').watermark();
	$('#email').focus(function () {
		var $this = $(this);
		if ($this.val() == 'E-mailadres' || $this.val() == 'E-mail address') {
			$this.val('');
		}
	});
	
	$('a.lightbox').each(function () {
		var $this = $(this);
		var content = $('#' + $this.attr('id') + '-content');
		if (!content.length) {
			return;
		}
		var intro = content.find('> .intro');
		var introHtml = intro.html();
		
		if (content.is('.lightboxVideo')) {
			// toon een lightbox met een YouTube-video erin
			$.get($this.attr('href'), function (html) {
				var match = html.match(/http:\/\/www\.youtube\.com\/v\/[^"]+/i);
				if (match) {
					var url = match[0].replace(/&amp;/, '&');
					$this.mauritshuisFancybox({
						type: 'swf',
						href: url,
						titleShow: intro.length > 0,
						title: introHtml,
						titlePosition: 'inside',
						cyclic: true
					});
				}
			});
		} else {
			// toon een lightbox met een afbeelding
			$this.mauritshuisFancybox({
				type: 'image',
				href: content.find('> img').attr('src'),
				titleShow: intro.length > 0,
				title: introHtml,
				cyclic: true
			});
		}
	});
	
	$('img.contentImage').each(function () {
		var $this = $(this);
		var fullImage = $this.closest('.contentBlock').find('.fullContentImage');
		if (fullImage.length) {
			$this.css('cursor', 'pointer');
			$this.mauritshuisFancybox({
				type: 'image',
				href: fullImage.attr('href'),
				titleShow: false
			});
		}
	});
	
	$('h2.shadow').each(function () {
		var $this = $(this);
		var content = $this.html();
		$.each(['a', 'b', 'c', 'd'], function (i, k) {
			$('<span>').addClass('h2-shadow').addClass('h2-shadow-' + k).html(content).insertAfter($this);
		});
	});
});
