document.observe("dom:loaded", function(event) {
	var lightboxLinks = $$('.lightboxLink');

	if(lightboxLinks && lightboxLinks.length > 0) {
		lightboxLinks[0].show();
	}
	
	$$('.fotothumb').each( function(el) { 
		el.observe('click', function(event) {
			event.stop();
			var old_source = $('mainfoto').getAttribute('src').replace('hoofdfoto','thumb-small');
			var new_source = el.getAttribute('src').replace('thumb-small','hoofdfoto');
			var lightbox_source = new_source.replace('hoofdfoto','large');
			
			$('mainfoto').setAttribute('src', new_source);
			el.setAttribute('src', old_source);
						
			// Show correct lightbox magnifier.			
			lightboxLinks.each( function(ll) {
				ll.hide();
				if( ll.getAttribute('href') == lightbox_source ) {
					ll.show();
				}
			});
			
			// Big image links to shown image
			if($('lightboxLinkBig')) {
				$('lightboxLinkBig').setAttribute('href', lightbox_source);
			}
		});
	});
});