// <script type="text/javascript">
<!--  to hide script contents from old browsers

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function()
{
	display_urhere();
	setup_email();

	setup_news_scroll();
});

/*******************************************************************************
This function sets up the news scrolling. Based on:
http://www.learningjquery.com/2006/10/scroll-up-headline-reader
*******************************************************************************/
function setup_news_scroll()
{
	headline_count = $("div.headline").size();

	$("div.headline:eq("+current_headline+")").css('top', '5px');

	headline_interval = setInterval(headline_rotate, 5000);

	$('#scrollup').hover(function()
	{
		clearInterval(headline_interval);
	}, function()
		{
			headline_interval = setInterval(headline_rotate, 5000);
			headline_rotate();
		}
	);
}

function headline_rotate()
{
	current_headline = (old_headline + 1) % headline_count;
	
	$("div.headline:eq(" + old_headline + ")")
		//.animate({top: -205}, 4000, 'swing', function()
		.animate({top: -100}, 3000, 'linear', function()
		{
			//$(this).css('top', '210px');
			$(this).css('top', '100px');
		});

	$("div.headline:eq(" + current_headline + ")")
	  .animate({top: 5}, 3000, 'linear');

	old_headline = current_headline;
}

/* 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);

	if ((currentHref == 'design_development.php') ||
		(currentHref == 'manufacturing.php') ||
		(currentHref == 'assembly.php') ||
		(currentHref == 'integration.php') ||
		(currentHref == 'quality.php'))
		services_subnav = true;
	else
		services_subnav = false;

	if ((currentHref == 'commercial.php') ||
		(currentHref == 'defense.php') ||
		(currentHref == 'industrial.php') ||
		(currentHref == 'medical.php'))
		markets_subnav = true;
	else
		markets_subnav = false;

	for (var i = 0; i < page.length; i++)
	{	href = getSimpleHref(page[i].href)

		if ((href == currentHref) ||
			(href == 'services.php' && services_subnav == true) ||
			(href == 'markets.php' && markets_subnav == true))
		{
			page[i].style.backgroundColor = "#9d0810";
			page[i].style.color = "#fff";
			//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');

	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 = "#fff";
			page[i].style.backgroundColor = "#9d0810";
			//page[i].parentNode.style.background = "#fff";			// Parent node is <div>

			return(TRUE);
		}
	}
}

/**************************************************************************************************
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="emailMichele"></span> where each
email address has an email**** associated with it.

To add another email address, add to email_array.
**************************************************************************************************/

function setup_email()
{
	// Get all <span> tags
	var tags = document.getElementsByTagName("span");

	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 index to email_array (strip off 'email')
			index = cname.substring(5);
			insert_email(tags[i], index);
		}
	}
}

/**************************************************************************************************
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="emailMichele"></span> 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 insert_email(tag, index)
{
	var email_array = new Array();
	email_array['ORM'] = 'info, ormincorporated, com';

	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];

	tag.innerHTML = '<a href="mailto:' + address + '">' + address + '</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>';
}

/*******************************************************************************
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 sets up a multi-dimension array for displaying rotating messages.
*******************************************************************************/

var index = 0;
var next_img;

var img_array = new Array('globe', 'teamwork', 'solution2', 'wedeliver');

/***************************************************************************************************
This function initializes the displaying of changing text on various pages. At the beginning a
random number is selected to determine what test to start with. After the first selection, the rest
of the text is displayed in order.
***************************************************************************************************/

function start_display()
{
	id = document.getElementById('big-img');

	// Preload next image
	index = 1;
	var pic = new Image();
	var folder = '../images/';		// Folder where all images are kept
	next_img = folder + img_array[index] + '.jpg';
	pic.src = next_img;

	setTimeout("fadeOut(id, 100)", 3 * 1000)
}

/***************************************************************************************************
This function displays a series of text on various pages.
***************************************************************************************************/

function display_message()
{
	id.src = next_img;

	fadeIn(id, 0);

	if (++index >= img_array.length)
		index = 0;

	// Preload next image
	var pic = new Image();
	var folder = '../images/';		// Folder where all images are kept
	next_img = folder + img_array[index] + '.jpg';
	pic.src = next_img;

	setTimeout("fadeOut(id, 100)", 3 * 1000)		// 3 secs
}

/***************************************************************************************************
The fadeIn function uses a Timeout to call itself every 50ms with an object Id and an
opacity. The opacity is specified as a percentage and increased 5% at a time. The loop
stops once the opacity reaches 100%:
***************************************************************************************************/

function fadeIn(id, opacity)
{
	if (opacity <= 100)
	{
		setOpacity(id, opacity);
		opacity += 5;
		window.setTimeout(function() { fadeIn(id, opacity) }, 10);		// 50
	}
}


function fadeOut(id, opacity)
{
	if (opacity > 0)
	{
		setOpacity(id, opacity);
		opacity -= 5;
		window.setTimeout(function() { fadeOut(id, opacity) }, 10);		// 50
	}
	else
	{
		setTimeout("display_message()", 100);
	}
}

/***************************************************************************************************
The setOpacity function is passed an object and an opacity value. It then sets the opacity of
the supplied object using four proprietary ways. It also prevents a flicker in Firefox
caused when opacity is set to 100%, by setting the value to 99.999% instead.
***************************************************************************************************/

function setOpacity(obj, opacity)
{
	opacity = (opacity == 100) ? 99.999 : opacity;

	if (opacity == 400)
		alert('obj = ' + obj + '  opacity = ' + opacity);
	if (opacity == 600)
		alert('obj = ' + obj + '  opacity = ' + opacity);

	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	//obj.style.filter = "alpha(opacity = " + opacity + ")";

	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

/***************************************************************************************************
This function displays an image when a link on the Assembly page is clicked.
***************************************************************************************************/

function display_assembly(type)
{
	var id = document.getElementById('assembly-img');

	if (type == 'box_panel_build')
		img = '../images/epion.jpg';

	else if (type == 'cable_harness')
		img = '../images/camerapics06_023.jpg';

	else if (type == 'electronic')
		img = '../images/photo_1.jpg';

	else if (type == 'electromechanical')
		img = '../images/camerapics06_020.jpg';

	else if (type == 'mechanical')
		img = '../images/epion.jpg';

	else if (type == 'pneumatic')
		img = '../images/pneumatic.jpg';

	else if (type == 'full_system_build')
		img = '../images/camerapics06_005.jpg';

	else
		img = '';

	id.innerHTML = '<img src="' + img + '">';
}


// end hiding contents from old browsers  -->
// </script>