<!--
/******************************************************/
/*                    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 allDivs=new Array(),revealedDivs=new Array(),nReveal,nSubs;
var pageStart,pageTitle,pageLink,pageChapter;


function dopageStart() {var id=Number(pageStart.substr(4,2)),im=Number(pageStart.substr(2,2))-1,iy=Number(pageStart.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 doJump(inNum) {
	if(!revealedDivs[Number(inNum)]) return;
	var ref=revealedDivs[Number(inNum)];
	window.location="#s-"+allDivs[ref].id;
}

function doTop() {window.location="#top";}

function getPageInformation(r) {
	var ref=Number(r);
	pageChapter=ref;
	pageStart=pageInfo[ref][start];
	pageTitle=pageInfo[ref][title];
	pageLink=pageInfo[ref][link];
}

var splt="/";
function init() {
	getPageInformation(management_reference);
	nReveal=getNumberOfReveals();
	nSubs=getNumberOfSubChapters();
	if(nReveal>nSubs) nReveal=nSubs;
	setCookie(("c"+pageChapter),(nReveal + splt + nSubs)); // NOTE: no expiration time!
	nReveal=(getCookie(tM)!="")?nSubs:nReveal;
	if(nReveal==0 || nSubs==0) return;
	doRevealDivs();
	doNavigation();
}

function getNumberOfSubChapters() {
	var n=0;allDivs=document.getElementsByTagName("DIV");
	for (x=0;x<allDivs.length;x++) {if(allDivs[x].className=="subChapter") n++;}
	return(n);
}
function getNumberOfReveals() {return(Math.max(0,Math.floor(numElapsedDays()/revealInterval)));}

function doRevealDivs() {
	var cReveal=0;allDivs=document.getElementsByTagName("DIV");
	for (x=0;x<allDivs.length;x++) {
		if(allDivs[x].className=="subChapter" && nReveal>cReveal) {
			allDivs[x].style.display="block";revealedDivs[cReveal]=x;
			var anchorText='<a name="s-'+allDivs[x].id+'"></a>';
			var c=cReveal+1;
			var dividerText=(c>1)?'<a name="d-'+c+'"></a><div title="bookmark '+c+'" class="divider" onclick="javascript:writeBookmark(\''+c+'\');">'+c+'</div>':'';
			allDivs[x].innerHTML=anchorText+dividerText+allDivs[x].innerHTML;
//			alert(cReveal+","+revealedDivs[cReveal]+','+allDivs[x].id);
			cReveal++;
		}
	}
}


function doTime() {
	getPageInformation(management_reference);
	var tim=Number(numElapsedDays()%revealInterval);	// 0 today, 1 tomorrow, 2 yesterday
	nReveal=getNumberOfReveals();if(nReveal<=0) return;
	nSubs=getNumberOfSubChapters();
	if(nReveal>=nSubs) {
		tim=0;var dTit="all sections complete";
	} else {
		dTit=(tim==0)?"new section added today":(tim==1)?"new section added yesterday":(nSubs-nReveal==1)?"last section will be added tomorrow":"next section will be added tomorrow";
	}
	getObject("gTime").innerHTML='<img src="gifs/'+tim+'.gif" alt="time" class="navImg" title="'+dTit+'">';
}

function doNavigation() {
	var nLinkText="";
	for (x=0;x<nSubs;x++) {
		var src=(x==nReveal-1)?"orangebox.gif":(x<nReveal)?"slatebox.gif":"greybox.gif";
		nLinkText+='<img onClick="javascript:doJump(\''+x+'\');" ';
		nLinkText+='src="gifs/'+src+'" class="nImg" ';
		nLinkText+='title="go to section '+(x+1)+'">';
}
	getObject("navBar").innerHTML='<p>'+nLinkText+'&nbsp;['+nReveal+'/'+nSubs+']</p>';		// write out navigation
}

var link_identifier="autoLink",foundIndex=0,linkCount=0,linkIDs=new Array();
/* This routine collects all text from the table of contents DIV ("toc") and searches through it for text that marches that of automatic links. The id of the element is this link text plus one or two digits (xx), a number that indexes the pageInfo array. If the page has started being revealed, a link is created around the autolink object */

function doLinks() {
	var mText=getObject("toc").innerHTML;
	while (mText.indexOf(link_identifier,foundIndex)!=-1) {
		foundIndex=mText.indexOf(link_identifier,foundIndex);
		endIndex=foundIndex+link_identifier.length+2;
		linkIDs[linkCount]=mText.substr(foundIndex,endIndex-foundIndex);linkCount++;
		foundIndex=endIndex;
	}
	for (x=0;x<linkIDs.length;x++) {				// cycle through found links
		var refID=Number(linkIDs[x].slice(link_identifier.length));
		if (refID<pageInfo.length) {
			pageStart=pageInfo[refID][start];
			if(getNumberOfReveals()>0 || getCookie(tM)) {
				linkURL='<a href="'+pageInfo[refID][link]+'">';
				var proc=getCookie(("c"+x));prop=proc.split(splt);
				var prog=(proc!="")?'<span class="progress">['+Math.floor(prop[0]/prop[1]*100)+'%]</span>':"";
				getObject(linkIDs[x]).innerHTML=linkURL+getObject(linkIDs[x]).innerHTML+'</a>'+prog;
			}
		}
	}
}

function doBookMark() {
	var bmName=getCookie("bookmark");
	if(bmName!="") getObject("bMark").innerHTML='<a href="'+bmName+'"><img alt="bm" title="jump to bookmark" src="gifs/attach.png" class="navImg"></a>';	
}

function writeBookmark(divNum) {
	var lname=location.pathname.substr(location.pathname.lastIndexOf("/")+1)+"#d-"+divNum;
	setCookie("bookmark",lname,30);
	getObject("bMark").innerHTML='<a href="#d-'+divNum+'"><img alt="bm" title="jump to bookmark '+divNum+'" src="gifs/attach.png" class="navImg"></a>';
}

function doBookmark() {
	if(getCookie("bookmark")=="") return;
	var lname=getCookie("bookmark"),divNum=Number(lname.substr(lname.indexOf("#")+3));
	thisPage=location.pathname.substr(location.pathname.lastIndexOf("/")+1);
	getObject("bMark").innerHTML=(lname.indexOf(thisPage)!=-1)?'<a href="#d-'+divNum+'"><img alt="bm" title="jump to bookmark '+divNum+'" src="gifs/attach.png" class="navImg"></a>':"";
}

function doPDF() {
	getPageInformation(management_reference);
	nReveal=getNumberOfReveals();
	nSubs=getNumberOfSubChapters();
	if(nReveal>=nSubs) {
		getObject("pDF").innerHTML = '<a href="pdf/SoWhereAreYouNow-'+pageChapter+'.pdf"><img src="gifs/pdf.gif" alt="pdf" title="get pdf of this page" class="navImg"></a>';
	} 
}

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>The time icon indicates when the latest section came or will come on line: <img class="hIcon" src="gifs/0.gif" alt="time" title="today"> today, <img class="hIcon" src="gifs/1.gif" alt="time" title="tomorrow"> yesterday or <img class="hIcon" src="gifs/2.gif" alt="time" title="tomorrow"> tomorrow</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>Click the <img class="hIcon" src="gifs/pdf.gif" alt="top" title="pdf icon"> at the top of any chapter that is completely on line to download a PDF version of the chapter.  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() { };


-->
