// JQuery-based CSS menus by Smart Multimedia - http://www.smartmultimedia.com.au

var menuTimer;

function hideOldMenu(menuWrapperElement) {
	$(menuWrapperElement + ' li.oldhover').removeClass("hover");	
	$(menuWrapperElement + ' li.oldhover').removeClass("oldhover");
}
function hideAllMenusAndStop() {
	hideOldMenu('#mainNav');
	clearTimeout(menuTimer);
}

$(function(){
	// initialise the CSS menus
	$('#mainNav li:last-child').addClass("last");
	$('#mainNav ul ul ..').addClass("hasSublevels");
	$('#mainNav li').hover(function(){
		hideOldMenu('#mainNav');
		$(this).addClass("hover");
	},function(){
		$(this).addClass("oldhover");
		menuTimer = setTimeout('hideOldMenu("#mainNav")', 1500);
	});
	$('.subNav li').hover(function(){
		hideOldMenu('.subNav');
		$(this).addClass("hover");
	},function(){
		$(this).addClass("oldhover");
		menuTimer = setTimeout('hideOldMenu(".subNav")', 1500);
	});
	
	// automatically set the target of each external href
	var thisUrl = '';
	var thisDomain = window.location.href.substring(0, window.location.href.indexOf('/',7)+1);
  	if (thisDomain) {
		$('#contentRow a').each(function(i){
	  		thisUrl = $(this).attr('href');
	  		if ( (thisUrl.indexOf('http://') >= 0)  &&  (thisUrl.indexOf(thisDomain)<=-1) ) {
	  		   $(this).attr('target', '_blank');	
	  		} else {
	  			if ( (thisUrl.indexOf('.pdf') >= 0)  ||  (thisUrl.indexOf('.doc') >= 0) ) {
	  		   	   $(this).attr('target', '_blank');
	  			} else {
	  			   $(this).attr('target', '_self');
	  			}
	  		}
		});
	}

});

