document.getElementsByTagName('html')[0].className = 'hasJS';

window.addEvent('domready', function () {
	/** NAVIGATION **/
	var home = $(document.body).getElement('#nav ul.topnav li:first-child');
	if ($type(home) === 'element') {
		var first = home.getFirst();

		/* if the first nav item is selected set a class on the UL (to get the corner black) */
		if (first.hasClass('selected')) {
			home.getParent('div#nav').addClass('selected');

		/* if the first nav item is not selected set events so the parent UL gets classes to make the corner black */
		} else {
			first.addEvent('mouseover', function (event) {
				home.getParent('div#nav').addClass('selected');
			});
			first.addEvent('mouseout', function (event) {
				home.getParent('div#nav').removeClass('selected');
			});
		}
	}


	/** MAILTO LINKS **/
	$$('#main a.mailto').each(function(a) {
		a.addEvent('click', buildMailToAddress.bind(this, a));
	});

	function buildMailToAddress (el) {
		var mailto = el.get('text');
		mailto = mailto.replace(/\s*\[(?:dot|punt)\]\s*/g, '.');
		mailto = mailto.replace(/\s*\[(?:at|apenstaartj?e?)\]\s*/g, '@');
		mailto = mailto.replace(/\s*\[(?:dash|hyphen|minus|min|minteken)\]\s*/g, '-');
		mailto = mailto.replace(/\s*\[(?:underscore|low ?dash|liggend ?streepje)\]\s*/g, '_');
		el.set('href', 'mailto:' + mailto);
		return true;
	}
});
