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

	// known extensions for downloadable and shadowbox files
	var exts  = ['jpg', 'jpeg', 'png', 'gif', 'mov', 'wmv', 'pdf', 'doc', 'xls', 'ppt', 'zip', 'gz', 'mpg', 'mpeg', 'mp4', 'avi', 'mp3', 'wav', 'tif', 'tiff', 'svg'];
	var links = $$('#content a, #aside-0 a, #aside-1 a');
	var initShadowbox = false;

	links.each(function(link, index) {

		// find extension
		var split_slash = link.getProperty('href').split('/');
		var split_ext   = split_slash.getLast().split('.');
		var ext         = split_ext.getLast();

		// check if extension indicates a downloadable file or mediafile
		if (split_ext.length > 1) {
			if (exts.contains(ext)) {
				link.setProperty('target', '_blank');
				initShadowbox = true;
			}
		}

		// look for links to youtube (init shadowbox)
		if (link.href.substring(0, 23) == 'http://www.youtube.com/') {
			initShadowbox = true;
		}

		// look for links to other sites
		if (link.href.substring(0, 7) == 'http://') {
			if (link.href.substring(7, 7 + window.location.hostname.length) != window.location.hostname) {
				link.target = '_blank';
			}
		}

		if (link.href.substring(0, 8) == 'https://') {
			if (link.href.substring(8, 8 + window.location.hostname.length) != window.location.hostname) {
				link.target = '_blank';
			}
		}
	});

	// init shadowbox
	if (initShadowbox == true) {
		Shadowbox.init();
	}
});
