<!--
/******************************************************/
/*                    Common Routines                 */
/******************************************************/

var d=document;
function getObject(name) {return (d.getElementById?d.getElementById(name):d.all?document.all[name]:d.layers?eval("document.layers[\"" + name + "\"]"):null);
}
var objDiv = null;
function doShow(objid) {if (objDiv) objDiv.style.display="none";objDiv=getObject(objid);objDiv.style.display = "block";}

function doToggle(divID) {
	getObject(divID).style.display=(getObject(divID).style.display=="none")?"block":"none";
}


/******************************************************/
/*                 Page Management Routines           */
/******************************************************/
// common variables
var div=(1000*60*60*24);		// milliseconds in one day
var nReveal,nSubs;
var essayNumber,essayStar,essayTitle,essayLink,essaysOnline=new Array();



function doTop() {window.location="#top";}

function getPageInformation(r) {
	var ref=Number(r);
	essayNumber=ref+1;
	essayStart=essayInfo[ref][start];
	essayTitle=essayInfo[ref][title];
	essayLink=essayInfo[ref][link];
}


function init() {
	var path=location.pathname;	
	getNumberOfRevealedEssays(path);
	for (x=essaysOnline.length-1;x>=0;x--) {		// most recent first
		getPageInformation(essaysOnline[x]);
		if (path.indexOf(essayLink.slice(0,essayLink.indexOf(".")))!=-1) {
			var essay=getObject("e"+essayNumber);
			essay.innerHTML='<a name="link'+Number(essayNumber)+'"></a>'+essay.innerHTML;
			essay.style.display="block";
			var eL=getObject("eNav");var eC=(x==essaysOnline.length-1)?"here":"there";
			eL.innerHTML+='<p class="'+eC+'" onclick="window.location=\'#link'+essayNumber+'\';">'+essayTitle+'</p>';
		}
	}
}

function doEssayLinks() {
	var eL="";
	getNumberOfRevealedEssays("all");
	for (x=0;x<essaysOnline.length;x++) {
		getPageInformation(essaysOnline[x]);
		eL+='<li><a href="'+essayLink+'">'+essayTitle+'</a></li>';
	}
	getObject("essayLinks").innerHTML='<ul class="essayList">'+eL+'</ul>';
}

function getNumberOfRevealedEssays(path) {
	var i=0,test=(getCookie(tM)!="")?true:false;		// test mode?
	for (x=0;x<essayInfo.length;x++) {
		getPageInformation(x);
		var fit=(path=="all" || path.indexOf(essayLink.slice(0,essayLink.indexOf(".")))!=-1)?true:false;
		if(test || (Number(getNumberOfReveals())>0 && fit)) {
			essaysOnline[i]=x;
			i++;
		}
	}
}

function getNumberOfReveals() {return(Math.max(0,Math.floor(numElapsedDays()/erevealInterval)));}
function dopageStart() {var id=Number(essayStart.substr(4,2)),im=Number(essayStart.substr(2,2))-1,iy=Number(essayStart.substr(0,2))+2000;return (Date.UTC(iy,im,id)/div);}
function doTodayDate() {var r=new Date(),y=r.getFullYear(),m=r.getMonth(),d=r.getDate();return (Date.UTC(y,m,d)/div);}
function numElapsedDays() {return (doTodayDate()-dopageStart());}





function doToggleTest() {if(getCookie(tM)==""){setCookie(tM,true);}else{setCookie(tM,"");}}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

var helpText="";
helpText+='<img src="gifs/fileclose.png" title="close help" alt="close" class="navImg" onclick="javascript:doToggle(\'help\');" style="float:right;">';
helpText+='<h1>Reading the memoir</h1>';
helpText+='<ul class="arrow">';
helpText+='<li>A new section of the memoir comes on line every three days</li>';
helpText+='<li>The blocks at the beginning of each chapter (e.g.: <img  class="hIcon" src="gifs/navigation.jpg" alt="example" title="in-page navigation">) correspond to the sections of the chapter. The filled blocks represent the sections that are on line; the first block corresponds to section 1, the second to section 2, and so on. Click on a block to jump to that section of the chapter. The orange block takes you to the most recent entry</li>';
helpText+='<li>To see which sections are currently on line, click the <img class="hIcon" src="gifs/info.png" alt="online" title="what\'s on line"> information icon in the Table of Contents</li>';
helpText+='<li>Once all sections of each chapter are on line, a PDF icon <img class="hIcon" src="gifs/pdf.gif" alt="top" title="pdf icon"> will be shown at the top of the page. Click the icon to download a PDF file of the entire chapter</li>';
helpText+='<li>Wherever you are, click the red triangle <img src="gifs/upred.gif" alt="top" title="go to top icon"> to jump to the beginning of the chapter</li>';
helpText+='<li>Place your cursor on the navigation icon <img  class="hIcon" src="gifs/contents.png" alt="top" title="navigation icon"> to move from page to page. The menu shows which chapters are on line</li>';
helpText+='<li>Click the numbered box at the start of each section <img class="hIcon" src="gifs/bookmark.jpg" alt="top" title="bookmark icon"> to create a bookmark. Click the paper clip <img  class="hIcon" src="gifs/attach.png" alt="top" title="go to bookmark icon"> to return to this bookmark</li>';
helpText+='<li>Words and terms in the glossary are highlighted the first time they appear in each chapter</li>';
helpText+='<li>To see this information at any time, click the help icon <img class="hIcon" src="gifs/help.png" alt="help" title="help icon">';
helpText+='</ul>';

function doHelp() {getObject("help").innerHTML=helpText;doToggle("help");}


var whatsText='<img src="gifs/fileclose.png" title="close help" alt="close" class="navImg" onclick="javascript:doToggle(\'help\');" style="float:right;"><h1>What\'s on line?</h1><p>The following chapter sections are currently on line:</p>';
var keyText='<p><strong>Key: </strong><img class="hIcon" src="gifs/slatebox.gif" alt="box"> completed section, <img class="hIcon" src="gifs/orangebox.gif" alt="box"> most recent section, <img class="hIcon" src="gifs/greybox.gif" alt="box"> section to come</p>';

function whatsOnline() {
	var nLinkText=whatsText+'<table class="onTable">';
	for (y=0;y<pageInfo.length;y++) {
		var proc=getCookie(("c"+y));getPageInformation(y);nReveal=getNumberOfReveals();
		if(proc!="" && nReveal>0) {
			var num=Number(proc.split(splt)[0]),tot=Number(proc.split(splt)[1]);
			if(num>0) {
				nLinkText+='<tr><td><strong>'+pageInfo[y][title]+'</strong>&nbsp;</td><td>';
				for (x=0;x<tot;x++) {
					var src=(x==num-1)?"orangebox.gif":(x<num)?"slatebox.gif":"greybox.gif";
					nLinkText+='<img src="gifs/'+src+'" class="nImg">';
				}
				nLinkText+='</td></tr>';
			}
		}
	}
	nLinkText+='</table>'+keyText;
	getObject("help").innerHTML=nLinkText;doToggle("help");
}




/* Sliding Navigation Menus */

var hp=26;
function doMenus() {
//     ypMenu(   id      dir    right  top   width   items)  //
 	new ypMenu("menu1", "down",   1,   92,    300,    17);	
 	new ypMenu("menu2", "down",   1,   92,    300,    18);	
}

// Menu for memoir chapter pages
function doMenu1() {
	var msg='<div id="menu1Container"><div id="menu1Content">';
	// FIXED MENU ITEMS
    msg +='<a class="rollmenu" onmouseover="ypMenu.showMenu(\'menu1\')" onmouseout="ypMenu.hideMenu(\'menu1\')" href="toc.html"><strong>Table Of Contents</strong></a>';
	// DYNAMIC MENU ITEMS
	for (x=0;x<pageInfo.length;x++) {
		getPageInformation(x);			// get relevant info. of page
		if(getNumberOfReveals()>0) {
			msg += '<a class="rollmenu" onmouseover="ypMenu.showMenu(\'menu1\')" onmouseout="ypMenu.hideMenu(\'menu1\')" href="'+pageLink+'">&raquo;&nbsp;'+pageTitle+'</a>';
		}
	}
	msg += '</div></div>';
	d.write (msg);
}

// Menu for table of contents page
function doMenu2() {
	var msg='<div id="menu2Container"><div id="menu2Content">';
	// FIXED MENU ITEMS
    msg += '<a class="rollmenu" onmouseover="ypMenu.showMenu(\'menu2\')" onmouseout="ypMenu.hideMenu(\'menu2\')" href="../index.html"<strong>HOME</strong></a>';
    <!-- msg +='<a class="rollmenu" onmouseover="ypMenu.showMenu(\'menu2\')" onmouseout="ypMenu.hideMenu(\'menu2\')" href="toc.html"><strong>Table Of Contents</strong></a>'; -->
	// DYNAMIC MENU ITEMS
	for (x=0;x<pageInfo.length;x++) {
		getPageInformation(x);			
		if(getNumberOfReveals()>0) {
			msg += '<a class="rollmenu" onmouseover="ypMenu.showMenu(\'menu2\')" onmouseout="ypMenu.hideMenu(\'menu2\')" href="'+pageLink+'">&raquo;&nbsp;'+pageTitle+'</a>';
		}
	}
	msg += '</div></div>';
	d.write (msg);
}

////////////////////////////// Slide Out Menus //////////////////////////////////

ypMenu.Registry = [];
ypMenu.aniLen = 650;
ypMenu.hideDelay = 500;
ypMenu.minCPUResolution = 10;

// constructor
function ypMenu(id, dir, right, top, width, h) {
	this.ie  = document.all ? 1 : 0;
	this.ns4 = document.layers ? 1 : 0;
	this.dom = document.getElementById ? 1 : 0;

	var height=parseInt(h,10)*hp;
	if (this.ie || this.ns4 || this.dom) {
		this.id			 = id;
		this.dir		 = dir;
		this.orientation = dir == "left" || dir == "right" ? "h" : "v";
		this.dirType	 = dir == "right" || dir == "down" ? "-" : "+";
		this.dim		 = this.orientation == "h" ? width : height;
		this.hideTimer	 = false;
		this.aniTimer	 = false;
		this.open		 = false;
		this.over		 = false;
		this.startTime	 = 0;

		// global reference to this object
		this.gRef = "ypMenu_"+id;
		eval(this.gRef+"=this");

		// add this menu object to an internal list of all menus
		ypMenu.Registry[id] = this;

		var d = document;
		d.write('<style type="text/css">');
		d.write('#' + this.id + 'Container { visibility:hidden; ');
		d.write('right:' + right + 'px; ');
		d.write('top:' + top + 'px; ');
		d.write('overflow:hidden; }');
		d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute;z-index:1000; ');
		d.write('width:' + width + 'px; ');
		d.write('height:' + height + 'px; ');
		d.write('clip:rect(0 ' + width + ' ' + height + ' 0); ');
		d.write('}');
		d.write('</style>');

		this.load();
	}
}

ypMenu.prototype.load = function() {
	var d = document;
	var lyrId1 = this.id + "Container";
	var lyrId2 = this.id + "Content";
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1];
	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2);
	var temp;

	if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100);
	else {
		this.container	= obj1;
		this.menu		= obj2;
		this.style		= this.ns4 ? this.menu : this.menu.style;
		this.homePos	= eval("0" + this.dirType + this.dim);
		this.outPos		= 0;
		this.accelConst	= (this.outPos - this.homePos) / ypMenu.aniLen / ypMenu.aniLen;

		// set event handlers.
		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
//		this.menu.onmouseover = new Function("ypMenu.showMenu('" + this.id + "')")
//		this.menu.onmouseout = new Function("ypMenu.hideMenu('" + this.id + "')")

		//set initial state
		this.endSlide();
	}
};

ypMenu.showMenu = function(id)
{
	var reg = ypMenu.Registry;
	var obj = ypMenu.Registry[id];

	if (obj.container) {
		obj.over = true;

		// if this menu is scheduled to close, cancel it.
		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer); }

		// if this menu is closed, open it.
		if (!obj.open && !obj.aniTimer) reg[id].startSlide(true);
	}
};

ypMenu.hideMenu = function(id)
{
	// schedules the menu to close after <hideDelay> ms, which
	// gives the user time to cancel the action if they accidentally moused out
	var obj = ypMenu.Registry[id];
	   if (obj.container) {
		   if (obj.hideTimer) window.clearTimeout(obj.hideTimer);
		   obj.hideTimer = window.setTimeout("ypMenu.hide('" + id + "')", ypMenu.hideDelay);
	   }
};

ypMenu.hide = function(id)
{
	var obj = ypMenu.Registry[id];
	obj.over = false;

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer);

	// flag that this scheduled event has occured.
	obj.hideTimer = 0;

	// if this menu is open, close it.
	if (obj.open && !obj.aniTimer) obj.startSlide(false);
};

ypMenu.prototype.startSlide = function(open) {
	this[open ? "onactivate" : "ondeactivate"]();
	this.open = open;
	if (open) this.setVisibility(true);
	this.startTime = (new Date()).getTime();
	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypMenu.minCPUResolution);
};

ypMenu.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime;
	if (elapsed > ypMenu.aniLen) this.endSlide();
	else {
		var d = Math.round(Math.pow(ypMenu.aniLen-elapsed, 2) * this.accelConst);
		if (this.open && this.dirType == "-")		d = -d;
		else if (this.open && this.dirType == "+")	d = -d;
		else if (!this.open && this.dirType == "-")	d = -this.dim + d;
		else										d = this.dim + d;

		this.moveTo(d);
	}
};

ypMenu.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer);
	this.moveTo(this.open ? this.outPos : this.homePos);
	if (!this.open) this.setVisibility(false);
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over);
	}
};

ypMenu.prototype.setVisibility = function(bShow) {
	var s = this.ns4 ? this.container : this.container.style;
	s.visibility = bShow ? "visible" : "hidden";
};
ypMenu.prototype.moveTo = function(p) {
	this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : (p) + "px";
};
ypMenu.prototype.getPos = function(c) {
	return parseInt(this.style[c],10);
};

// events
ypMenu.prototype.onactivate		= function() { };
ypMenu.prototype.ondeactivate	= function() { };


-->
