$(document).ready(function(){
		
	// add class to body tag to indicate JS is on
	
	//$('body').addClass('js');
	
	// open links in new window

	$('a.non-html').click(function() { window.open(this.href); return false; });
		
			
	// stripe tables
	
	$('.table-striped tr:even').addClass('even'); 

	// menu hide/show
	
	// script hides sidebar navigation and then opens it to the current
	// page
	
	var path = location.pathname;
	var home = '/';
	
	// check for home page
	if ( (path == home) || (path == home + 'index.htm') ) {
		path = 'home';
		var path_exists = 1;
	}
	
	// get the path automatically
	else {
				
		// if there is a query string, add it to the path
		qs = location.search;
			if (qs.length > 0) {
			path = path + qs;
		};
		
		// check if the path exists
		var path_exists = $('#navigation a[@href="' + path + '"]').length;
			
		if (!path_exists) {
			// account for default page names - index.html, index.shtml, index.php
			var last_char =  path.charAt((path.length)-1);
			
			if (last_char == '/') {
				if ($('#navigation a[@href="' + path + 'index.htm"]').length) {
					path = path + 'index.htm';
					path_exists = 1;
				}
				else if ($('#navigation a[@href="' + path + 'index.php"]').length) {
					path = path + 'index.php';
					path_exists = 1;
				}
				else if ($('#navigation a[@href="' + path + 'index.shtml"]').length) {
					path = path + 'index.shtml';
					path_exists = 1;
				}
			} // end if last char is /
			
			// if no match, check for reverse -- filename is index.* and path ends in /
			
			if (!path_exists) {			
				// get the filename to test			
				var filename;
				var x = path.length;
				while((path.substring(x,x-1)) != "/"){ x--; } 
				var clipstart = x;
				filename = path.substring(path.length,clipstart);
				
				if ((filename == 'index.htm') || (filename == 'index.php') || (filename == 'index.shtml') ) {
				
					var len = path.length - filename.length;
					
					path = path.substring(0, len);
					
					var path_exists = $('#navigation a[@href="' + path + '"]').length;
				
				} // end if filename is a default
			
			} // end if path does not exist
			
		} // end if path does not exist
	} // end get path automatically
		
	// if the path exists, then hide all nav and selectively show
	if (path_exists) {
	
		// hide all the sidebar nav
		$('#navigation li ul').hide();
		
		if (path != 'home') {
		
		// show only the current path
		$('#navigation a[@href="' + path + '"]').siblings('ul').show();
		$('#navigation a[@href="' + path + '"]').parents('ul').show();
		$('#navigation a[@href="' + path + '"]').parents('li').children('a:gt(0)').addClass('parent');
		
		// create the breadcrumbs
		
		// check if page name was set externally		
		var the_name;
		
		if (window.page_name) {
			the_name = page_name;
		}
		else {
			the_name = $('#navigation a[@href="' + path + '"]').text();
		}
		
		// check if the sub setting was set externally (to hold the nav open one level lower than usual)
		var last_link;
		
		if (window.page_sub) {
			last_link = '<a href="' + $('#navigation a[@href="' + path + '"]').attr('href') + '" title="' + $('#navigation a[@href="' + path + '"]').attr('title') + '">' + $('#navigation a[@href="' + path + '"]').html()  + '</a> <span>&nbsp;&gt;&nbsp;</span> ';
		}
		else {
			last_link ='';
		}
		

		// find the parents of the current page and create a list of links	
		var crumbs =  $('#navigation a[@href="' + path + '"]').parents('li').children('a:gt(0)').map(function () { 
		return ('<a href="' + this.href + '" title="'+ this.title +'">' + this.innerHTML + '</a>'); 
		})
		.get().reverse().join(' <span>&nbsp;&gt;&nbsp;</span> ');
		
		// add the Home link, last link if any, and the page name
		$("#breadcrumbs").append('<p><a href="/" title="Home">Home</a> ' + (crumbs ? ' <span>&gt;</span> ' +  crumbs : '') + ' <span>&nbsp;&gt;&nbsp;</span> ' + last_link + the_name + '</p>');
		
		
		// add selected class & arrow to nav item
		
		$('#navigation a[@href="' + path + '"]').prepend('&gt; ').addClass('selected');

		
	} // end if not home

	} // end if the path exists
	
});