window.addEvent('domready', function() {
	// Add dynamic input boxes
	var dynamicInput = new DynamicInput('input, textarea');

	// Add news ticker
	new Ticker('newsticker', {
		effect: {
			duration: 500
		}
	});

	// Setup slideshows
	$$('#content .slideshow').each(function(element) {
		var slideshow = new Slideshow.Controlled({
			container: element,
			elements: 'li',
			wait: 6000,
			duration: 1250,
			transition: Fx.Transitions.linear,
			autoStart: true,
			controlsContainer: new Element('li', {
				'class': 'navigation'
			})
		});
	});

	// Add focussed style to .round element
	$$('.round input, .round textarea').addEvents({
		'focus': function() { this.getParent().addClass('focussed'); },
		'blur': function() { this.getParent().removeClass('focussed'); }
	}).each(function(element) {
		if (element.hasClass('ivld')) {
			element.getParent().addClass('focussed');
		}
	});

	// Clickable frontpage blocks
	$$('#content div[id^=frontpage]').each(function(element) {
		var link = element.getElement('a');
		if (link) {
			element.setStyle('cursor', 'pointer');
			element.addEvents({
				'mouseenter': function() {
					element.addClass('hover');
				},
				'mouseleave': function() {
					element.removeClass('hover');
				},
				'click': function(e) {
					if ($(e.target).get('tag') != 'a') {
						if (e.shift || e.control) {
							window.open(link.get('href'));
						} else {
							window.location.href = link.get('href');
						}
					}
				}
			});
		}
	});

	// Open links in new window
	$$(document.links).filter(function(a) {
		// Only open link in new window if:
		// - link doesn't already have a target
		// - the domain is different
		// - the link has the class 'external'
		return !a.getProperty('target') &&
               (a.href.test('^http', 'i') && !a.href.test('^' + document.location.href.substring(0, document.location.href.indexOf('/', 8)), 'i')) ||
               a.href.test('.pdf$', 'i') ||
               a.hasClass('external');
	}).setProperty('target', '_blank');
});