document.observe('dom:loaded', function() {
	/* subNav onMouseOver/onMouseOut */
	$('nav').childElements().each(function(el) {
		if ( el.descendants().size() > 1 ) { // Groter dan 1, want element moet A- en UL-tag bevatten
			Event.observe(el, 'mouseover', function(event) {
				el.descendants()[1].setStyle({display: 'block'}); // el.descendants()[1] = UL van sub
			});
			Event.observe(el, 'mouseout', function(event) {
				el.descendants()[1].setStyle({display: 'none'});
			});
			/* Navigatie links van het eerste niveau tegenhouden als deze een submenu hebben */
			Event.observe(el.descendants()[0], 'click', function(event) {
				Event.stop(event);
			});
		}
	});

	// If there is more than one photo, hide them all, except the first one
	if ( $('photo') != null ) {
		var numPhotos = $('photo').select('img').size();
		if ( numPhotos > 1 ) {
			for (var i=1; i<numPhotos; i++) {
				$('photo').descendants()[i].setStyle({opacity: 0});
			}
			startSlideshow();
		}
	}
});

function startSlideshow() {
	var curImg = 0;
	var photo = $('photo').select('img');
	var numPhotos = photo.size();

	pe = new PeriodicalExecuter(function() {
		new Effect.Opacity(photo[curImg], {duration: 1.5, from: 1.0, to: 0.0, fps: 100});
		var nextImg = (curImg === numPhotos-1) ? 0 : curImg+1;
		new Effect.Opacity(photo[nextImg], {duration: 1.5, from: 0.0, to: 1.0, fps: 100, afterFinish: function() {
				curImg = nextImg;
			}
		});
	}, 5);
}
