/**
 * 
 */

function buildHeaderAndNavBar()
{
	buildHeader();
	buildNavBar();
}
 
function buildHeader()
{
	document.writeln( "<div class=\"header\">" );
	document.writeln( "<h1>" );
	document.write( document.title );
	document.writeln( "</h1>" );
	document.writeln( "</div>" );
}

function buildNavBar()
{
	document.writeln( "<div class=\"navbar\">" );
	document.writeln( "<p style=\"text-align:center\">" );

	var docPath = window.location.pathname.substring(0);
	/** 
	 * Normalize the docPath so that if it ends in "/index.html"
	 * we strip that part off and just leave the trailing "/"
	 */
	//if( docPath.match(/\/$/) ) 
	//	docPath += "index.html";
	docPath = docPath.replace( /\/index.html$/, "/" );
	
	/**
	 * If docPath is just "/", clear it out
	 */
	
	docPath = docPath.replace( /^\/$/, "" );
	
	/**
	 * Now, if docPath ends in something like this:
	 * ..../dir_name/, strip off the "dir_name/" part
	 */

	docPath = docPath.replace( /\/[^\/]+\/$/, "/" );
	
	/**
	 * One more thing...if docPath end in *.html, strip that off
	 */
	 
	docPath = docPath.replace( /\/[^\/]+\.html$/, "/" );
	

	/**
	 * OK, I lied...if docPath ends with ".cgi", replace it with "/"
	 */
	 
	if( docPath.match(/\.cgi$/) ) docPath = "/";
	
	var docs = docPath.split("/");
	
	
	var links = new Array();
	var names = new Array();
	if( docs.length > 1 )
	{
		links[links.length] = "/";
		names[names.length] = "Gordy-n-Mikie";
		for( var i = 0; i < docs.length; ++i )
		{			
			if( docs[i].length > 0 && docs[i] != "index.html")
			{
				var newIdx = links.length;
				links[newIdx] = links[newIdx-1] + docs[i] + "/";
				names[newIdx] = docs[i];
			}
		}
	}
	
	if( docPath.length > 0 )
	{	
		for( var i = 0; i < links.length; ++i )
		{
			document.writeln( "<a href=\"" + links[i] + "\">"+names[i]+"</a><br />" );	
			document.writeln( "&uarr;<br />" );
		}
	}
	document.writeln( "</p>" );
	
	document.writeln( "<form id=\"search_form\" method=\"get\" onsubmit=\"javascript:return checkSearchSubmit()\" action=\"/cgi-bin/search.cgi\">");
	document.writeln( "<p style=\"text-align:center\">");
	document.writeln( "<input type=\"text\" id=\"find\" name=\"find\" size=\"15\" />");
	document.writeln( "<img style=\"vertical-align:middle\" onclick=\"javascript:submitSearch()\" alt=\"btn-search\" src=\"/images/btn-search.gif\" />");
	document.writeln( "</p>");
	document.writeln( "</form>");
	
	document.writeln( "<p style=\"text-align:center\">" );
	document.writeln( "Last Updated:<br />" );
	document.write( document.lastModified );

	document.writeln( "</p>" );
	document.writeln( "<p style=\"text-align:center\">" );
	document.writeln( "Designed on, and<br />" );
	document.writeln( "Best viewed with a:<br /><br />" );
	document.writeln( "<a href=\"http://www.apple.com/macosx/\">" );
	document.writeln( "	<img alt=\"macosx\" src=\"/images/macoslogo.png\" />" );
	document.writeln( "</a>" );
	document.writeln( "</p>" );
	document.writeln( "<p style=\"text-align:center\">" );
	document.writeln( "<a href=\"http://www.w3.org/\">" );
	document.writeln( "	<img alt=\"Valid XHTML 1.0!\" src=\"/images/valid-xhtml10.png\" />" );
	document.writeln( "</a>" );
	document.writeln( "</p>" );
	document.writeln( "</div>" );
	
}

function popImg( imgUrl )
{
	var callerUrl = window.location.href;
	var baseUrl = callerUrl.replace( /\/[^\/]+$/, "/" );
	window.open( "/cgi-bin/popImg.cgi?url="+baseUrl + imgUrl, "pop_image" );
}

/**
 * Pop open a small centered window (500 x 120), 
 */
function popAudio( audioUrl, windowTitle )
{
	var ww = 500;
	var wh = 200;
	var sw = screen.width;
	var sh = screen.height;
	var x = (sw-ww)/2;
	var y = (sh-wh)/2;

	var callerUrl = window.location.href;
	var baseUrl = callerUrl.replace( /\/[^\/]+$/, "/" );
	window.open( "/cgi-bin/popAudio.cgi?url="+baseUrl + audioUrl +
		"&title=" + windowTitle , 
		"pop_audio",
		"height=120,width=500" + ",left=" + x + ",top=" + y 	
	);
}


function searchKeyUp( evt )
{
	evt = (evt) ? evt : ((event) ? event : null );
	if( evt )
	{
		
	}
}

function checkSearchSubmit()
{
	var findTxt = document.getElementById( "find" );
	if( findTxt.value.length > 0 )
		return true;
	else
		alert( "You have to enter something to search for!" );

	return false;
}

function submitSearch()
{
	if( checkSearchSubmit() )
	{
		var searchForm = document.getElementById( "search_form" );
		searchForm.submit();
	}	
}