if (document.all) {
	var docObj = "document.all.";
	var styleObj = ".style";
	}
else {
	var docObj = "document.getElementById('";
	var styleObj = "').style";
	}

mtnbk = new Image(801, 532); //declaring images makes first swapping faster
forestbk = new Image(640, 468); //although first loadup takes longer
skybk = new Image(1024, 768);
windbk = new Image(1024, 768);
mtnbk.src = "images/springtimemountainW.jpg"; // to change images just edit these lines
forestbk.src = "images/mistyforest.jpg";
skybk.src = "images/CloudSun.jpg";
windbk.src = "images/wind.jpg";

/*
Create arrays of objects with the classes "comments" and "mlink" using the artifical method "getElementsByClass", then build arrays of their id's for use by the theme-selecting function, which just sets their colors, but could do much more. All the other elements set by theme are unique, so the id only can be used. "searchClass" means the class name you want fetched. domNode usually would be "document". tagName is the kind of element (p, a, span, div, etc) that has the class.
*/
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;
}
// run by onload, as id's are not available until then:
function buildarrays(){
var divids = getElementsByClass("comment", document, "div");
comms = new Array(divids.length);
for (x = 0; x < divids.length; x++) 
  {
  comms[x] = divids[x].getAttribute("id");
  }
var anclas = getElementsByClass("mlink", document, "a");
ancids = new Array(anclas.length);
for (x = 0; x < anclas.length; x++)
  {
  ancids[x] = anclas[x].getAttribute("id");
  }
}

var theme = "wind"; // default setting for theme
function themeswap(theme){
    var instrstyle = eval(docObj + "instr" + styleObj);
  switch(theme){
    case("mountain"):
	document.getElementById("maintitle").className = "montane";
	instrstyle.color = "white";
      if(document.all){ document.all.bkgnd.src = mtnbk.src; }
	else { document.bkgnd.src = mtnbk.src; };
	document.body.style.backgroundColor = "#8888ba"; // bgColor for mountain if no image
	break;
    case("forest"):
	document.getElementById("maintitle").className = "glen";
	instrstyle.color = "white";
       if(document.all){ document.all.bkgnd.src = forestbk.src; }
	else { document.bkgnd.src = forestbk.src; }; 
	document.body.style.backgroundColor = "#008844";
	break;
    case("sky"):
	document.getElementById("maintitle").className = "clouds";
	instrstyle.color = "black";
      if(document.all){ document.all.bkgnd.src = skybk.src; }
	else { document.bkgnd.src = skybk.src; };
	document.body.style.backgroundColor = "#4488aa";
	break;
    case("wind"):
	document.getElementById("maintitle").className = "windy";
	instrstyle.color = "black";
     if(document.all){ document.all.bkgnd.src = windbk.src; }
	else { document.bkgnd.src = windbk.src; };
	document.body.style.backgroundColor = "#006633"; // restores wind bgColor
	break;
    }
  for (x = 0; x < comms.length; x++) 
    {
    var comments = eval(docObj + comms[x] + styleObj);
    if(theme== "wind"){ comments.backgroundColor = "#f0e0a0"; }
    if(theme== "mountain"){ comments.backgroundColor = "#b6dfff"; }
    if(theme== "sky"){ comments.backgroundColor = "#b6dfff"; }
    if(theme== "forest"){ comments.backgroundColor = "#bbddbb"; }
    }
  for (x = 0; x < ancids.length; x++) {
    if(theme== "wind"){ document.getElementById(ancids[x]).className = "windy2"; }
    if(theme== "mountain"){ document.getElementById(ancids[x]).className = "montane2"; }
    if(theme== "sky"){ document.getElementById(ancids[x]).className = "clouds2"; }
    if(theme== "forest"){ document.getElementById(ancids[x]).className = "glen2"; }
    }
}

var prev = "DLINT";
function showit(dette) {
  hideit();
  var DL2 = eval(docObj + dette + styleObj);
  DL2.visibility = "visible";
  prev = dette;
}
function hideit() {
  var DLV = eval(docObj + prev + styleObj);
  DLV.visibility = "hidden";
}

function togtoc(){
  var tocbox = eval(docObj + "toc" + styleObj);
	if(tocbox.visibility=="visible")
	{tocbox.visibility = "hidden";
	hideit();}
	else
	{tocbox.visibility = "visible";}
}

