// <script type="text/javascript">
<!--  to hide script contents from old browsers

window.onload = init;

function init()
{
	display_urhere();
	setup_email();
	setup_bg_hover();
}

/* 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");
	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 = "#f8dfb2";
			page[i].style.backgroundColor = "#6e3631";
			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('sub-nav');
	
	if (list == null)
	{	
		return;
	}
	
	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 = "#f8dfb2";	
			page[i].style.backgroundColor = "#6e3631";
			//page[i].parentNode.style.background = "#fff";			// Parent node is <div>

			break;
		}
	}
}

/**************************************************************************************************
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 <a href="" class="emailMichele">Email Michele</a> where each
email address has an email**** associated with it.

To add another email address, add to email_array and add another case statement.
**************************************************************************************************/

function setup_email()
{
	var email_array = new Array();
	email_array['Info'] = 'Info';

	for (var name in email_array)
		email_array[name] += "@" + 'RubyCreekDesign' + "." + 'com';
	
	var anchors = document.getElementsByTagName("a");
	if (anchors == null)
		return;

	for (var i = 0; i < anchors.length; i++)
	{
		switch(anchors[i].className)
		{
			case "emailRCD":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Info'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Info'];
				}
				break;
			}
	
		}
	}
}

/***
var name1 = "info";
var name2 = "RubyCreekDesign";
var name3 = "com";
var rcd_email = name1 + "@" + name2 + "." + name3;

function setup_email()
{
	var anchors = document.getElementsByTagName("a");
	if (anchors == null)
		return;

	for (var i = 0; i < anchors.length; i++)
	{
		switch(anchors[i].className)
		{
			case "emailRCD":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + rcd_email;
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = rcd_email;
				}
				break;
			}
		}
	}
}

***/

/*******************************************************************************
This function changes the background of the portfolio table cells on mouseOver.
Each <td> has class = background-hover. Can't remember why I don't do it with Safari.
*******************************************************************************/

function setup_bg_hover()
{
	var id = document.getElementById('main-content');
	
	var hover_class = getElementsByClass("background-hover", id, 'td');

	if (hover_class == null)
		return;

	var safari = (navigator.userAgent.indexOf('Safari') != -1);	
	if (safari)
		return;

	for (var i = 0; i < hover_class.length; i++)
	{
		hover_class[i].onmouseover = function()
		{
			this.style.backgroundColor = '#f0f0f0';
		}
		hover_class[i].onmouseout = function()
		{
			this.style.backgroundColor = 'transparent';
		}
	}
}

/***
function hover_bg(selection, state)
{
	
	var safari = (navigator.userAgent.indexOf('Safari') != -1);	
	if (safari)
		return;
	
	selection.style.backgroundColor = (state == 1) ? '#f0f0f0' : 'transparent';
}
***/

/*******************************************************************************
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 is for the testimonials.htm page. The testimonials have background
images for quotes, but Safari only displays the end quote. So, this detects if 
the browser is Safari and then changes the background to not include the quotes.
*******************************************************************************/

function remove_quote_images()
{
	var safari = (navigator.userAgent.indexOf('Safari') != -1);	
	if (safari)
	{
		var testimonial = document.getElementById("testimonial");
		var dd = testimonial.getElementsByTagName("dd");
		
		for (var i = 0; i < dd.length; i++)
		{	
			dd[i].style.backgroundImage = "none";			
		}
	}
}

// end hiding contents from old browsers  -->
// </script>