/* Check to insure logo rollovers work */
if ( document.images )
{
	logoNormal = new Image();
	logoNormal.src = "/odslogo.gif";
	logoAlternate = new Image();
	logoAlternate.src = "/odslogo2.gif";
}

/* This section determines the browser being used, its version and the operating system. */
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
/* End of section to determine browser, etc. */
//document.write("Browser: " + browser + "<br>Version: " + version);

/* Ensure only try to load menus once per page */
doneMenu = 'N';

/* Function to change image to its alternate state on mouseover */
function imageOver( name )
{
	if ( document.images )
	{
		document["logo"].src = eval("logoAlternate.src");
	}
}

/* Function to revert image to its normal state on mouseout */
function imageOut( name )
{
	if ( document.images )
	{
		document["logo"].src = eval("logoNormal.src");
	}
}

/* Display given text onMouseOver of whatever */
function mOver(txt)
{
    window.status=txt;
    return true;
}

/* Clear whatever text displayed onMouseOut of whatever */
function mOut()
{
	window.status="";
}

/* Display previous window */
function goback()
{
	window.history.back()
}

/* Open a new window of the specified size. However, we're not going to open one that  */
/* is larger than will fit on the users screen so we check for the available width and */
/* and height. Don't ask me why I need to subtract the extra 10/30 pixels, you just    */
/* seem to need to, to get it to display correctly!                                    */
/* The new window is positioned top, left of the screen. The left and top arguments    */
/* are strictly IE only, but Netscape doesn't complain, so it'll do for the moment.    */
function newWindow(url, x, y)
{
	//w = Math.min( x, (screen.availWidth-10) );
	//h = Math.min( y, (screen.availHeight-30) );
	//options = "scrollbars,resizable,width=" + w + ",height=" + h + ",left=0,top=0";
	//window.open(url, "_blank", options);
	//return false;
	newWindow(url, x, y, 0, 0);
}

function newWindow(url, x, y, off1, off2)
{
	w = Math.min( x, (screen.availWidth-10) );
	h = Math.min( y, (screen.availHeight-30) );
	options = "scrollbars,resizable,width=" + w + ",height=" + h + ",left=" + off1 + ",top=" + off2;
	window.open(url, "_blank", options);
	return false;
}

/* Open a new window with the default toolbars, etc. for the given url. */
/* Typically used when opening a link to an external website.           */
function extWindow( url )
{
	window.open( url, "_blank" );
	return false;
}

/* Opens 'vanished.htm' in a new window. Used for societies whose website is defunct. */
function vanished()
{
	return newWindow('/authors/norman_robbins/vanished.htm',450,320);
}

/*
* Write the navigation to appear at the top and bottom of each page.
* For Windows, Internet Explorer v5 or later there's a neat menu system at the top of each page.
* For the rest there's an appropriate set of conventional hyperlinks.
* Links required are determined entirely from folder depth, and current path.
*/
function writeLinks()
{
	// If Windows and IE v5 or later
	if ( OS      == "Windows" &&
		 browser == "Internet Explorer" &&
		 version >= 5
	   )
	{
		/*
		* DHTML Menu version 3.3.19
		* written by Andy Woolley
		* Copyright 2002 Andy Woolley. All Rights Reserved.
		*
		* Please feel free to use this code on your own website free of charge.
		* You can also distribute and modify this source code as long as this
		* Copyright notice remains intact and that you send me notice that you
		* intend to use this code on your website.
		*
		* Limited support for this script is provided
		* Commercial licence agreements are available on request for use & full support.
		* You can send email to menu3@milonic.com
		*
		* Script featured on Dynamic Drive (http://www.dynamicdrive.com)
		*/
		// First call to method from page being displayed.
		if ( doneMenu != 'Y' )
		{
			document.write( "<br />" );
			//var path = getPathData().backPath + "scripts/";
			//document.write( "<SCRIPT language=JavaScript src=\"" + path + "menu_array.js\" type=text/javascript></SCRIPT>" );
			//document.write( "<SCRIPT language=JavaScript src=\"" + path + "mmenu.js\" type=text/javascript></SCRIPT>" );
			document.write("<SCRIPT language=JavaScript src=\"/scripts/menu_array.js\" type=text/javascript></SCRIPT>");
			document.write("<SCRIPT language=JavaScript src=\"/scripts/mmenu.js\" type=text/javascript></SCRIPT>");
			doneMenu = 'Y';
		}
		// Subsequent call to method from page being displayed.
		else
		{
			// Just one link to the top of the page where the menu is.
			document.write( "<p align=\"left\">" );
			document.write( "<a class=\"backnav\" href=\"#top\"" );
			document.write( " onmouseover=\"return mOver('Top of page');\"" );
			document.write( " onmouseout=\"mOut()\">" );
			document.write( "Top of page</a>" );
			document.write( "</p>" );
		}
	}
	else
	{
		// For everything else stick with the old links top and bottem of pages.

		var pathData = getPathData();

		// No links on home page.
		if ( pathData.folders == 0 &&
			 pathData.fileName == "home.htm"
		   )
		{
			return;
		}

		// Ensure everything left justified.
		document.write( "<p align=\"left\">" );

		// Home page link required for all but Home page (which we can't be on - see above).
		document.write( "<a class=\"backnav\" href=\"" + pathData.backPath + "home.htm\"" );
		document.write( " onmouseover=\"return mOver('Home Page');\"" );
		document.write( " onmouseout=\"mOut()\">" );
		document.write( "Home page</a>" );
		document.write( "&nbsp;" );

		// The Previous page link - same as above.
		document.write( "<a class=\"backnav\" href=\"javascript:goback()\"" );
		document.write( " onmouseover=\"return mOver('Go Back to previous page');\"" );
		document.write( " onmouseout=\"mOut()\">" );
		document.write( "Previous page</a>" );
		document.write( "&nbsp;" );

		// If we're at or below two logical levels down we'll want another link, that
		// depends on just where we are, pointing back to some sort of summary page.
		// Each section of the website is structured slightly differently as well!

		// Authors. Summary file in same folder as rest of files.
		if ( pathData.folders > 0 &&
			 pathData.folderNames[0] == "authors" &&
			 pathData.fileName != "index.htm"
		   )
		{
		document.write( "<a class=\"backnav\" href=\"index.htm\"" );
		document.write( " onmouseover=\"return mOver('Authors List');\"" );
		document.write( " onmouseout=\"mOut()\">" );
		document.write( "Authors List</a>" );
		document.write( "&nbsp;" );
		}
		else
		// Biographies.
		if ( pathData.folders > 0 &&
			 pathData.folderNames[0] == "biogs" &&
			 pathData.fileName != "index.htm"
		   )
		{
		document.write( "<a class=\"backnav\" href=\"index.htm\"" );
		document.write( " onmouseover=\"return mOver('Biographies List');\"" );
		document.write( " onmouseout=\"mOut()\">" );
		document.write( "Biographies List</a>" );
		document.write( "&nbsp;" );
		}
		else
		// Previous productions.
		if ( pathData.folders > 1 &&
			 pathData.folderNames[0] == "previous"
		   )
		{
		document.write( "<a class=\"backnav\" href=\"" + pathData.backPath.substring( 3 ) + "index.htm\"" );
		document.write( " onmouseover=\"return mOver('Previous productions summary');\"" );
		document.write( " onmouseout=\"mOut()\">" );
		document.write( "Previous productions summary</a>" );
		document.write( "&nbsp;" );
		}
		else
		// Social.
		if ( pathData.folders > 1 &&
			 pathData.folderNames[0] == "social"
		   )
		{
		document.write( "<a class=\"backnav\" href=\"" + pathData.backPath.substring( 3 ) + "index.htm#next\"" );
		document.write( " onmouseover=\"return mOver('Social');\"" );
		document.write( " onmouseout=\"mOut()\">" );
		document.write( "Social page</a>" );
		document.write( "&nbsp;" );
		}

		// Search. Goes everywhere except Home and Search pages.
		if ( pathData.folders > 0 ||
			 pathData.fileName != "search.htm"
		   )
		{
			document.write( "<a class=\"backnav\" href=\"" + pathData.backPath + "search.htm\"" );
			document.write( " onmouseover=\"return mOver('Search our Site');\"" );
			document.write( " onmouseout=\"mOut()\">" );
			document.write( "Search</a>" );
		}

		// Always include the sitemap page.
		document.write( "&nbsp;" );
		document.write( "<a class=\"backnav\" href=\"" + pathData.backPath + "sitemap.htm\"" );
		document.write( " onmouseover=\"return mOver('Sitemap');\"" );
		document.write( " onmouseout=\"mOut()\">" );
		document.write( "Sitemap</a>" );

		// Conclude the paragraph.
		document.write( "</p>" );
	}
}
/*
* Write out html to display the ODS logo complete in mousein/out reversing.
*/
function writeLogo( )
{
	document.write( "<center><img src=\"/odslogo.gif\" name=\"logo\" alt=\"ODS logo\"" );
	document.write( "    onmouseover=\"imageOver()\"" );
	document.write( "    onmouseout=\"imageOut()\"" );
	document.write( "</center>" );
}
/*
* Derive all the data we need to do various things from the pathname. These are:-
* 1) The number of folders in the hierarchy.
* 2) The path to get us back to the root directory.
* 3) The file name.
* 4) All the folders in the path.
*/
function getPathData()
{
	var pathData = new Object();

	// First count up the number of folder delimiters (slashes) we've got.
	var path = location.pathname;
	var pos  = 0;
	if ( location.protocol == "file:" )	// I.e. on my own computer.
	{
		pos = path.indexOf( "ODS" );
		path = path.substring( pos+3 );	// Lose path prior to logical root.
	}
	var dlim = path.substring( 0, 1 );	// Slash/delimiter can be either way
										// but is consistent through path.
	path = path.substring( 1 );			// Remove leading slash.
	var cnt  = 0;
	var strt = 0;
	pos  = path.indexOf( dlim, strt );
	while ( pos != -1 )
	{
		cnt++;
		strt = pos + 1;
		pos  = path.indexOf( dlim, strt );
	}
	pathData.folders = cnt;

	// Set path back to root directory base on depth we're at.
	var bckPath = "";
	while ( cnt > 0 )
	{
		bckPath = bckPath + "../";
		cnt--;
	}
	pathData.backPath = bckPath;

	// Extract file name.
	if ( pathData.folders == 0 )
	{
		pathData.fileName = path;
	}
	else
	{
		pos = path.lastIndexOf( dlim );
		pathData.fileName = path.substring( pos+1 );
	}

	// Extract folder names (if any).
	pathData.folderNames = new Array();
	cnt  = 0;
	strt = 0;
	while ( cnt < pathData.folders )
	{
		pos = path.indexOf( dlim, strt );
		pathData.folderNames[ cnt ] = path.substring( strt, pos );
		strt = pos + 1;
		cnt++;
	}

	return pathData;
}
/*
* Diagnostic facility to show what's in the pathData object.
*/
function writePathData( pathData )
{
	document.write( "pathname: " + location.pathname + "<br>" );
	document.write( "folders : " + pathData.folders  + "<br>" );
	document.write( "backPath: " + pathData.backPath + "<br>" );
	document.write( "fileName: " + pathData.fileName + "<br>" );
	for ( var j=0; j<pathData.folders; j++ )
	{
		document.write( "folder (" + j + "): " + pathData.folderNames[j] + "<br>" );
	}
}
