$(document).ready(function(){
	
	// Main nav //
	// Works with pure CSS on all except IE - JS for enhancements across all, and to work in IE6
	function showSubNav() {
    $(this).addClass('hover');
		$(this).siblings('li.primary').removeClass('hover');
		$('ul.show').removeClass('show');
		showCount++;
  };
	
	function hideSubNav() {
    if (showCount < 2)
    {
      $(this).removeClass('hover');
	    $('a.on').next('ul').addClass('show');
	  }
    showCount--;
	  // just in case but should never happen!!!
    if (showCount < 0) showCount = 0;
	};
	
  var showCount	= 0;
	// For mouse users
	
	var config = {    
	     sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
	     interval: 50, // number = milliseconds for onMouseOver polling interval    
	     over: showSubNav, // function = onMouseOver callback (REQUIRED)    
	     timeout: 200, // number = milliseconds delay before onMouseOut    
	     out: hideSubNav // function = onMouseOut callback (REQUIRED)    
	};
	
	$('li.primary').hoverIntent(config);
	
	// For keyboard users using the tab key
	function showSubNavKB(navItem) {
		$(navItem).addClass('hover');
		$(navItem).siblings('li.primary').removeClass('hover');
		$('ul.show').removeClass('show');
	};
	function hideSubNavKB(navItem) {
		$(navItem).removeClass('hover');
		$('a.on').next('ul').addClass('show');
	};
	
	$('li.primary a').focus(function(){
		showSubNavKB($(this).parents('li.primary'));
	});
	$('li.primary a').blur(function(){
		hideSubNavKB($(this).parents('li.primary'))
	});
	
	
	
	// Subnav //
	function navSlide() {
		if ($('#nav-left li.active ul li a').hasClass('on')){
			$('#nav-left li.active ul').show();
		}
		else {
			$('#nav-left li.active ul').slideDown('slow');
		}
	};	
	navSlide();
	
	// PDF link //
	// - Finds all links that link to .pdf documents and adds a class to display PDF icon	
	$('a[href$=".pdf"]').addClass('pdf');
	
	// Page tools //
	// - Writes in the "Print page" link after the breadcrumb
	$('#breadcrumb').after('<div class="page-tools"><a href="javascript:window.print();" title="Print this page"><img src="/images/icons/icon-print.gif" alt="Print this page" /> Print page</a></div>');
	
	// Zebra striping //
	// - Aesthetic affect for listings	
	$('.listing li:odd').addClass('alt');
	
	// Resources - grid enhancement //
	// - Aesthetically enhanced to display better than standard CSS
	$('.grid.two-column .block').addClass('enhanced');
	$('.grid.two-column .block:odd').addClass('end');
	
	$('.grid.three-column .block').addClass('enhanced');
	$('.grid.three-column .block:nth-child(3n-1)').addClass('middle');
	$('.grid.three-column .block:nth-child(3n)').addClass('end');
	
});