function outPutLinkSubject(name, domain, domainExt, subject) {
	var wholeThing = name + "@" + domain + "." + domainExt;
	document.write("<a href='mail" + "to:" + wholeThing + "?subject=" + subject + "'>" + wholeThing + "</a>");
}

function getObject(objectId) {
    // cross-browser function to get an object
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getObject

function findPosX(obj)
{
	var curleft = 0;
	if (!obj)
		return 0;
		
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (!obj)
		return 0;
		
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function createCookie(name,value,days)
{
        if (days)
        {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function eraseCookie(name)
{
        createCookie(name,"",-1);
}

function set_menu_vis_cookie(vis)
{
	if (vis)
		createCookie("sassafras_site_menu_visible", "yes", 0);
	else
		eraseCookie("sassafras_site_menu_visible");
}

function maybe_make_menu_visible()
{
	var menu;
	if (readCookie("sassafras_site_menu_visible")) {
		menu = getObject("navColumn");
		if (menu && menu.style) {
			menu.style.visibility = 'visible';
		}
	}
}


function demo() {
	// function body.
}
demo.toString = function() {
	return 'demo();';
}

function attachMenu(link, div)
{	
	var activator= getObject(link);
	var menuDiv = getObject(div);
	if (activator)
		activator.onmouseover = function(e){ showDiv(div)};
	if (menuDiv)
		menuDiv.onmouseout = function(e){hideDiv(e, div)};
}

function attachMenuHere(link, div)
{
	var activator= getObject(link);
	var menuDiv = getObject(div);
	var x = findPosX(activator);
	var y = findPosY(activator);
	if (activator)
		activator.onmouseover = function(e){ showDivHere(x, y, link, div)};
	/*The mouse may not enter the menu immediatly, even though the mouse has left the activator -
	so we need to always close the menu when leaving the activator, 
	unless quite soon the HideMenu is canceled because of a mouseover in the menu */
	if (activator)
		activator.onmouseout = function(e){hideDivWait(e,100, div)};
	if (menuDiv)
		menuDiv.onmouseover = function (e) {cancelHide(div)}
	if (menuDiv)
		menuDiv.onmouseout =  function(e){hideDiv(e, div)};
	if (activator && activator.style)
		activator.style.color = '#000099' ;	
}

function showDiv(div) {
	var theDiv = getObject(div);
	if (theDiv) {
		theDiv.style.visibility = 'visible';
		if (div == "navColumn")
			set_menu_vis_cookie(1);
	}
}

function showDivHere(x, y, link, div) {
	var theDiv = getObject(div);
	var theLink = getObject(link);
	var theMenuBar = theLink.parentNode;
	//Apparently when the drop-down is shown, this causes a mouse-out of the top thing (activator). However, just following the mouseout, there's a mouseover.
//To fix it, add a call to cancelHide(div) at the beginning of the showDivHere function (so not only will mouseover make it visible, it will also be sure to cancel a pending hide)...No idea why the events happen in the sequence they do in Safari 2.
	cancelHide(div);
	if (theDiv && theDiv.style) {
		theDiv.style.left = x + 'px';
		theDiv.style.top = (y + theMenuBar.offsetHeight) + 'px';
		theDiv.style.visibility = 'visible';
	}
}


function hideDiv(e, div) {
	var theDiv = getObject(div);
	if (theDiv && leaveDiv(e, div)) {
		if (theDiv.style) {
			theDiv.style.visibility = 'hidden';
			if (div == "navColumn")
				set_menu_vis_cookie(0);
		}
	}
}
	

	
function setAsLink(div, link) {
	var theDiv = getObject(div);
	
	if (theDiv && theDiv.style) {
	//	theDiv.onmouseover = function (e) {theDiv.style.background = '#fff'; theDiv.style.color = '#6699cc';};
	//	theDiv.onmouseout =  function(e){if (leaveDiv(e, div)) theDiv.style.background = 'silver'; theDiv.style.color = '#000099';};
		theDiv.onmouseover = function (e) {theDiv.style.background = '#000085'; theDiv.style.color = 'white';};
		theDiv.onmouseout =  function(e){if (leaveDiv(e, div)) theDiv.style.background = 'silver'; theDiv.style.color = '#000099';};
	}
	if (theDiv)
		theDiv.onclick =  function(e){self.location.href=link};
}

function leaveDiv(e, div){
	if (!e) var e = window.event;
	// e gives access to the event in all browsers

	var theDiv = getObject(div);
	var tg = (window.event) ? e.srcElement : e.target;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	//Climb up through nested elements to check if mouseout event is outside the div (or undefined)
	while (reltg != null && reltg != theDiv && reltg.nodeName != 'BODY' && reltg.nodeName != 'HTML') 
		reltg= reltg.parentNode;
		
	if (reltg== theDiv)
		return false; /*the "mouseout" event was really going into a contained element, so don't hide*/
	return true;
	
}

//the following works for firefox, but not for IE Mac - which expects a string arg for setTimeout
function xhideDivWait(e, time, div) {
	var theDiv = getObject(div);
	if (theDiv)
		theDiv.waitTime = window.setTimeout(function(){var theDiv = getObject(div); if (theDiv && theDiv.style) theDiv.style.visibility = 'hidden'},time);
}
	
//the following works simply for firefox, and converts to a string defined function for IE Mac	
function xxxxhideDivWait(e, time, div) {
	var theDiv = getObject(div);
	var theFunc = function(){var theDiv = getObject(div); if (theDiv && theDiv.style) theDiv.style.visibility = 'hidden'};
	theFunc.toString = function (){return "var theDiv = getObject('"+div+"'); if (theDiv && theDiv.style) theDiv.style.visibility = 'hidden'";};
	if (theDiv)
		theDiv.waitTime = window.setTimeout(theFunc, time);
}
	

	
function nhideDiv(div) {
	var theDiv = getObject(div); 
	if (theDiv && theDiv.style)
		theDiv.style.visibility = 'hidden';
}
	
//this is a 'simpler' version of the string convert for IE Mac - it relies on the global  nhideDiv function above		
function hideDivWait(e, time, div) {
	var theDiv = getObject(div);
	var theFunc = function(){nhideDiv(div);};
	theFunc.toString = function (){return "nhideDiv('"+div+"');";};
	if (theDiv)
		theDiv.waitTime = window.setTimeout(theFunc, time);
}


	
function cancelHide(div) {
	var theDiv = getObject(div);
	if (theDiv)
		window.clearTimeout(theDiv.waitTime );
}

function goTo(newURL) {
	self.location.href=newURL;
}	

function menu_maybe() {
	var fw = getObject('framework');

	if (fw)
		fw.onclick = function(e){hideDiv(e, 'navColumn')};
	attachMenu('button', 'navColumn');
	attachMenu('homeLink', 'navColumn');
	attachMenuHere('menu1', 'menu1Div');
	attachMenuHere('menu2', 'menu2Div');
	setAsLink('navButtonBar','/home.html');
	maybe_make_menu_visible();
}



window.onload= function () {
	menu_maybe();
	}

