$(document).ready(function() {



// acronym
	
	// find the acronyms extracts the title and store it in var acronymTITLE.
	$('acronym').each( function (){
		var acronymTITLE = $(this).attr('title');
		// then insert a span inside the acronym tag and write the value of var acronymTITLE inside the span.
		$(this).append('<div class="acronym">'+acronymTITLE+'</div>');
	});

	// when your mouse is on an acronym fade in the span.
	$('acronym').mouseenter(function(){
		$(this).children('.acronym').fadeIn(300);
	});
	
	// when your mouse comes off an acronym fade out the span.
	$('acronym').mouseleave(function(){
		$(this).children('.acronym').fadeOut(300);
	});

	// clear the acronym titles.
	$('acronym').attr('title','');



// abbr

	// find the abbr extracts the title and store it in var abbrTITLE.
	$('abbr').each( function (){
		var abbrTITLE = $(this).attr('title');
		// then insert a span inside the abbr tag and write the value of var abbrTITLE inside the span.
		$(this).append('<div class="abbr">'+abbrTITLE+'</div>');
	});

	// when your mouse is on an abbr fade in the span.
	$('abbr').mouseenter(function(){
		$(this).children('.abbr').fadeIn(300);
	});
	
	// when your mouse comes off an abbr fade out the span.
	$('abbr').mouseleave(function(){
		$(this).children('.abbr').fadeOut(300);
	});

	// clear the abbr titles.
	$('abbr').attr('title','');



// table

	// find the tables and resets cellspacing and cellpadding. Also adds the formatted tr classes to alternating rows.
	$('table').each( function (){
		$(this).attr('cellspacing','0');
		$(this).attr('cellpadding','0');
		$(this).find('tr:nth-child(even)').addClass('tr_even');
		$(this).find('tr:nth-child(odd)').addClass('tr_odd');
		$(this).find('td:nth-child(even)').addClass('td_even');
	});
	// this removes the above mod, add any classes or id's you want to ignore the mod.
	$('table.no_format').each( function (){
		$(this).find('tr:nth-child(even)').removeClass('tr_even');
		$(this).find('tr:nth-child(odd)').removeClass('tr_odd');
		$(this).find('td:nth-child(even)').removeClass('td_even');
	});



// ordered list

	// Find each list
	$('ol').each( function (){
		// Find the li's and add level 1 class then insert a level 1 div for the bullet.
		$(this).children('li').each( function(){
			// This auto counts the # of level 1 li's and inserts the # as the bullet.
			$(this).addClass('li_lv1');
			var lv1COUNT = $(this).parent('ol').children('.li_lv1').size();
			// Insert the div as the top element inside the li. This prevent the level 1 bullet from displaying below an internal list. 
			$('<div class="div_lv1">'+lv1COUNT+'</div>').prependTo(this);								  

		});

		// Find the internal lists li's and add level 2 class then insert a level 2 div for the bullet.
		$(this).children('li').children('ol').children('li').each( function (){
			// This removes the level 1 classes from any level 2 li's and add a level 2 class.
			$(this).removeClass('li_lv1');
			$(this).addClass('li_lv2');
			// This auto counts the # of level 2 li's and inserts the # as the bullet after the decimal.
			var lv2COUNT = $(this).parent('ol').children('.li_lv2').size();
			// This finds the # of the parent bullet and inserts inserts # as the bullet before the decimal.
			var lv2ANCHOR = $(this).parent('ol').parent('li').children('.div_lv1').text();
			// Insert the div as the top element inside the li. 
			$('<div class="div_lv2">'+lv2ANCHOR+'.'+lv2COUNT+'</div>').prependTo(this);								  
		});

		// This removes the level 1 li's from any level 2 li's.
		$('.li_lv2').children('.div_lv1').remove();	
	});

	

// unordered list

		// Find each list
		$('ul').each( function (){
		
		// Find the li's and add level 1 class then insert a level 1 div for the bullet.
		$(this).children('li').each( function(){
			$(this).addClass('li_lv1');
			// Insert the div as the top element inside the li. This prevent the level 1 bullet from displaying below an internal list. 
			$('<div class="div_lv1"></div>').prependTo(this);								  
		});

		// Find the internal lists li's and add level 2 class then insert a level 2 div for the bullet.
		$(this).children('li').children('ul').children('li').each( function (){
			// This removes the level 1 classes form any level 2 li's and add a level 2 class.
			$(this).removeClass('li_lv1');
			$(this).addClass('li_lv2');
			// Insert the div as the top element inside the li. 
			$('<div class="div_lv2"></div>').prependTo(this);								  
		});

		// This removes the level 1 li's from any level 2 li's.
		$('.li_lv2').children('.div_lv1').remove();	
	});

	// this removes the above mod, add any classes or id's you want to ignore the mod.
	$('ul.h_nav, ul.v_nav, ul.no_format, ul#breadcrumbs, ul#sitemap, ul.remove_bullets').each( function (){
		$(this).find('.div_lv1').remove();
		$(this).find('.div_lv2').remove();
		$(this).find('li').removeClass('li_lv1');
		$(this).find('li').removeClass('li_lv2');
	});



// hr

	//replace all hr with a custom div.
	$('hr').replaceWith('<div class="hr"></div>');



// text buttons

	// Find each text button and wrap the internal text with a div.text
	$('#archive > li > a').addClass('txt_btn');
	$('a.txt_btn').wrapInner('<div class="text"></div>');

	$('.scroll_href').click(function(e) {
		e.preventDefault();
		var target = $(this).attr('href');
		var cushion = 20
		var target_pos = $(target).offset().top - cushion
		var scroll_time = 2000
		$('html, body').animate({scrollTop: target_pos}, scroll_time);
	});


	$('.page_nav').each( function(){
		$(this).children('li').hide();
		$(this).children('li').first().show();

		$(this).children('li').first().click( function(e){
			e.preventDefault();
			$(this).siblings('li').toggle('slow');
	    });

	});
	
});
