var isOpera, isIE, isNav, isFox, isOther = false;
if (navigator.userAgent.indexOf("Opera")!=-1) {
 isOpera = true;
} else if (navigator.userAgent.indexOf("Firefox")!=-1) {
 isFox = true;
} else if (navigator.appName == "Microsoft Internet Explorer") {
 isIE = true;
} else if (navigator.appName == "Netscape") {
 isNav = true;
} else {
 isOther = true;
}
//agent id above only used below to id IE, rest is vestigial

var docObj = "document.getElementById('";
var styleObj = "').style";

visref = "instructions"; //identify the default element to show onload
var previousX, isclict, ftn, ftnstyle, offsetx, offsety; // declare 6 empty global variables

function swapmark(e){ // invoked by onmouseup
	if(isclict=='clict'){isclict='';} // if it is marked 'clict', clear it
	else {isclict='clict';} // if not marked, name it 'clict'
	if (isIE) {
	posX = event.clientX + document.documentElement.scrollLeft;
	posY = event.clientY + document.documentElement.scrollTop;
	} else {
 	posY = e.pageY;
	posX = e.pageX;
	}
	previousX = posX; // Records location of click, compared to first mousemove to find direction and magnitude.
	leftnow = parseInt(ftnstyle.left); // record premove left position as number
	topnow = parseInt(ftnstyle.top); // record premove top position as number
	offsetx = leftnow-posX; // find click location relative to left side (varies with screen resolution and browser)
	offsety = topnow-posY; // find click location relative to top (ditto. also a border does not affect offset)
//posX and posY are always larger than left and top, so these produce negative numbers; global so moveit can use it
	} 

function unmarkit(){isclict='';} // clear the name (invoked on onmouseout [cursor breakaway] only)

function moveit(e){ // invoked by onmousemove
	if(isclict=='clict'){ // work only if isclict
		if (isIE){
		posX = event.clientX + document.documentElement.scrollLeft; 
		posY = event.clientY + document.documentElement.scrollTop;
		} else {
	 	posY = e.pageY;
	 	posX = e.pageX + document.documentElement.scrollLeft;
		}
	ftnstyle.left=(posX+offsetx)+'px'; // puts left side offsetx left of event. keeps cursor on icon. else jumps clear
	ftnstyle.top=(posY+offsety)+'px'; // same for top. adding a negative subtracts it so left and top side stay left and above click
	}}

function adjwidth(e){ // invoked by onmousemove
	if(isclict == 'clict'){
	if (isIE)
		{
	 	posX = event.clientX + document.documentElement.scrollLeft;
		} else {
	 	posX = e.pageX; //extract location at moment mousemove event occurs
		}
	directionX = posX - previousX; // extract direction and magnitude of mousemove (1px + or - if move slowly)
	leftside = previousX + directionX + offsetx; // puts left edge offsetx to left of event; keeps cursor within icon
// note no control of top as in moveit(), since footnote does not shift vertically
	ftnstyle.left = leftside+'px'; // ftnstyle was created with current footnote id by showme() or setid()
	rightside = parseInt(ftnstyle.width); // extracts whole-number value of width as a NUMBER, not a string
	ftnstyle.width = (rightside - (directionX*2))+'px'; // *2 required to pull right toward left; else just sits in place.
	previousX = posX; // set it up for next mousemove event, if cursor moves more; else exponential
	}}

function showme(e,ftnid,size){ // this is for footnote-open links
	ftn = ftnid; // footnote id is given to global 'ftn' here; now available to other functions
	ftnstyle = eval(docObj+ftn+styleObj); // create ftnstyle statement with current ftn id, also global
	if (isIE)
	{
	posY = event.clientY + document.documentElement.scrollTop;
	} else {
	posY = e.pageY;
	}
	ftnstyle.top = (posY + 10) + 'px'; // +10 puts footnote just below anchor, increase to push down
	windowsize = document.body.clientWidth; // .body. required here or Safari doesn't work
	if(size == null){
	leftside = windowsize/5;
	ftnstyle.left=leftside + 'px'; // this is the position if no size is given
	rtside = windowsize-(leftside*2.4); // this makes footnote about 3/5 width of window, centered
	ftnstyle.width=rtside+'px'; // the width if not specified
	} else {
	if(size >= windowsize){ size = windowsize-(windowsize/7); } // disallow widths greater than available screen
	ftnstyle.width=size+'px'; //  if given in link, sets width
	if(size <= (windowsize/1.66)){ // windowsize may range from 640 to over 2000
	leftside = windowsize/3; // if custom width is small, shift it right a little (to inside chapbody)
	} else {
	leftside = windowsize/10; // if custom width is large, place further left
	}
	ftnstyle.left = leftside+'px';
	}
	ftnstyle.visibility = "visible"; // and finally displays it.
	}
/*
NOTE: not all chapters place ftnotes at end. These MUST have a size specified, less than 480 (800x600 min res assumed). Else it will show tucked under the scripture pane, and the move icons will be unavailable.
*/
function setid(ftnid){ // invoked by onmousedown on any part of footnote, before ups or moves
	ftn = ftnid; // footnote id is given to global 'ftn' here; now available to other functions
	ftnstyle = eval(docObj+ftn+styleObj); // create ftnstyle statement with current ftn id, also global
// this function captures new id if user selects second of two open footnotes, so id of first is not used
	}

function goaway() { // dismisses the footnote with its icons
	ftnstyle.visibility="hidden"; // if showme() or setid() did their job, should already know who ftnstyle is
	}

// below is old simple footnote activator, on-off only
function showit(anc) {
	var inbox = eval(docObj + anc + styleObj);
	inbox.visibility = "visible";
	}

function hideit(divId) {
	document.getElementById(divId).style.visibility = 'hidden';
	}

if(document.images)
{
homup=new Image(40,40);
homdn=new Image(40,40);
homup.src="buttons/homeup.gif";
homdn.src="buttons/homedn.gif";

navcup=new Image(40,40);
navcdn=new Image(40,40);
navcup.src="buttons/navcompassup.gif";
navcdn.src="buttons/navcompassdn.gif";

larup=new Image(40,40);
lardn=new Image(40,40);
larup.src="buttons/larbutnup.gif";
lardn.src="buttons/larbutndn.gif";

rarup=new Image(40,40);
rardn=new Image(40,40);
rarup.src="buttons/rarbutnup.gif";
rardn.src="buttons/rarbutndn.gif";

subheads=new Image(40,40);
subheadsdn=new Image(40,40);
subheads.src="buttons/subheads.gif";
subheadsdn.src="buttons/subheadsdn.gif";

paletteup=new Image(40,40);
palettedn=new Image(40,40);
paletteup.src="buttons/paletteup.gif";
palettedn.src="buttons/palettedn.gif";

testup=new Image(40,40);
testdn=new Image(40,40);
testup.src="buttons/testqup.gif";
testdn.src="buttons/testqdn.gif";
}

var chaplist = '<div id="chapterlist"><p class="nav">Chapter Selector<\/p>'
chaplist += '<dl class="caption"><dt><b>1. <a href="01FindingthePurposeofLife.html">Does Life Have Any Purpose?<\/a><\/b><\/dt><dd>Why do we exist?<\/dd>';
chaplist += '<dt><b>2. <a href="02AnEnemyYouMustFace.html">An Enemy You Must Face<\/a><\/b><\/dt><dd>Why so much evil?<\/dd>'
chaplist += '<dt><b>3. <a href="03GettingAcquaintedwithGodsWord.html">Getting Acquainted with God&rsquo;s Word<\/a><\/b><\/dt><dd>Can you trust the Bible?<\/dd>'
chaplist += '<dt><b>4. <a href="04aWhoisGod.html">Who Is God?<\/a><\/b><\/dt><dd>He has a Name<\/dd>'
chaplist += '<dt><b>5. <a href="05JesusChrist.html">Jesus Christ, the One Through Whom All Things Are<\/a><\/b><\/dt><dd>Why did God send him to Earth?<\/dd>'
chaplist += '<dt><b>6. <a href="06LetYourKingdomCome.html">Let Your Kingdom Come<\/a><\/b><\/dt><dd>Where is God&rsquo;s Kingdom?<\/dd>'
chaplist += '<dt><b>7. <a href="07TheKingdomisNear.html">The Kingdom Is Near<\/a><\/b><\/dt><dd>When is God&rsquo;s Kingdom?<\/dd>'
chaplist += '<dt><b>8. <a href="08Armageddon.html">Armageddon<\/a><\/b><\/dt><dd>The war to end all wars<\/dd>'
chaplist += '<dt><b>9. <a href="09MakingEarthaParadise.html">Making Earth a Paradise<\/a><\/b><\/dt><dd>The Earth finally at peace<\/dd>'
chaplist += '<dt><b>10. <a href="10AllThoseintheGraves.html">All Those In the Graves Shall Hear His Voice<\/a><\/b><\/dt><dd>Free at last!<\/dd>'
chaplist += '<dt><b>11. <a href="11aLoyaltytotheKingdom.html">Loyalty to the Kingdom<\/a><\/b><\/dt><dd>Do not try to please everyone<\/dd>'
chaplist += '<dt><b>12. <a href="12ChristianOrganization.html">Christian Organization<\/a><\/b><\/dt><dd>Should Christians be organized?<\/dd>'
chaplist += '<dt><b>13. <a href="13WisdomofGod.html">Wisdom of God to Guide Your Life<\/a><\/b><\/dt><dd>What works, for eternity<\/dd>'
chaplist += '<dt><b>14. <a href="14ChooseLife.html">Choose the Way of Life<\/a><\/b><\/dt><dd>Take your stand confidently<\/dd>'
chaplist += '</dl></div>';


if(qf == "04"){ //easy way to see if any section of chap 4 is loaded
var subhdlist = '<a href="04aWhoIsGod.html#GodsName">What God&rsquo;s Name Means<\/a><br \/>';
subhdlist += '<a href="04aWhoIsGod.html#Jesus">Is Jesus Jehovah?<\/a><br \/>';
subhdlist += '<a href="04aWhoIsGod.html#Where">Where Is God?<\/a><br \/>';
subhdlist += '<a href="04aWhoIsGod.html#What">What Is God?<\/a><br \/>';
subhdlist += '<a href="04aWhoIsGod.html#Spirit">The Spirit Of God And Of Man<\/a><br \/>';
subhdlist += '<b>Part 2:<\/b><br \/>';
subhdlist += '<a href="04bWhoIsGod.html#Fate">Foreknowledge and Predestination<\/a><br \/>';
subhdlist += '<a href="04bWhoIsGod.html#Personality">Jehovah&rsquo;s Personality<\/a><br \/>';
subhdlist += '<a href="04bWhoIsGod.html#FearGod">Should We Fear God?<\/a><br \/>';
subhdlist += '<a href="04bWhoIsGod.html#Worship">What Is True Worship?<\/a><br \/>';
subhdlist += '<a href="04bWhoIsGod.html#SincerityAlone">Sincerity Alone Not Enough<\/a><br \/>';
subhdlist += '<a href="04bWhoIsGod.html#Cross">Loving Correction From God&rsquo;s Word<\/a>';
} //set the Chapter 4 subhead list for toolbar below (saves having to do it twice)

if(qf == "11"){ //easy way to see if any section of chap 11 is loaded
var subhdlist = '<b>Part 1:<\/b><br \/>';
subhdlist += '<a href="11aLoyaltytotheKingdom.html#submit">Submitting to the Law of God<\/a><br \/>';
subhdlist += '<a href="11aLoyaltytotheKingdom.html#loyalty">Misplaced Loyalty<\/a><br \/>';
subhdlist += '<a href="11aLoyaltytotheKingdom.html#war">Christian Warfare<\/a><br \/>';
subhdlist += '<b>Part 2:<\/b><br \/>';
subhdlist += '<a href="11bLoyaltytotheKingdom.html">Self-Defense?<\/a><br \/>';
subhdlist += '<a href="11bLoyaltytotheKingdom.html#revenge">Justice and Revenge<\/a><br \/>';
subhdlist += '<a href="11bLoyaltytotheKingdom.html#taxes">National Service and Taxes<\/a><br \/>';
subhdlist += '<b>Part 3:</b><br />';
subhdlist += '<a href="11cLoyaltytotheKingdom.html">Nationalism and Racism<\/a><br \/>';
subhdlist += '<a href="11cLoyaltytotheKingdom.html#neutral">Are Christians Neutral?<\/a><br \/>';
subhdlist += '<a href="11cLoyaltytotheKingdom.html#democracy">Democracy and the Kingdom<\/a><br \/>';
subhdlist += '<a href="11cLoyaltytotheKingdom.html#politics">More on Political Involvement<\/a><br \/>';
subhdlist += '<a href="11cLoyaltytotheKingdom.html#activism">Social Activism<\/a><br \/>';
subhdlist += '<b>Part 4:<\/b><br \/>';
subhdlist += '<a href="11dLoyaltytotheKingdom.html">Guarding the Kingdom<\/a><br \/>';
subhdlist += '<a href="11dLoyaltytotheKingdom.html#holidays">Making God\'s Heart Rejoice<\/a><br \/>';
subhdlist += '<a href="11dLoyaltytotheKingdom.html#blood">Would You Risk Your Life for God?<\/a>';
} //set the Chapter 11 subhead list for toolbar below (saves having to do it 4 times)

var toolbar = '<table align="center"><tr>'

toolbar += '<td id="google_translate_element"><\/td>'
toolbar += '<script> function googleTranslateElementInit() {new google.translate.TranslateElement({pageLanguage: \'en\'},\'google_translate_element\');}<\/script><script src="http:\/\/translate.google.com\/translate_a\/element.js?cb=googleTranslateElementInit"><\/script>'

toolbar += '<td><img src="buttons/homeup.gif" border="0" class="butn" alt="Home" name="hom" onclick="gotochap(\'index.html\')" onmouseover="src=homdn.src; window.status=\'Introduction and Table of Contents\'; return;" onmouseout="src=homup.src; window.status=\'\'; return;" \/><\/td>'

toolbar += '<td><img src="buttons/navcompassup.gif" onclick="showit(\'chapterlist\')" onmouseover="src=navcdn.src; window.status=\'Chapter Selector\'; return;" onmouseout="src=navcup.src; window.status=\'\'; return;" border="0" class="butn" alt="Navigator" name="navc" \/><\/td>'

toolbar += '<td><img src="buttons/larbutnup.gif" onclick="gotochap(prevchap)" onmouseover="src=lardn.src; window.status=prevchapname; return;" onmouseout="src=larup.src; window.status=\'\'; return;" border="0" alt="Previous" class="butn" name="lar" \/><\/td>'

toolbar += '<td><img src="buttons/rarbutnup.gif" onclick="gotochap(nextchap)" onmouseover="src=rardn.src; window.status=nextchapname; return;" onmouseout="src=rarup.src; window.status=\'\'; return;" border="0" class="butn" alt="Next" name="rar" \/><\/td>'

toolbar += '<td><img src="buttons/subheads.gif" onclick="showit(\'subheads\')" onmouseover="src=subheadsdn.src; window.status=\'Subhead Navigator\'; return;" onmouseout="src=subheads.src; window.status=\'\'; return;" border="0" alt="Links to subheads" class="butn" name="subhds" \/><\/td>'

toolbar += '<td><img src="buttons\/testqup.gif" onclick="popit(\'quiz\')" onmouseover="src=testdn.src; window.status=\'What do you think?\'; return;" onmouseout="src=testup.src; window.status=\'\'; return;" border="0" alt="Test Your Understanding" class="butn" name="test" \/><\/td>'

toolbar += '<\/tr><\/table>'

toolbar += '<span onmouseup="hideit(\'subheads\')">'
toolbar += '<div id="subheads"><span class= "caption">'
toolbar += '<b>Chapter Subheads<\/b><br \/>'
toolbar += subhdlist
toolbar += '<\/span><\/div><\/span>'

toolbar += '<span onmouseup="hideit(\'chapterlist\')">'
toolbar += chaplist
toolbar += '<\/span>'

var ftnicos = '<img src="images\/Close.png" width="24" height="24" style="position:absolute; top:2px; right:2px;" alt="Close" onclick="goaway(ftn);" \/>'
ftnicos += '<img src="images\/MoveGo.png" style="position:absolute; top:1px; left:1px;" width="24" height="24" border="0" alt="Move-Go Icon" onmouseup="swapmark(event);" onmousemove="moveit(event);" onmouseout="unmarkit();" \/>'
ftnicos += '<img src="images\/AdjWidthGrn.png" style="position:absolute; top:1px; left:26px;" width="24" height="24" border="0" alt="Adjust Width Grn Icon" onmouseup="swapmark(event);" onmousemove="adjwidth(event)"; onmouseout="unmarkit();" \/>'

var ftnguide = '<span class="guidance" style="top:0px; left:54px; right:28px;"><span style="font-size:15px;">&larr;<\/span>Click-release-move to move or resize; click again to stop. Move slowly if your CPU is slow.<\/span>'

function gotochap(chapter) {  // this used by toolbar Next and Prev buttons above
	top.location.href = chapter; // "chapter" is declared by each chapter and selected by button choice
}

function popit(item) {
  var curref = visref; // find out whats showing
  var hideref = eval(docObj + curref + styleObj);
  hideref.visibility = "hidden"; // hide it
  var thisref = eval(docObj + item + styleObj);
  document.getElementById("verses").scrollTop = 0; // pixels from top to scroll to on each popit
  thisref.visibility = "visible"; // show clicked item
  visref = item; // assign it as visible to be hidden by next item click
}

/*
Build array of id's for use by buttons only (does not hide anything; css does that). Triggered by file onload, since the id's are not available until then. getElementsByClass() is an artificial "method" borrowed from the web. Do not remove leading space before searchClass.
*/
function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function buildarray()
{
document.getElementById(visref).style.visibility = "visible"; // first show the default element
var pids = getElementsByClass("NW", document, "p");
screfs = new Array(pids.length);
for (x = 0; x < pids.length; x++) 
  {
  screfs[x] = pids[x].getAttribute("id");
  }
}

/* For the "Prev" and "Next" buttons; identifies current visible ref and sets hidden, then increments or decrements array and sets visible. Nextscr must use one less because if not, secondstep's count+1 calls for an element beyond the end of the array. There may be a more elegant solution, but my brain hurts.
*/

function prevscr() {
  for(count=1;count<screfs.length;count++){
  if(visref != "instructions"){
    if(visref==screfs[count]) { // scan array for match to current visref
	var firststep = eval(docObj + screfs[count] + styleObj);
	firststep.visibility = "hidden"; // hide it
	var secondstep = eval(docObj + screfs[count-1] + styleObj); 
	secondstep.visibility = "visible"; // back up one in the array, and show it
	visref = screfs[count-1]; // identify showing item as visref
	  }
   }
  }
}

function nextscr() {
  var arraysize=screfs.length
  var topcount=--arraysize
  for(count=0;count<topcount;count++){
    if(visref==screfs[count]) {
	var firststep = eval(docObj + screfs[count] + styleObj);
	firststep.visibility = "hidden";
	var secondstep = eval(docObj + screfs[count+1] + styleObj);
	secondstep.visibility = "visible"; // advance one in array and show it
	visref = screfs[++count];
	}
    }
  }

// This is the <Prev  Next> bar.
var navbar = '<div align="center"><form><input type="button" class="nav2" name="back" value="&lt; Prev" onclick="prevscr()" \/>&nbsp;&nbsp;'
navbar += '<input type="button" class="nav2" name="forward" value="Next &gt;" onclick ="nextscr()" \/><\/form>'
navbar += '<p class="NW" id="instructions">Scriptures appear here when scripture links are clicked. You can also step through them with the buttons above.<\/p><\/div>'

onload = function() {
	document.getElementsByTagName("body")[0].className = "scriptOn"; // reclassify body as scriptOn (fails if noscript)
	buildarray(); // build the array of elements with class "NW" for the scripture pane stepping
	}
