// JavaScript Document

var WHITMAN_HOME = "http://whitmanarchive.org/";
/*
var secTitles = new Object;
secTitles['published'] = {title:"Published Works"};
secTitles['published']['LG'] = {title:"U. S. editions of Leaves of Grass"};
secTitles['published']['LG']['1855'] = {title: "<em>Leaves of Grass</em> (1855)"};
secTitles['published']['foreign'] = {title:"Leaves of Grass Editions printed outside the U. S."};
secTitles['published']['foreign']['british'] = {title:"British Editions"}; 
*/

var secTitles = { title: "Home", published: {title: "Published Works", LG: {title: "U.S. editions of Leaves of Grass", n1855: {title: "1855 Edition"} , n1856: {title: "1856 Edition"} , n1860: {title: "1860 Edition"} , n1867: {title: "1867 Edition"} , n1871: {title: "1871-72 Edition"} , n1881: {title: "1881-82 Edition"} , n1891: {title: "1891-92 Edition"} } , foreign: {title: "Editions printed outside the U.S.", british: {title: "British Editions"} , spanish: {title: "Spanish Editions"} } , periodical: {title: "Poems in Periodicals", misattributed_poems: {title: "Misattributed Poems"} , poems: {title: "Index of Poems"} , periodical_titles: {title: "Index of Periodicals"} } } , manuscripts: {title: "Manuscripts", transcriptions: {title: "Poetry Manuscripts"} , finding_aids: {title: "Finding Aids for Manuscripts"} } , biography: {title: "Biography &amp; Correspondence", walt_whitman: {title: "Walt Whitman by Ed Folsom and Kenneth M. Price"} , correspondence: {title: "Correspondence"} } , criticism: {title: "Criticism", reviews: {title: "Contemporary Reviews"} , current: {title: "Selected Criticism", encyclopedia: {title: "The Walt Whitman Encyclopedia"} } , bibliography: {title: "Bibliography"} , disciples: {title: "Disciples", bucke: {title: "Richard Maurice Bucke"} , burroughs: {title: "John Burroughs"} , oconnor: {title: "William Douglas O'Connor"} , traubel: {title: "Horace Traubel", WWWiC: {title: "With Walt Whitman in Camden", n1: {title: "Volume 1"}, n3: {title: "Volume 3"}, n4: {title: "Volume 4"} , n5: {title: "Volume 5"} , n8: {title: "Volume 8"} , n9: {title: "Volume 9"} } } } } , multimedia: {title: "Pictures and Sound"} , resources: {title: "Resources"} , about: {title: "About the Archive", articles: {title: "Articles and Interviews"} } };  


//write crumbs on ready
//$(writeBreadCrumbs);

function writeBreadCrumbs() {
	/*if (gup("test") == 1)
	{*/
		/*****
		Dynamic Javascript Breadcrumb Navigation by Adam DuVander
		http://duvinci.com/projects/javascript/crumbs/
		
		Released under Creative Commons License:
		http://creativecommons.org/licenses/by/2.5/
		*****/
		var crumbsep = " &#187; ";
		var precrumb = "<span class=\"crumb\">";
		var postcrumb = "</span>";
		var sectionsep = "/";
		var rootpath = "/"; // Use "/" for root of domain.
		var rootname = "Home";

		var objurl = secTitles;

		// Grab the page's url and break it up into directory pieces
		var pageurl = (new String(document.location));
		var protocol = pageurl.substring(0, pageurl.indexOf("//") + 2);
		pageurl = pageurl.replace(protocol, ""); // remove protocol from pageurl
		var rooturl = pageurl.substring(0, pageurl.indexOf(rootpath) + rootpath.length); // find rooturl
		//if (rooturl.charAt(rooturl.length - 1) == "/") //remove trailing slash
		//{
		//  rooturl = rooturl.substring(0, rooturl.length - 1);
		//}
		pageurl = pageurl.replace(rooturl, ""); // remove rooturl fro pageurl
		if (pageurl.charAt(0) == '/') // remove beginning slash
		{
		  pageurl = pageurl.substring(1, pageurl.length);
		}
		
		var page_ar = pageurl.split(sectionsep);
		var currenturl = protocol + rooturl;
		var allbread = precrumb + "<a href=\"" + currenturl + "\">" + rootname + "</a>" + postcrumb; // start with root
		
		for (i=0; i < page_ar.length-1; i++)
		{
		  var displayname = "";
		  currenturl += page_ar[i] + "/";
		  
		  var obRef = ((page_ar[i].match(/^\d/)) ? ('n' + page_ar[i]) : (page_ar[i]));
		  if (objurl[obRef])
		  { 
			displayname = objurl[obRef]['title'];
			objurl = objurl[obRef];
			allbread += crumbsep + precrumb + "<a href=\"" + currenturl + "\">" + displayname + "</a>" + postcrumb;
		  }
		}
		
		//$("div#bh").prepend("<p class=\"breadCrumbs\">" + allbread + "</p>");
		//var head = document.getElementById("bh");
		//head.innerHTML = "<p class=\"breadCrumbs\">" + allbread + "</p>" + head.innerHTML;
		
		document.write("<p class=\"breadCrumbs\">" + allbread + "</p>");
		
	/*}*/
}



function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function openImage(ancElement)
{
	
	  var newwin =  window.open("","window","scrollbars=yes,resizable=yes,width=500,height=600")
	  window.name="nom"
	  var htmlpage='<head><title></title></head><body bgcolor="#000000">'
	  newwin.document.open()
	  newwin.document.write(htmlpage)
	  newwin.document.write("<center>")
	  newwin.document.write("<img src='" + WHITMAN_HOME + "published/LG/figures/" + ancElement.name + ".jpg' name='first_image'>")
	  newwin.document.write("</center>")
	  newwin.document.write("</body>")
	  newwin.document.close()
	  newwin.focus();

}

function selectSearch(formElement) {
	if (formElement.className == "searchUnseleted")
	{
		formElement.value = "";
		formElement.className = "searchSeleted";
	}
}
