/*
 * @param 	navTagName		name of div tag to inject menu into
 * @param	navFilename		location of JSON file containing nav structure
 * 
 * -required javascript files:	jquery-1.2.1.min.js, 'navFilename'
 * 
 *  usage
 *  -----
 *  1) include the following at the top of every html page
 *  	<script src="jquery-1.2.1.min.js" type="text/javascript></script>
 *  	<script src="nav.js" type="text/javascript"></script>
 *  
 *  2) make sure that you have a div tag with whatever ID you want, but make sure below (in the code)
 *  	that 'navTagName' is equal to your ID name
 *  3) that's it!
 *  
 *  -sk
 */
$(document).ready(function(){
	var navTagName = 'nav'; // div tag (id) where you want nav text injected
	var navFilename = 'includes/navItems.js'; // location of JSON file with nav items

	// don't touch anything below here...	
	$.ajaxSetup({async:false});
	var s = '<ul>';
	$.getJSON(navFilename, function success(json){
		$.each(json, function(i, data){
			var insertTarget = false;
			
			var link = data.link;
			var target = data.target;
			var className = data.className;
			var numericID = data.numericID;
			var displayText = data.displayText;
			
			if (target != '' && target != undefined) insertTarget = true;
	
			s += '<li><a href="' + link + '"';
			if (insertTarget) s += ' target="' + target + '"';
			s += ' class="' + className + '"><span class="dot">&bull;</span><strong>' + numericID + '</strong><br />' + displayText + '</a></li>\n';
		});
		
		s += '</ul>';
	$('#' + navTagName).html(s);
	
	var url = window.location.href;
	var currentURL = url.substring(url.lastIndexOf('/') + 1);
	
	$('#' + navTagName + ' ul li').each(function(){
		var id = $(this).find('a');
		console.log(id);
		if (id.attr('href') == currentURL) $(id).addClass('selected');
	});
		
	});
	
});
