document.onload = booksHider();

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// find all H2 tags that appear to the left of the "Also by..." column and change their style to clear=right
function changeH2s(newStyle) {
	var el = getElementsByClass('overflowHead',document,'h2');
	var howMany = el.length;
	for (var i = 0; i < howMany; i++) {
		el[i].style.clear = newStyle;
	}
}

// show or hide the "Also by..." column
function bookDisplay(displayValue) {
	var sideBooks = document.getElementById("sideBar");
	var booksLink = document.getElementById("alsoLink");
	if (displayValue == "hide") {
		sideBooks.className = "noDisplay";
		booksLink.className = "blockDisplay";
		changeH2s("right");
	} else {
		sideBooks.className = "blockDisplay";
		booksLink.className = "noDisplay";
		changeH2s("none");
	}
}

// change the "Also by..." header bar to a linked button that hides contents (this way only users with Javascript enabled will see the header as a link that can show/hide (since clicking the link would be ineffectual for non-JS users)
function addHideLink() {
	document.getElementById("alsoByHeader").innerHTML = "<h1><a href=\"javascript: bookDisplay('hide');\" id=\"hideBooks\">Also by Randall Robinson</a></h1>";	
}

// hide the "Also by..." column contents if no on description or buy page
function evalBooks() {
	if (pageType != "description" && pageType != "buy") {
		bookDisplay('hide');
		addHideLink();
	}
}

// wait a few milliseconds to build the column before hiding it
function booksHider() {
	var timer = setTimeout("evalBooks()", 0);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
