
$(document).ready(function() {

	if (! modern_browser()) {
	
		// Fixes for non-CSS3 browsers

		$('A:first-child').addClass('first-child');
		$('A:last-child').addClass('last-child');
		$('LI:first-child').addClass('first-child');
		$('LI:last-child').addClass('last-child');
		$('LI:nth-child(odd)').addClass('nth-child-odd');
		$('LI:nth-child(even)').addClass('nth-child-even');
		$('BODY.sub-page #content .column-main P:first').addClass('first-of-type');

		
		// Fixes for IE7 or older
		
		/*if ($.browser.msie && parseFloat($.browser.version) < 8) {*/

			// Emulate correct 'clear: left' behaviour by setting height explicitly
			$('#content UL.nav-collage > LI').each(function() {
				var h = $(this)[$(this).hasClass('nth-child-odd') ? 'next' : 'prev']().height();
				if ($(this).height() < h) $(this).height(h);
			});
		/*}*/


		// Fixes for pre-historical browsers

		if ($.browser.msie && parseFloat($.browser.version) < 7) {
			$('.column-top :first-child').addClass('first-child');
			$('#header .nav-main li').hover(function() {
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
			});
		}

	}

	// De-obfuscate emails
	$('A[href^=mailto:][href$=.example.com]').each(function() {
		var email = $(this).attr('href').substr(7).split('').reverse().join('').substr(12);
		$(this).attr('href', 'mailto:' + email);
		if ($(this).text().indexOf('@') != -1)
			$(this).text(email);
	});

	// Make sure the container for absolute/bottom-positioned corner image is tall enough
	var img = $('.subfront-page #content .column-top .column-first IMG');
	var needed_height = img.height();
	img.attr('title', needed_height);
	var column = $('#content .column-top');
	if (column.height() < needed_height)
		column.height(needed_height);
	if ($.browser.msie && parseFloat($.browser.version) < 7)
		img.css('bottom', '1.5em');  // re-set bottom value or image won't be positioned against new parent height
		
});


function modern_browser() {
	// Note: this is just for speed-up - css3 stuff is always backed up by js.
	// Only popular browsers are detected as non-css3, i.e. Camino etc. are
	// assumed to be up to date.
	return ! (
		// IE 9+
		($.browser.msie && parseFloat($.browser.version) < 9) ||

		// FF 3.1+
		($.browser.mozilla && (parseFloat(jQuery.browser.version.substr(0, 3)) < 1.9
			|| (parseFloat(jQuery.browser.version.substr(0, 3)) == 1.9
			&& parseInt(jQuery.browser.version.substr(4, 1)) < 1))) ||

		// Safari 3+
		($.browser.safari && parseInt($.browser.version) < 522) ||

		// Opera 9+
		($.browser.opera && parseFloat($.browser.version) < 9) ||

		// Konqueror 3.4+
		(navigator.userAgent.toLowerCase().indexOf('khtml') != -1 && parseFloat($.browser.version) < 3.4)
	);
}

function launchWin(url, dlgname, w, h) 
{
  settings = "toolbar=0,location=0,status=yes,menubar=0,scrollbars=auto,width=" + w + ",height=" + h;
  windowObj = window.open(url, dlgname, settings);
  windowObj.focus();
}
