// if temptext doesnt exist on the page, then there are no directions at the foot of the page
//if(document.getElementById("temptext")) var temptext = document.getElementById("temptext");
if ( document.getElementById('temptext')) {
	//alert('bar is missing!');
	var temptext = document.getElementById("temptext");
} else {
	var temptext = new String();
}

// directions var is passed from calling page, or not
if(! directions) var directions = '';


// links for items
var _itemlinks = document.getElementById("itemlinks");
var links = _itemlinks.getElementsByTagName("a");


function extLink(linkID) {
	myLink = document.getElementById(linkID);

	if (myLink.href) {
		temphref = document.location.href.split('#')[0] + '#' + myLink.href.split('#')[1];
		if (! myLink.onclick) {
			document.location.href = temphref;
		} else {
			if (false != myLink.onclick()) {
				document.location.href = temphref;
			}
		}
	}

}



var showItem = function() {
	temptext.innerHTML = '';

	// loops over all links to check if any are open, if they are, close them first
	for (var x=0; x<links.length; x++) {
		if(links[x].currentlyOpen) {
			divclose(links[x].item); links[x].currentlyOpen = false;
		}

	}

	// gets the div ID to use from #
	this.item = this.href.split('#')[1];
	this.disp = document.getElementById(this.item).style.display;

	// if the display property is none or null, the div has been closed and thus can be opened, else it was open so close it


	if(this.disp=='none' || this.disp=='') {
		// open and flag as open
		divopen(this.item); this.currentlyOpen = true;

	} else {

		// close and flag as closed
		divclose(this.item); this.currentlyOpen = false;
		temptext.innerHTML = directions;

	}



}


var prepareContent = function() {


	// this stuff will not run if your browser cant hang
	if (!document.getElementById || !document.getElementsByTagName) {
		return;
	}

	// hide links
	b = document.getElementById("marquee");
	b.style.display='none';

	if(typeof(temptext) != 'string' ) temptext.innerHTML = directions;



	// links for items

	for (var i=0; i<links.length; i++) {
		links[i].onclick = showItem;
	}


	if (document.getElementById('items')) {
		// prepare items for collapsibility by first hiding them all
		var _itemcontent = document.getElementById("items");
		var divs = _itemcontent.getElementsByTagName("div");

		for (var i=0; i<divs.length; i++) {
			divs[i].style.display = 'none';
			divs[i].style.overflow = 'hidden';
		}

		// parse the ID of the open item from the location, and execute extLink
		var loc = new String(document.location);

		if(hash = loc.split('#')[1]) {
			extLink('link-' + hash.split('-')[1]);
		}
	}
	
	


}

