
	$(document).ready
	(
		function()
		{
			var useStylesheetRolloverEffectsTop = 0; //1 if true, 0 if false
			var useStylesheetRolloverEffectsBottom = 0; //1 if true, 0 if false
			var topHoverSuffix = 'Over';
			var bottomHoverSuffix = 'On';

			if (useStylesheetRolloverEffectsTop)
			{
				$('.topNavCell').hover
				(
					function()
					{
						if (topHoverSuffix == 'On') $(this).addClass('topNavCellOn');
						else $(this).addClass('topNavCellHover'); 
						$(this).removeClass('topNavCellOff');
					}
					,
					function()
					{
						$(this).addClass('topNavCellOff');
						if (topHoverSuffix == 'On') $(this).removeClass('topNavCellOn');
						else $(this).removeClass('topNavCellHover'); 
					}
				);
			}

			if (useStylesheetRolloverEffectsBottom)
			{
				$('.bottomNavCell').hover
				(
					function()
					{
						if (bottomHoverSuffix == 'On') $(this).addClass('bottomNavCellOn');
						else $(this).addClass('bottomNavCellHover'); 
						$(this).removeClass('bottomNavCellOff');
					}
					,
					function()
					{
						$(this).addClass('bottomNavCellOff');
						if (bottomHoverSuffix == 'On') $(this).removeClass('bottomNavCellOn');
						else $(this).removeClass('bottomNavCellHover');
					}
				);
			}

			if (true)
			{
				var rolloverIsAnimated = 1; //1 if true, 0 if false
				var fadeOutAnimationTime = 750; //time to animate fade out of 'off' image in milliseconds
				var fadeInAnimationTime = 250; //time to animate fade in of 'off' image in milliseconds
				var navBaseImageType = 'gif';
				var navOverImageType = 'png';
				var navOnImageType = 'png';
				var pageId;
				var type;
				var linkText;
				var imgText;
				var target;
				$('.topNavCell').each
				(
					function()
					{
						pageId = $(this).attr('id').replace('nav','');
						imgText = '<img src="images/nav/nav';
						if ($(this).hasClass('topNavCellOn')) type = 'On';
						else type = 'Off';
						imgText += type + pageId + '.';
						if (type == 'On') imgText += navOnImageType;
						else imgText += navBaseImageType;
						linkText = $(this).children('span').text(); //use text() rather than html() to eliminate possible anchor tags inside span
						imgText += '" alt="' + linkText + '" />';
						if ($(this).children('span').children('a').length == 0) $(this).children('span').html(imgText); //navText span does not contain a link
						else $(this).children('span').children('a').html(imgText); //nest image tag inside link
						var backgroundImageText = 'url(images/nav/nav' + topHoverSuffix + pageId + '.' + navOverImageType + ')';
						if (rolloverIsAnimated && $(this).hasClass('topNavCellOff')) $(this).children('span').css('background-image', backgroundImageText);
						if ($(this).hasClass('topNavCellOff') && !$(this).hasClass('topNavCellHasChildren'))
						{
							$(this).hover
							(
								function()
								{
									if (rolloverIsAnimated) $('img:eq(0)',this).fadeTo(fadeOutAnimationTime,0.01); //can't fade out completely because that triggers mouseout behavior and momentarily loses link; image that fades out can't be png due to problems animating opacity of pngs in IE (IE 8, at least)
									else
									{
										pageId = $(this).attr('id').replace('nav',''); //otherwise page id will still be that of last nav link due to cycling through all nav links initially, before hover happens
										$('img:eq(0)',this).attr('src','images/nav/nav' + topHoverSuffix + pageId + '.' + navOverImageType);
									}
								}
								,
								function()
								{
									if (rolloverIsAnimated) $('img:eq(0)',this).fadeTo(fadeInAnimationTime,1);
									else $('img:eq(0)',this).attr('src','images/nav/navOff' + pageId + '.' + navBaseImageType);
								}
							);
						}
					}
				);
			} 

			if (true)
			{
				var headingImageType = 'gif';
				var pageId;
				var linkText;
				var imgText;
				$('.pageHeading').each
				(
					function()
					{
						pageId = $(this).attr('id').replace('heading','');
						imgText = '<img src="images/headings/heading' + pageId + '.' + headingImageType;
						linkText = $(this).html();
						imgText += '" alt="' + linkText + '" />';
						$(this).html(imgText);
					}
				);
			} 
		}
	);

	$(window).load
	(
		function()
		{

			//nav arrows - use "$(window).load()" rather than "$(document).ready()" to to make sure nav bar elements are in final position before drawing arrows
			var positions = ['top','bottom'];
			for (var i=0; i<2; i++)
			{
				var position = positions[i];
				$('img.' + position + 'Arrow').each
				(
					function(imageIndex,imageObject)
					{
						var startLeft = $($('td.' + position + 'NavCellOn')[imageIndex]).position().left;
						var startWidth = $($('td.' + position + 'NavCellOn')[imageIndex]).width();
						var start = startLeft + startWidth/2;
						var endLeft = $($('td.' + position + 'NavCellOn')[imageIndex + 1]).position().left;
						var endWidth = $($('td.' + position + 'NavCellOn')[imageIndex + 1]).width();
						var end = endLeft + endWidth/2;
						imageObject.src = 'arrowimage.php?position=' + position + '&start=' + start + '&end=' + end;
					}
				);
			}
	
			//hide bottom nav bar if page height < min height for showing it, where min height > 0 (= 0 means no minimum) - use "$(window).load()" rather than "$(document).ready()" to to make sure everything has assumed its final height before determinig height of overall document
			if (0 > 0 && $(document).height() < 0)  $('#bottomNav').hide();
		}
	);

