// <script type="text/javascript">
<!--  to hide script contents from old browsers

$(document).ready(function()
{
	// Wait for everything to download, then fade out black and white image on home page
	$(window).load(function()
	{
		$('#banner-bw').fadeOut(3000);
	});

	// For Services page, add toggle function for text inside <div class="toggle">
	$('h4 a').click(function(eve)
	{
		eve.preventDefault();
		$(this).parent().next('div').toggle();
	});

	display_urhere();
	setup_email();
});

/* 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()
{	var list; var page; var currentHref; var href; var anchorPosition;

	if (!document.getElementById)
	{
		return true;
	}

	list = document.getElementById("navbar");
	if (list == null)
		list = document.getElementById("navbar-db");

	page = list.getElementsByTagName("a");
	currentHref = document.location.href;

	anchorPosition = currentHref.indexOf("#");
	if (anchorPosition >= 0)
	{	currentHref = currentHref.substring(0, anchorPosition);
	}

	currentHref = getSimpleHref(currentHref);

	for (var i = 0; i < page.length; i++)
	{	href = getSimpleHref(page[i].href)

		if (href == currentHref)
		{
			//page[i].style.backgroundColor = "#7f3434";
			page[i].style.color = "#fff";
			//page[i].style.textDecoration = "underline";
			//page[i].parentNode.backgroundColor = "#fff";
			break;
		}
	}

	display_subnav_urhere();
}

/*
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);
}

/*******************************************************************************
This function sets the urhere for the sub navigation menu for the portfolio pages.
If there is no sub-nav ID on the page, then the function simply returns.
*******************************************************************************/

function display_subnav_urhere()
{
	var href;

	//var list = document.getElementById('subnav');
	var list = document.getElementById('sidebar-content');

	if (list == null)
	{
		return false;
	}

	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++)
	{
		href = getSimpleHref(page[i].href)

		if (href == currentHref)
		{
			page[i].style.color = "#000";
			page[i].style.backgroundColor = "#9d0810";
			//page[i].parentNode.style.background = "#fff";			// Parent node is <div>

			return(TRUE);
		}
	}
}

/**************************************************************************************************
This function changes the display from "none" to "block" or "block" to "none"of the selected
section. This only includes selected tags.
**************************************************************************************************/
function display_text(link)
{
	// Get <h3>
	h3 = link.parentNode;
	// Get <div>
	div = h3.parentNode;

	// Get <p> within specific <div>
	var paragraphs = div.getElementsByTagName("p");

	// Change display to block
	for (var i = 0; i < paragraphs.length; i++)
	{
		if (paragraphs[i].style.display == "block")
			paragraphs[i].style.display = "none";
		else
			paragraphs[i].style.display = "block";
	}


	var lists = div.getElementsByTagName("ul");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
	{
		if (lists[i].style.display == "block")
			lists[i].style.display = "none";
		else
			lists[i].style.display = "block";
	}


	var lists = div.getElementsByTagName("h4");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
	{
		if (lists[i].style.display == "block")
			lists[i].style.display = "none";
		else
			lists[i].style.display = "block";
	}


	var lists = div.getElementsByTagName("iframe");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
	{
		if (lists[i].style.display == "block")
			lists[i].style.display = "none";
		else
			lists[i].style.display = "block";
	}


	var lists = getElementsByClass('risk-tracker-img', div)

	// Change display to block
	for (var i = 0; i < lists.length; i++)
	{
		if (lists[i].style.display == "block")
			lists[i].style.display = "none";
		else
			lists[i].style.display = "block";
	}
}

/**************************************************************************************************
This function changes the display from "none" to "block" of the selected div.
This only includes selected tags. This is to be called from the actual page and should be sent
the id of the <div>. Used when page is called from left hand sidebar links.
**************************************************************************************************/
function display_service(div_id)
{
	var div = document.getElementById(div_id);

	// Get <p> within specific <div>
	var paragraphs = div.getElementsByTagName("p");

	// Change display to block
	for (var i = 0; i < paragraphs.length; i++)
		paragraphs[i].style.display = "block";


	var lists = div.getElementsByTagName("ul");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";


	var lists = div.getElementsByTagName("h4");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";


	var lists = div.getElementsByTagName("iframe");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";


	var lists = getElementsByClass('risk-tracker-img', div)

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";
}

/**************************************************************************************************
This function changes the display from "none" to "block" of the selected div.
This only includes selected tags. This is to be called from the actual page and should be sent
the id of the <div>. Used when page is called from left hand sidebar links.
**************************************************************************************************/
function display_news(div_id)
{
	var div = document.getElementById(div_id);

	// Get <p> within specific <div>
	var paragraphs = div.getElementsByTagName("p");

	// Change display to block
	for (var i = 0; i < paragraphs.length; i++)
		paragraphs[i].style.display = "block";


	var lists = div.getElementsByTagName("ul");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";


	var lists = div.getElementsByTagName("h4");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";


	var lists = div.getElementsByTagName("iframe");

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";


	var lists = getElementsByClass('risk-tracker-img', div)

	// Change display to block
	for (var i = 0; i < lists.length; i++)
		lists[i].style.display = "block";
}

/**************************************************************************************************
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 where each array element corresponds to
1 email address.

To use in html code, as an example, 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.

First, an <a href="#"></a> tag is wrapped around the text inside the <span> tag for all <span>
tags with class="email***".

On mouseenter (mouseover triggers both entering and leaving), the <a> tag is replaced with
the actual mailto href, e.g. <a href="mailto:test@gmail.com"> and the text that the generic text
that the user sees, e.g. Email John Doe, is replaced with the email address, e.g. test@gmail.com.
**************************************************************************************************/
function setup_email()
{
	// Add <a> tag to any <span> with class="email****"
	$('span[class^="email"]').wrapInner('<a href="#"></a>');

	// On mouseenter, replace <a href="#"> with mailto
	$('span[class^="email"]').mouseenter(function(eve)
	{
		email_array = new Array();
		email_array['Pendulum'] = 'Contact, WeArePendulum, com';
		email_array['Info'] = 'Info, WeArePendulum, com';
		email_array['AssistLine'] = 'AssistLine, WeArePendulum, com';
		email_array['OnlineTraining'] = 'OnlineTraining, WeArePendulum, com';
		email_array['EventsInfo'] = 'EventsInfo, WeArePendulum, com';
		email_array['ClaimsInfo'] = 'ClaimsInfo, WeArePendulum, com';
		email_array['MMSEAInfo'] = 'MMSEAInfo, WeArePendulum, com';

		eve.preventDefault();

		// If a href has already been changed to mailto, prevent repeated operation
		if ($(this).children('a').attr('href').indexOf('mailto') >= 0)
			return;

		// Get currently displayed html text within <a> tag
		var html = $(this).children('a').html();

		// Get index to email_array (strip off 'email' from class name)
		var index = $(this).attr('class').substring(5);

		// Split email string by commas
		var temp = email_array[index].split(',');

		// Construct email address (also trim spaces)
		var address = jQuery.trim(temp[0]) + '@' + jQuery.trim(temp[1]) + '.' + jQuery.trim(temp[2]);
		$(this).html(html + ' <a href="mailto:' + address + '">' + '(' + address + ')' + '</a>');
	});
}

/*******************************************************************************
It’s simple. It works just how you think getElementsByClass would work, except better.

1. Supply a class name as a string.

2. (optional) Supply a node. This can be obtained by getElementById, or simply by just
throwing in “document” (it will be document if don’t supply a node)). It’s mainly useful
if you know your parent and you don’t want to loop through the entire D.O.M.

3. (optional) Limit your results by adding a tagName. Very useful when you’re toggling
checkboxes and etcetera. You could just supply “input“. Or, if you’re like me, and you
said Good Bye to IE5, you can use the “*” asterisk as a catch-all (meaning ‘any element).
*******************************************************************************/
function getElementsByClass(searchClass, node, tag)
{
	var classElements = new Array();

	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';

	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;

	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++)
	{
		if ( pattern.test(els[i].className) )
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/*******************************************************************************
This function simply opens a window that displays an image.
*******************************************************************************/
function open_window(image, width, height)
{
	window.open('../images/' + image,'mywindow','width=' + width + ',height=' + height + "menubar=0,toolbar=0");
}


function subnav_urhere(id)
{
	var href;

	//var list = document.getElementById('subnav');
	var list = document.getElementById('sidebar-content');

	if (list == null)
	{
		return false;
	}

	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++)
	{
		href = getSimpleHref(page[i].href)

		var x = href.indexOf(id);

		if (href.indexOf(id) >= 0)
		{
			page[i].style.color = "#000";
			page[i].style.backgroundColor = "#fff";
			//page[i].parentNode.style.background = "#fff";			// Parent node is <div>

			return(TRUE);
		}
	}
}


// end hiding contents from old browsers  -->
// </script>