function removeBorderBottom(element) {
	if (element) { element.addClass('last'); }
}

function initSlideShow(wpr, season) {

	var slideShowPhotoPath = '/layouts/engelenburg/images/banner/' + season + '/';
	var photos = [
		'img-01.jpg',
		'img-02.jpg',
		'img-03.jpg',
		'img-04.jpg',
		'img-05.jpg'
	];

	// create slideshow
	var slideshow = new Slideshow(wpr, photos, {
		loader: false,
		hu: slideShowPhotoPath,
		width: 960,
		height: 340,
		delay: 3000,
		duration: 1000,
		random: true
	});
}

window.addEvent('domready', function() {

	// define constants
	var body          = $(document.body);
	var mainmenu      = $('mainmenu');
	var wprSlideshow  = $('slideshow');
	var sidebarLeft   = $('sidebar-left');
	var content       = $('content');
	var sidebarRight  = $('sidebar-right');
	var slimbox_exts, contents, season, seasonColor;

	// define season and season color
	if      (body.hasClass('spring')) { season = 'spring'; seasonColor = '#95ab3d'; }
	else if (body.hasClass('summer')) { season = 'summer'; seasonColor = '#e3b200'; }
	else if (body.hasClass('autumn')) { season = 'autumn'; seasonColor = '#645729'; }
	else if (body.hasClass('winter')) { season = 'winter'; seasonColor = '#54779f'; }

	// animate mainmenu
	if (mainmenu) {
		var mainmenuItems = mainmenu.getElements('li');

		mainmenuItems.each(function(mainmenuItem) {

			mainmenuItem.morphFX = new Fx.Morph(mainmenuItem).set({'background-color': '#551a12'});

			mainmenuItem.addEvents({
				'mouseover': function(){
					if (!this.hasClass('current')) {
						this.morphFX.pause();
						this.morphFX.start({'background-color': seasonColor});
					}
				},
				'mouseout': function(){
					if (!this.hasClass('current')) {
						this.morphFX.pause();
						this.morphFX.start({'background-color': '#551a12'});
					}
				}
			});

			if (mainmenuItem.hasClass('current')) {
				mainmenuItem.morphFX.set({'background-color': seasonColor});
			}
		});
	}

	// form behaviours
	var formElements = $$('.content form input:not(.submit), .content form textarea');
	formElements.each(function(formElement) {
		formElement.addEvents({
			'focus': function(e) {
				this.addClass('current');
			},
			'blur': function(e) {
				this.removeClass('current');
			}
		});
	});

	// init slideshow
	initSlideShow(wprSlideshow, season);

	// remove border bottoms from last content items
	if (sidebarLeft)  { removeBorderBottom(sidebarLeft.getLast('div.content')); }
	if (content)      { removeBorderBottom(content.getLast('div.content')); }
	if (sidebarRight) { removeBorderBottom(sidebarRight.getLast('div.content')); }

	// margin thumbnail photo-album
	var photoAlbums = body.getElements('.photo-album');

	photoAlbums.each(function(album) {
		album.addClass('photo-album-js');
		var thumbs = album.getElements('img');
		thumbs.each(function(thumb, index) {
			if (((index + 1) % 3) == 0) {
				thumb.addClass('last');
			}
		});
	});

	// init Slimbox
	slimbox_exts = ['jpg', 'jpeg', 'png', 'gif'];
	contents     = $$('#main .content');

	contents.each(function(content, index) {
		var links  = content.getElements('a[href$=.jpg], a[href$=.jpeg], a[href$=.png], a[href$=.gif]');

		if (links.length > 0) {

			links.slimbox({
				captionAnimationDuration: 300,
				overlayOpacity: 0.9,
				counterText: "foto {x} van {y}",
				resizeDuration: 500
			});

		}
	});
});