
// Request number to keep Ajax requests from being cached.
var ajaxReqNum = 1;

var doInit = true;

// initialize page based on body id and class
function initPage(page) {

	if (doInit) {
		
		var pageID = page.document.body.id;
		var pageClass = page.document.body.className;
		
		showHideAllMenus('close');
		
		// object view
		if (pageClass == "object-view") {
			setObjectPanes(pageID);
			// scroll panes if targets are present
			if (document.getElementById("target-text"))
				selectText("target-text");
			if (document.getElementById("target-notes"))
				selectNote("target-notes");
			if (document.getElementById("target-browse"))
				selectBrowse("target-browse");
		}
		
		// biography landing page
		if (pageID == "landing-biography") {
			var defaultMenu = document.getElementById('a-f');
			showHideMenu(defaultMenu, 'open');
		}
		
		setFieldFocus(page);
	
		doInit = false;
		
	}
	
}

// create element for Lightbox in document
function initLightBox(data) {
	
	// create wrapper div and insert popup html
	var lbWrapper = document.createElement('div');
	lbWrapper.innerHTML = data.responseText;
	var lbChildren = lbWrapper.childNodes;
	
	// get the class of 'popup' div
	for (i=0; i<lbChildren.length; i++) {
		if (lbChildren[i].id == 'popup') {
			lbType = lbChildren[i].className;
		}
	}
	
	if (lbType == "change-view-letter") {
		setChangeView(lbWrapper);
	}
	
	setFieldFocus(lbWrapper);
	
}

function setFieldFocus(pageObj) {
	if (document.getElementById('focus-field')) document.getElementById('focus-field').focus();
}

// get an element by classname
function getElementsByClassName(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = document.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}

// get specific class value when there are multiple
function getClassValue(element, index) {
	var classArray = element.className.split(" ");
	return classArray[index];
}

// get position of given object
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// get mouse cursor position
function getCursorPos(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return new Array(posx, posy);
}

// function to open popup window - accepts params for location, status, etc
function openPopupWindow(url, params) {
	var popup = window.open(url, 'popupwin', params);
	popup.focus();
}


/****** Begin functions for left nav ******/

// global associative array to keep track of menu states (open/close)
var menuState = new Array();

// collapse or expand all menus in left nav
function showHideAllMenus(mode) {
	
	// get all elements below the expand/collapse link
	var listArray = document.getElementsByTagName('UL');
	var listClass;
	
	// loop through to check for lists
	for (x = 0; x < listArray.length; x++) {
		listClass = listArray[x].className;
		// if the list has a class of "sub", open or close
		if (listClass == "sub") {
			showHideMenu(listArray[x], mode);
		}
	}

}

function showHideMenuById(menuID) {
	
	var menu = document.getElementById(menuID);
	
	if (menuState[menuID] == "close") {
		var mode = "open";
	} else {
		var mode = "close";
	}
	
	showHideMenu(menu, mode);

}

function showHideMenu(menu, mode) {

	// get id of menu
	var menuID = menu.id;
	
	// change the plus/minus icon and add/remove more link
	if (menuID) {
		menuState[menuID] = mode;
		showHideMoreLink(menuID, mode);
		changeCollapseIcon(menuID, mode);
		
		// if biography menu, show/hide items in content table
		if (menuID == 'a-f' || menuID == 'g-l' || menuID == 'm-r' || menuID == 's-z') {
			showHideBioItems(menuID, mode);
		}
	
	}
	
	showHideMenuItems(menu, mode);
	
}

// global array of biographies menu classes
var bioMenuArray = new Array("a-f", "g-l", "m-r", "s-z");

function showHideBios(menuID) {
		
	showHideAllMenus('close');
	showHideMenuById(menuID);
	
}

function showHideMenuItems(menu, mode) {
						   
	// get items for this list
	var items = menu.childNodes;

	// loop through all children of given list
	for (var i = 0; i < items.length; i++) {
		
		var childItem = items[i];
		
		// hide or show each item of list, if class is "hidden"
		if (childItem.nodeName == "LI") {
			if (childItem.className == "hidden") {
				if (mode == "open") {
					childItem.style.display = "block";		
				} else if (mode == "close") {	
					childItem.style.display = "none";
				}
			}
			
			// recursively loop through children to find nested lists
			var subChildren = childItem.childNodes;
			
			for (var j = 0; j < subChildren.length; j++) {
				// if sub item is a list, call show menu function
				if (subChildren[j].nodeName == "UL") {
					showHideMenu(subChildren[j], mode);
				}
				
			}
			
		}
	
	}
	
}

function changeCollapseIcon(menuID, mode) {
	
	var imgName = "img-" + menuID;
	
	if (document.images[imgName]) {
		var imgAppend = "";
		if (imgName != "img-texts-menu" && imgName != "img-resources-menu") {
			imgAppend = "_black";
		}
		if (mode == "close") {
			document.images[imgName].src = "/xtf/icons/mtp/menu_closed" + imgAppend + ".gif";
		} else {
			document.images[imgName].src = "/xtf/icons/mtp/menu_open" + imgAppend + ".gif";
		}
	}
	
}

function showHideMoreLink(menuID, mode) {
	
	var moreLinkID = menuID + "-more-link";
	var moreLink = document.getElementById(moreLinkID);
	
	// hide or show more link
	if (moreLink) {
		if (mode == "open") {
			moreLink.style.display = "none";
		} else {
			moreLink.style.display = "block";
		}
	}
	
}

// show/hide biography items in content table
function showHideBioItems(range, mode) {
	
	var contentTable = document.getElementById('content-primary');
	var childRows = contentTable.getElementsByTagName("tr");
	var childClass = 'bio-' + range;
	
	for (i=0; i<childRows.length; i++) {
		if (childRows[i].className == childClass) {
			if (mode == "open") {
				if(navigator.appName.indexOf("Microsoft") > -1) {
					childRows[i].style.display = "block";
				} else {
					childRows[i].style.display = "table-row";
				}
			} else {
				childRows[i].style.display = "none";
			}
		}
	}
	
}

/****** End functions for left nav ******/


/****** Begin functions for top nav *******/

// keep track of timeout
var timeOn = null;

// keep track off active menu
var currentMenu;

function showTopMenu(menuID) {
	
	var menu = document.getElementById(menuID);
	currentMenu = menuID;
	
	if (menu) {
		if (menu.style.display == "block") {
			menu.style.display = "none";
		} else {
			menu.style.display = "block";
		}
	}
	
}

function menuOver(menuID) {
	
	if (menuID != currentMenu) {
		hideTopMenu(currentMenu);
	}
	
	clearTimeout(timeOn);
	
}

function hideTopMenu(menuID) {
	timeOn = setTimeout("hideAllMenus('top-sub')", 300);
}

function hideMenu(menuID) {
	
	var menu = document.getElementById(menuID);
	if (menu) {
		menu.style.display = 'none';
	}
	
}

function hideAllMenus(className) {
	
	var menus = document.getElementsByTagName('ul');
	
	for (i=0; i < menus.length; i++) {
		if (className == "") {
			menus[i].style.display = "none";
		} else if (menus[i].className == className) {
			menus[i].style.display = "none";			
		}
	}
	
}

/****** End functions for top nav ******/


/****** Begin functions for object view div sizing onload and onresize ******/

var minHeight = 400; // minimum height of window
	
// returns height in pixels based on how different browsers determine window dimensions
function getWindowHeight() {

	var x,y;

	// all except Explorer
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
	// Explorer 6 Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	// other Explorers
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	return y;

}

// set height of browse pane in left column
function setBrowsePane() {

	var offset = 370; // offset from top of browser window
	
	var winHeight = getWindowHeight();
	
	if (winHeight < minHeight) {
		winHeight = minHeight;
	}
	
	var totalHeight = (winHeight - offset);
	var tocDiv = document.getElementById('toc');
	
	if (tocDiv) {
		tocDiv.style.height = totalHeight + "px";
	}

}

// set object view panes (equal height, side by side)
function setObjectPanes(pageID) {
	
	var winHeight = getWindowHeight();
	var notesOffset = 0;
	
	if (pageID == "lit-work") {
		var offset = 275; // offset from top of browser window
		notesOffset = -40;
	} else if (pageID == "letter-object") {
		var offset = 258;
		notesOffset = -19;
	} else if (pageID == "embed-letter-object") {
		var offset = 220;
		notesOffset = 5;
	} else if (pageID == "photo-object") {
		var offset = 230;
		notesOffset = 37;
	} else if (pageID == "facsimile") {
		var offset = 240;
		notesOffset = 5;
	}
	
	if (winHeight < minHeight) {
		winHeight = minHeight;
	}
	
	var totalHeight = (winHeight - offset);
	var padding = (totalHeight / 2);
	
	var textDiv = document.getElementById('content-primary');
	var notesDiv = document.getElementById('notes');
	
	if (textDiv) {
		textDiv.style.height = totalHeight + "px";
	}
	
	if (notesDiv) {
		notesDiv.style.height = (totalHeight + notesOffset) + "px";
	}
	
	setBrowsePane();
	
}

/****** End functions for text/note pane sizing onload and onresize *****/


/****** Begin functions for text/note highlight behavior on object views ******/

// padding at top of pane after scroll
var paddingTop = 10;

function hiliteNote(noteID) {
	
	var note = document.getElementById(noteID);
	
	if (note) {
		
		var noteClass = getClassValue(note, 0)
		
		if (noteClass == "altnote") {
			note.className = "altnote-hi";
		} else if (noteClass == "appnote") {
			note.className = "appnote-hi";
		}
		
	}
		
}

function unliteNote(noteID) {
		
	var note = document.getElementById(noteID);
	
	if (note) {
			
		var noteClass = note.className;
	
		if (noteClass == "altnote-hi") {
			note.className = "altnote";
		} else if (noteClass == "appnote-hi") {
			note.className = "appnote";
		}
		
		var noteDiv = document.getElementById('notes');
		var children = noteDiv.childNodes;
		
		for (var i = 0; i < children.length; i++) {
			if (children[i].style) {
				children[i].style.display = "block";
			}
		}
		
	}
		
}

function selectNote(noteID) {
	
	var note = document.getElementById(noteID);
	var noteDiv = document.getElementById('notes');
	
	if (note) {
	
		var notesTop = noteDiv.offsetTop;
		var notesCenter = (parseFloat(noteDiv.style.height) / 2);
		var fromTop = note.offsetTop;
		var scrollPos = ((fromTop - notesTop) - paddingTop);
		
		noteDiv.scrollTop = scrollPos;
		
	}
	
}

function hiliteText(textID) {
	
	var text = document.getElementById(textID);
	
	if (text) {
		text.style.backgroundColor = "#999999";
	}

}

function unliteText(textID) {
	
	var text = document.getElementById(textID);
	
	if (text) {
	
		var textClass = text.className;
		text.style.backgroundColor = "";
		text.className = textClass;
		
	}
		
}

function selectText(textID) {
	
	var text = document.getElementById(textID);
	var textDiv = document.getElementById('content-primary');
	
	if (text) {
		
		var textTop = textDiv.offsetTop;
		var textCenter = (parseFloat(textDiv.style.height) / 2);
		var fromTop = text.offsetTop;
		var scrollPos = ((fromTop - textTop) - paddingTop);
		
		textDiv.scrollTop = scrollPos;
		
	}
	
}

function selectBrowse(browseID) {
	
	var navItem = document.getElementById(browseID);
	var browseDiv = document.getElementById('toc');
	
	if (navItem) {
	
		var browseTop = browseDiv.offsetTop;
		var browseCenter = (parseFloat(browseDiv.style.height) / 2);
		var fromTop = navItem.offsetTop;
		var scrollPos = ((fromTop - browseTop) - paddingTop);
		
		browseDiv.scrollTop = scrollPos;
		
	}
	
}

/****** End functions for text/note highlight behavior on object views ******/


/****** Begin functions for search and other popups ******/

// set the action href of the form when radio buttons clicked
function setSearchForm(form) {
	
	var link = document.getElementById('more-options');
	link.href = form;
	
	// clear the Lightbox cache and re-initialize
	Event.unloadCache();
	initialize();
	
}

// select/deselect checkboxes
// checking box with class of "top" checks all with class "sub"
// checking all boxes with class of "sub" checks "top"

function toggleCheckboxes(field) {
	
	var type = getClassValue(field, 1);
	var parentDiv = field.parentNode;
	var children = parentDiv.childNodes;
	
	// if box clicked is top, check or uncheck sub fields
	if (type == "top") {
		
		var mode = field.checked;
	
		for (var i = 0; i < children.length; i++) {
			if (children[i].tagName == "INPUT") {
				children[i].checked = mode;
			}
		}
	
	// if sub field was clicked, check or uncheck the top
	} else if (type == "sub") {
		
		var mode = true;
		
		for (var i = 0; i < children.length; i++) {
			if (children[i].tagName == "INPUT" && children[i].className.indexOf("top") > -1) {
				var topIndex = i;
			}
			if (children[i].tagName == "INPUT" && children[i].className.indexOf("sub") > -1) {	
				var childMode = children[i].checked;
				if (childMode == false) {
						mode = false;
				}
			}
		}
		
		children[topIndex].checked = mode;
	
	// bad or missing classname for clicked box
	} else if (type) {
		alert("Field class '" + type + "' not recognized.");
	}
	
}

// validate search form - year and checkboxes
function validateSearchForm(form) {
	
	// validate year fields - between range and start year before end year
	var begin_range = 1813;
	var end_range = 1962;
	
	if (form.start_year && form.end_year) {
	
		var start_year = form.start_year.value;
		var end_year = form.end_year.value;
		
		if (start_year && end_year) {
		
			if (start_year < begin_range || start_year > end_range || isNaN(start_year)) {
				alert("Please enter a start year between " + begin_range + " and " + end_range + ".");
				form.start_year.focus();
				form.start_year.select();
				return false;
			}
			
			if (end_year < begin_range || end_year > end_range || isNaN(end_year)) {
				alert("Please enter an end year between " + begin_range + " and " + end_range + ".");
				form.end_year.focus();
				form.end_year.select();
				return false;
			}
			
			if (end_year < start_year) {
				alert("The start year for the date range must be earlier than the end year.");
				form.start_year.focus();
				form.start_year.select();
				return false;
			}
			
		}
		
	}
	
	// validate checkboxes - at least one must be checked
	var inputArray = document.getElementsByTagName('input');
	var numChecked = 0;
	
	for (var i = 0; i < inputArray.length; i++) {
		if (inputArray[i].className.indexOf('toggle-checkboxes') > -1 && inputArray[i].checked == true) {
			numChecked++;
		}
	}
	
	if (numChecked == 0) {
		alert('Please select the field(s) within which you wish to search.');
		return false;
	}
	
        // validate text box - must not be empty
        if(form.text.value.length == 0){
                alert('Please enter at least one search term.');
                form.text.focus(); // set the focus to this input
                return false;
        }
	
	return true;

}

// set view options radio box to reflect current view
function setChangeView(lbObj) {
	
	// check for existing elements
	var viewOptions = document.getElementById('view-options-form').childNodes;
	var isText = document.getElementById('content-text');
	var isExNotes = document.getElementById('content-explanatory-notes');
	var isTextCom = document.getElementById('content-textual-commentary');
	
	// set number of radio to check
	if (isText && isExNotes && isTextCom) {
		optionIndex = 1;
	}
	
	var radioNum = 0;
	for (var i = 0; i < viewOptions.length; i++) {
		if (viewOptions[i].nodeName == 'INPUT') {
			if (radioNum == optionIndex) {
				viewOptions[i].checked = true;
			}
			radioNum++;
		}
	}
	
}

/****** End functions for search and other popups ******/


/****** Begin functions to show/hide floating div ******/

// show div next to mouse cursor with passed id and event
function showPopupDiv(showDiv, e) {
	var pos = getCursorPos(e);
	var offsetX = -80;
	var offsetY = 20;
	showDiv.style.left = (pos[0] + offsetX) + 'px';
	showDiv.style.top = (pos[1] + offsetY) + 'px';
	if (showDiv) {
		showDiv.style.display = "block";
	}
	
}

function hidePopupDiv(hideDiv) {
	
	if (hideDiv) {
		hideDiv.style.display = "none";
	}
	
}



				
/****** Begin functions to show/hide floating div ******/


/****** Begin behaviour code ******/

var utilFunctions = {
	
		// clear search text field onfocus
		'#search-field' : function(element) {
			element.onfocus = function() {
				this.value = '';
			}
		},
		
		// change href of search form, left column
		'.set-search-form' : function(element) {
			
			// click on radio button to change search form
			element.onclick = function() {
				var searchForm = this.id + '.html';
				setSearchForm(searchForm);
			}
		
		},
		
		/*** begin left nav functions ***/
		// show / hide menu by id
		'.show-hide-menu' : function(element) {
			
			element.onclick = function() {
				var menuClass = getClassValue(this, 1);
				showHideMenuById(menuClass);
				return false;
			}
		
		},
		
		// show / hide all menus
		'.show-hide-all-menus' : function(element) {
			
			element.onclick = function() {
				showHideAllMenus(getClassValue(this, 1));
				return false;
			}
		
		},
		
		// show / hide biographies menu and content items
		'.show-hide-bios' : function(element) {
			
			element.onclick = function() {
				showHideBios(getClassValue(this, 1));
				return false;
			}
			
		},
		
		/*** end left nav functions ***/
		
		/*** begin top nav functions ***/
		'#site-nav a' : function(element) {
			
			// mouseover menu item
			element.onmouseover = function() {
				menuOver(this.className);
			}
			
			// mouseout menu item
			element.onmouseout = function() {
				hideTopMenu(this.className);
			}
			
			// click menu item
			element.onclick = function() {
				showTopMenu(this.className);
			}
			
		},
		/*** end top nav functions ***/
		
		/*** begin sort tab functions ***/
		
		'.sort-tab a' : function(element) {
			
			// on mouseover change to red arrow
			element.onmouseover = function() {
				var imgName = this.id;
				if (imgName) {
					document.images[imgName].src = 'icons/mtp/sort_arrow_red.gif';
				}
			}
			
			// on mouseout change to black arrow
			element.onmouseout = function() {
				var imgName = this.id;
				if (imgName) {
					document.images[imgName].src = 'icons/mtp/sort_arrow_down.gif';
				}
			}
			
			
		},
		
		// add to list link function
		'.add-to-list' : function(element) {
			
			element.onclick = function() {
				var parent = this.parentNode;
				var children = parent.childNodes;
				for (var i = 0; i < children.length; i++) {
					if (children[i].nodeName == "A" && (children[i].innerHTML == "Add" || children[i].innerHTML == "Add to List")) {
						parent.removeChild(parent.childNodes[i]);
					}
				}
				var newChild = document.createTextNode('Added');
				parent.appendChild(newChild);
				return false;
			}
			
		},
		
		/*** end sort tab functions ***/
		
		/*** begin object view/text pane functions ***/
		'.select-note' : function(element) {
			
			// click on text in top pane to select note in bottom
			element.onclick = function() {
				var noteID = 'note-' + this.id.split("-")[1];
				selectNote(noteID);
			}
		
		},
		
		'.select-text' : function(element) {
			
			// click on note in bottom pane to select text in top
			element.onclick = function() {
				var textID = 'text-' + this.id.split("-")[1];
				selectText(textID);
			}
			
		},
			
		'.hilite-note' : function(element) {
			
			var noteID = element.id.split("_")[1];
			
			// on mouse over, hilite note
			element.onmouseover = function() {
				if(document.getElementById(noteID)) {
					hiliteNote(noteID);
				}
			}
			
			// on mouse out, unlite note
			element.onmouseout = function() {
				if(document.getElementById(noteID)) {
					unliteNote(noteID);
				}
			}
			
			// on mouse click, select note
			element.onclick = function() {
				if(document.getElementById(noteID)) {
					selectNote(noteID);
					return false;
				}
			}
			
		},
		
		'.hilite-text' : function(element) {
			
			var textID = 'text_' + element.id;
			
			// on mouse over, hilite note
			element.onmouseover = function() {
				if(document.getElementById(textID)) {
					hiliteText(textID);
				}
			}
			
			// on mouse out, unlite note
			element.onmouseout = function() {
				if(document.getElementById(textID)) {
					unliteText(textID);
				}
			}
			
			// on mouse over, select note
			element.onclick = function() {
				if(document.getElementById(textID)) {
					selectText(textID);
// skg: return true because we want hyperlinks inside the note pane to work 
					return true;
				}
			}
			
		},
		
		'.asterix' : function(element) {
			
			var e = window.event;
			
			element.onmouseover = function(e) {
				var citation_id = element.id.split("-")[1];
				var citation_block_id = 'citblock-' + citation_id;
				var citation_block = document.getElementById(citation_block_id);
				if (citation_block) {
					showPopupDiv(citation_block, e);
				}
			}
			
			element.onmouseout = function() {
				var citation_id = element.id.split("-")[1];
				var citation_block_id = 'citblock-' + citation_id;
				var citation_block = document.getElementById(citation_block_id);
				if (citation_block) {
					hidePopupDiv(citation_block);
				}
			}

                        element.onclick = function() {
				var citation_id = element.id.split("-")[1];
				var citation_block_id = 'citblock-' + citation_id;
				var citation_block = document.getElementById(citation_block_id);
				if (citation_block && (citation_block.getAttribute('saveURL') != null)) {
				  citation_block.innerHTML = "Adding...";
				  new Ajax.Request(citation_block.getAttribute('saveURL'), {
				    method: 'post',
				    onSuccess: function(transport) {
				       citation_block.innerHTML = transport.responseText;
				    },
				    onFailure: function() {
				       citation_block.innerHTML = "Error adding citation";
				    }
				  });
				}
			}
		
		},

		'.citationDelete' : function(element) {
			
			var e = window.event;
			
			element.onclick = function() {
				var citation_id = element.id.split("-")[1];
				var text_el = $('citationDeleteText-' + citation_id);
				text_el.innerHTML = "Deleting";
				new Ajax.Request(element.getAttribute('deleteURL'), {
				    method: 'post',
				    onSuccess: function(transport) {
				      var main_el = $('citationMain-' + citation_id);
				      main_el.parentNode.removeChild(main_el);
				      var count_el = $('myFolderCount');
				      --count_el.innerHTML;
				    }
				});
			}
		
		},
		
		'.letterAdd' : function(element) {
			
			var e = window.event;
			
			element.onclick = function() {
				var citation_id = element.id.split("-")[1];
				var text_el = $('letterAddSpan-' + citation_id);
				text_el.innerHTML = "Adding";
				new Ajax.Request(element.getAttribute('addURL'), {
				  method: 'post',
				  onSuccess: function(transport) {
				     text_el.innerHTML = "Added";
				  },
				  onFailure: function() {
				     text_el.innerHTML = "Error";
				  }
				});
			}
		
		},
		
		'#emailFolderForm' : function(element) {
			
			var e = window.event;
			
			element.onsubmit = function() 
			{
			  // Validate the input address
			  var baseURL = element.getAttribute('baseURL');
			  var inputEl = $('emailAddr');
			  var text = inputEl.value;
			  if (text.length < 5 || text.length > 100 || text.indexOf("@") < 1) {
			    alert('Please enter a valid email address.');
			    inputEl.focus(); // set the focus to this input
			    return false;
			  }

			  // Calculate the URL to send the email
			  var value = Form.Element.serialize(inputEl);
			  var fullURL = baseURL + ";" + value + ";ajaxReqNum=" + (ajaxReqNum++);
			  inputEl.setAttribute('href', fullURL);
			  
			  // Update the lightbox to let the user know what's happening
			  var lbObj = new lightbox(inputEl);
			  var lbDiv = $('lightbox');
			  lbDiv.className = 'loading';
			  lbDiv.innerHTML = '<div id="lbLoadMessage">' +
					    '<p>Sending email...</p>' +
					    '</div>';
                       
			  // Send the email
			  var myAjax = new Ajax.Request(
				fullURL,
				{method: 'get', parameters: "", onComplete: lbObj.processInfo.bindAsEventListener(lbObj)}
			  );
			}
		
		},
				
		'.embedded-letter' : function(element) {
			
			element.onclick = function() {
				
				// set params for window
				var params = "location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=860,height=600,top=20,left=20";
				
				// open popup window
				openPopupWindow(this.href, params);
				
			}
			
		},
		
		'.individual-bio' : function(element) {
			
			element.onclick = function() {
				
				// set params for window
				var params = "location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=700,height=500,top=20,left=20";
				
				// open popup window
				openPopupWindow(this.href, params);
				return false;
			
			}
			
		},
		
		'.close-popup' : function(element) {
			
			element.onclick = function() {
				self.close();
			}
			
		},
		
		/*** end object view/text pane functions ***/
		
		
		/*** begin highslide image viewer functions ***/
		
		'.highslide' : function(element) {
			element.onclick = function() {
				return hs.expand(this);
			}
		},
		
		/*** end highslide image viewer functions ***/
		
		
		/*** begin functions for search and other popups ***/
		
		'.validate-search-form' : function(element) {
			
			element.onsubmit = function() {
				return validateSearchForm(this);
			}
			
		},
		
		'.toggle-checkboxes' : function(element) {
			
			element.onclick = function() {
				toggleCheckboxes(this);
			}
			
		},
		
		'.search-year-field' : function(element) {
			element.onclick = function() {
				this.value = '';
			}
		}
		
		/*** end functions for search and other popups ***/
		
};

// initialize the onload event for object views
Behaviour.addLoadEvent(function() {

	// set up page
	initPage(this);
	
	// bind resize event to page init
	Event.observe(window, 'resize', function(element) { initPage(this) }, false);
	
	// track cursor position
	//Event.observe(window, 'mousemove', function(element) { getCursorPosition(this) }, false);
	
});

// initialize behaviour and register functions
Behaviour.register(utilFunctions);

// load all behaviour functions
Behaviour.start();

