// JavaScript Document

$(document).ready(function(){
  	
  	//hide every child in the first dl
	$('dl#first-gloss > *').hide();
	
	//for every dt in the dl
	$('dl#first-gloss dt').each(function() {
	
		//store the first letter of the dt it's looking at
		var letter = $(this).text().substring(0, 1);
		
		//add a class equal to that letter to the dt
		$(this).addClass(letter);
		
		//add a class equal to that letter to the dd
		$(this).next().addClass(letter);
		
		//store the next letter and test if it's the same as the previous one
		var next_letter = $(this).next().next().text().substring(0, 1);
		if(letter !== next_letter) {
			//if it is not, make a nav item for the glossary
			$('<a>'+letter+'</a>').appendTo('#gloss-nav');
		}
	});
	
	//when you click the nav item
	$('#gloss-nav a').click(function() {
		
		//hide everything
		$('dl#first-gloss > *').hide();
		
		//fade the associated stuff in
		$('.'+$(this).text()).fadeIn('slow');
	});
	
	buildMiniNav();
  
});

function buildMiniNav() {
  $('.miniNav').append(
    '\n<li><a href="/index.php#top">Contact Info</a></li>' 
    + '\n<li><a href="/index.php#about">About Me</a></li>'
    + '\n<li><a href="/index.php#fayetteville">About Fayetteville</a></li>'
    + '\n<li><a href="/index.php#buyers">For Buyers</a></li>'
    + '\n<li><a href="/index.php#sellers">For Sellers</a></li>'
    + '\n<li><a href="/index.php#glossary">Glossary</a></li>\n'
  );
  $('.miniNav').css('height','25px');
}