window.addEvent('domready', function() {
	// Fix browser bugs.
	if (Browser.Engine.trident) {
		var ieVersion = parseFloat((/MSIE (.*?);/.exec(navigator.appVersion))[1]);
		if (ieVersion <= 7.0) {
			// Fix for lack of display : table and friends.
			$$('div.speech').each(function(speechBubble) {
				var speechBubbleTable = new Element('table').adopt(new Element('tbody').adopt(new Element('tr').adopt(new Element('td').adopt(new Element('span')))));
				speechBubbleTable.setStyle('width', '100%');				
				speechBubbleTable.getElement('td').setStyles(speechBubble.getElement('div').getStyles('height', 'padding', 'verticalAlign', 'textAlign'));
				speechBubbleTable.replaces(speechBubble.getElement('div'));
			});
			// Fix for menus losing focus to  images in the background.
			$$('#navigation li').each(function(navigationLink) {
				navigationLink.addEvent('mouseenter', function() {
					$$('img.absolute_overlay').each(function(absoluteOverlay) {
						absoluteOverlay.setStyle('visibility', 'hidden');
					});
				});
				navigationLink.addEvent('mouseleave', function() {
					$$('img.absolute_overlay').each(function(absoluteOverlay) {
						absoluteOverlay.setStyle('visibility', 'visible');
					});
				});
			});
		}
		if (ieVersion <= 6.0) {
			// Fix for lack of :hover
			['navigation'].each(function(hoverableContainer) {
				var h = $(hoverableContainer);
				if (h) {
					h.getElements('*').each(function(hoverable) {
						hoverable.addEvent('mouseenter', function() {
							hoverable.addClass('hover');
						});
						hoverable.addEvent('mouseleave', function() {
							hoverable.removeClass('hover');
						});
					});
				}
			});
			// If the background_fader is around, fade the page background too.
			if ($('background_fader')) $(document.body).setStyle('backgroundColor', '#808080');
		}
		// Clear alt attributes to prevent IE from showing its own tooltips.
		$$('img.sector_icon').each(function(image) { image.set('alt', ''); });
	}
	// Make menu links completely clickable.
	$$('#navigation li').each(function(li) {
		var linkUrl = li.getElement('a');
		li.setStyle('cursor', 'pointer');
		li.addEvent('click', function(e) {
			e.stop();
			window.location.href = linkUrl.href;
			
		});
	});
	// Make rel="external" links open in new windows.
	$$('a[rel=external]').each(function(a) {
		a.target = '_blank';
	});
	// Make all PDF links open in a new window.
	$$('a').each(function(link) {
		if ((/\.pdf$/i).exec(link.href) && (/\/press\//.exec(link.href) || $('current_user'))) {
			link.target = '_blank';
		}
	});
});
