$(function() {
	
	// configure superfish for the main nav
	$('#nav_top > ul')
		.supersubs({ 
			minWidth:    12,   // minimum width of sub-menus in em units 
			maxWidth:    27,   // maximum width of sub-menus in em units 
			extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
			// due to slight rounding differences and font-family 
		})
		.superfish({
			animation: { 
				opacity:'show',
				height:'show'
			},
			speed: 'fast',
			autoArrows: false,
			delay: 100
		})
		.find('ul').bgIframe({opacity:false});
	
	// addclass for last li in each ul in main nav
	$('.sf-menu ul').find('li:last').addClass('last');
	
	// addclass for first li in footer nav
	$('#footer li:first').addClass('first');
	
	// make external links open in new window
	$('#header div, #col1, #col2 div').find('a[href^="http"]').addClass('external').attr('target', '_blank');
	
	// split long unordered lists in two
	$('ul.splitcol').each(function(i){
			var colsize = Math.round($(this).find("li").size() / 2);
			$(this).find("li").each(function(i) {
				if (i>=colsize){
					$(this).addClass('splitcol_right');
				}
			});
			$(this).find('.splitcol_right').removeClass('splitcol_right').insertAfter(this).wrapAll("<ul class='splitcol'></ul>");
		}
	);
	
	// fade form error message tooltips
	$('div.fb_invalid').mouseenter(function(){
		$(this).children('.error_message').fadeOut('fast');
	});
	
});
