// <script type="text/javascript">
<!--  to hide script contents from old browsers

window.onload = init;

function init()
{
	display_urhere();
	setup_email();
}

/**************************************************************************************************
This function sets up a links associated with class names to send email. Email address cannot
be read by spambots. email_array is an associative array. Each array corresponds to 1 email address.

To use in html code, as an exampke, add <span class="emailAmyChurckrow">Email Amy</span> where each
email address class starts with email****. This code is different than the email_display_link code
in that any text can be displayed between the <span> tags (e.g. "Email Amy") until the user hovers
over the text, then it will change to the actual email address (e.g. amy@gmail.com).

To add another email address, add to email_array.
**************************************************************************************************/
function define_emails()
{
	email_array = new Array();
	email_array['Kathy'] = 'ourglass.studio, gmail, com';
}

/**************************************************************************************************
This function finds all tags that have the form: <span class="email*****"></span>.
Code is then inserted between the span tags to call the function replace_email() onmouseover.
The parameters for replace_email() are the appropriate index in email_array[] and this.
**************************************************************************************************/

function setup_email()
{
	// Get all <span> tags
	var tags = document.getElementsByTagName("span");

	if (tags.length > 0)
	{
		for (var i = 0; i < tags.length; i++)
		{
	        // Get className of <span> tag
			var cname = tags[i].className;

			// Now look for classes that begin with 'email'
			var s = cname.indexOf('email');

			// If <span> tag and class starts with 'email'
     		if (s == 0)
	        {
				// Get text between <span> tags (e.g. Email John)
				text = tags[i].innerHTML;

        		// Get index to email_array (strip off 'email')
        		index = cname.substring(5);
    			tags[i].innerHTML = '<a href="" onmouseover="replace_email(' + "'" + index + "', " + 'this' + '); return false;">' + text + '</a>';
			}
		}
	}
}

/**************************************************************************************************
This function replaces the generic "Email John Doe" with the actual email address when the user
mouses over the email link.
The innerHTML of the <span> tag is replaced with the new <a> tag with the form:
<a href="mailto:john@gmail.com">john@gmail.com</a>

Parameters:
	index: is the index of the associative array email_array.
	this_ptr: this points to the <a> tag, so this_ptr.parentNode points to the <span> tag.
**************************************************************************************************/

function replace_email(index, this_ptr)
{
    // define array of email addresses
	define_emails();

	var temp = email_array[index];

	// Remove any spaces, leave commas
    while (temp.indexOf(' ') != -1)
		temp = temp.replace(' ', '');

	// Split email string by commas
    var temp = temp.split(',');

	address = temp[0] + '@' + temp[1] + '.' + temp[2];

    this_ptr.parentNode.innerHTML = '<a href="mailto:' + address + '">' + address + '</a>';
}


/* This function alters the style of the navigation bar to indicate urhere.
I added code from the original to shorten the href string so that it does
not include any bookmarks (....#bookmark). Otherwise, the strings would not
match and the urhere formatting would not be applied.
******************************************************************************/

function display_urhere()
{	if (!document.getElementById)
	{	
		return;
	}

	var list = document.getElementById("navbar");
	var page = list.getElementsByTagName("a");
	var currentHref = document.location.href;

	var anchorPosition = currentHref.indexOf("#");
	if (anchorPosition >= 0)
	{	currentHref = currentHref.substring(0, anchorPosition);
	}

	currentHref = getSimpleHref(currentHref);
	
	for (var i = 0; i < page.length; i++)
	{	var href = getSimpleHref(page[i].href)	

		if (href == 'index.html')
		{	var home_index = i;
		}

		// This is when url doesn't include the page. Highlight index.html
		if ((href == currentHref) || ((currentHref.length == 0) && (home_index >= 0)))
		{			
			if ((currentHref.length == 0) && (home_index >= 0))
			{	i = home_index;
			}
			
			page[i].style.background = "#800000";	
			page[i].style.border = "none";	
			page[i].style.color = "#fff";	
			
/*			page[i].parentNode.style.backgroundColor = "#fff";	*/	// parentNode will be <li>

			break;
		}
	}
}

/******************************************************************************
This function was added because Mac Safari does not include the directory structure
before the href, so there was never a match. This function strips the beginning directory structure
away and just leaves the end part--such as about_us.htm
******************************************************************************/

function getSimpleHref(s)
{	var length;
	var anchorPosition = 0;	

	while (anchorPosition >= 0)
	{	anchorPosition = s.indexOf('/');
		length = s.length;

		if (anchorPosition >= 0)
		{	s = s.substring(anchorPosition + 1, length);
		}		
	}
	
	return(s);
}


// end hiding contents from old browsers  -->
// </script>