/*
   Browser() function borrowed from the DynAPI Distribution
   The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
	http://www.dynapi.sorceforge.net
*/
function Browser() {
	var b=navigator.appName;
	if (b=="Netscape") this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) alert('Unidentified browser./nThis browser is not supported,');
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v==5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("mac")>-1) this.platform="mac";
	else this.platform="other";
}
is = new Browser();

function gE(id,type,objectPath) { 
	if (!is.ns4) {
		if (document.getElementById) {
			return document.getElementById(id)
		} else {
			//alert("this browser does not support getElementById()")
			return false
		}
	} else {
		if (objectPath) return eval("document." + objectPath + "." + type + "['" + id + "']")
		else return eval("document." + type + "['" + id + "']")
		
	}
}

function gsP(id,type,prop,newVal,objectPath) {
	if (!gE(id,type,objectPath)) return false 

	if (!is.ns4) {
		if (newVal) {
			eval("gE(id)" + "." + prop + "= newVal");
			return true;
		} else {
			return eval("gE(id)" + "." + prop );
		}
	} else {
		if (newVal) {
			eval("gE(id,type,objectPath)." + prop.substring(prop.indexOf(".")+1) + "= newVal");
			return true;
		} else {
			return eval("gE(id,type,objectPath)." + prop.substring(prop.indexOf(".")+1) );
		}
	}
}

function megaPreload (treeDepth,fileFormat,imageDir,namesArray,statesArray,rangeUBound) {
	for (var state in statesArray) {
		for (var name in namesArray) {
			if (rangeUBound) {
				for (var range=0; range <= rangeUBound; range++) {
					eval(namesArray[name] + range + statesArray[state] +  '= new Image()')
					eval(namesArray[name] + range + statesArray[state] + '.src = "' + treeDepth + imageDir + "/" + namesArray[name] + '_' + statesArray[state] + fileFormat + '"')
					//alert('MEGAPRELOAD: Image Object ' + namesArray[name] + range + statesArray[state] + ' \n loaded at: ' + eval(namesArray[name]+ range + statesArray[state] + ".src"))
				}
			} else {
					eval(namesArray[name] + statesArray[state] +  '= new Image()')
					eval(namesArray[name] + statesArray[state] + '.src = "' + treeDepth + imageDir + "/" + namesArray[name] + '_' + statesArray[state] + fileFormat + '"')
					//alert('MEGAPRELOAD: Image Object ' + namesArray[name] + statesArray[state] + ' \n loaded at: ' + eval(namesArray[name] + statesArray[state] + ".src"))
			}
		}
	}
}

megaPreload("",".gif","images",["leftnav_topsection"],["plus","minus"],'')

var defaultImg = ""
function Swapper(imgName, imgNum, type,layerName) {
	//alert('SWAPPER: imgName= ' + imgName + '; imgNum= ' + imgNum + '; type=' + type)
	//alert('SWAPPER: source= ' + eval(imgName+imgNum+type+".src"))
	if ((imgName + imgNum) != defaultImg) {
		var FullName = imgName + imgNum
		var imgFile = eval(imgName + imgNum + type + ".src")
		if (is.ns4 && layerName) {
			eval("document." + layerName + ".document." + FullName + ".src = imgFile")
		} else {
			document.images[FullName].src = imgFile
		}
	} else {
		//alert('Swapper: not going to swap' + imgName + imgNum + ' to it\'s ' + type + ' state because it\'s the default for this page')
	}
}

var leftNavSections = ["chapter1","chapter2","chapter3","chapter4","chapter5","chapter6","chapter7","chapter8","chapter9","chapter10","chapter11"]
var activeSection = ""

function showTable(tableId) {
	// make sure browser isn't ns4
	if (is.ns4) return false
	
	// make sure tableId refers to a valid object
	if (!gE(tableId,'','')) return false 

	// reset all sections to their collapsed state and all bullets to plus
	for(var i in leftNavSections) {
		gsP(leftNavSections[i],'','style.display','none','')
		swapArrow(leftNavSections[i],'plus')
	}
	
	// if tableId is the same as it was the last time the function was called,
	// collapse the open menu. Otherwise, open the menu.
	if (activeSection == tableId) {
		swapArrow(tableId,'plus')
		activeSection = "" // activeSection is no longer active at this point
		gsP(tableId,'','style.display','none','')
	} else {
		swapArrow(tableId,'minus')
		gsP(tableId,'','style.display','block','')
		activeSection = tableId
	}
}

function swapArrow(tableId,state) {
	tableId += "Bullet"
	if (state == 'plus') {
		gsP(tableId,'','src',leftnav_topsectionplus.src)
	} else {
		gsP(tableId,'','src',leftnav_topsectionminus.src)
	}
	tableId = ""
}

function resetTable() {
	window.event.cancelBubble = true
	if (window.event.srcElement.tagName == 'DIV') {
		showTable('none')
	}
}