// <script type="text/javascript">
<!--  to hide script contents from old browsers

//window.onload = display_urhere;
window.onload = init;

function init()
{
	display_urhere();
	set_new_window_on_click();
	set_new_window_on_events_table_link();	
	setup_email_brad();
}

/**************************************************************************************************
This function sets up a link with class "emailBrad" to send email.
**************************************************************************************************/

function setup_email_brad()
{
	var link = document.getElementById("emailBrad");
	if (link == null)
		return;
		
	link.onclick = function()
	{	
		var name0 = "Email Brad"
		var name1 = "brad"
		var name2 = "bradhatfield"
		var name3 = "com"
		var addr = name1 + "@" + name2 + "." + name3
		var full = "mail" + "to:" + addr

		document.location.href= full;
		return(false);
	}
}

/**************************************************************************************************
This function causes a new window to open for any link <a> that has class "newWindow".
**************************************************************************************************/

function set_new_window_on_click()
{	
	var anchors = document.getElementsByTagName("a");
	if (anchors == null)
		return;

	for (var i = 0; i < anchors.length; i++)
	{	
		if (anchors[i].className == "newWindow")
		{
			anchors[i].onclick = function()
			{
				window.open(this.href); 
				return false;
			}
		}
	}
}

/**************************************************************************************************
This function causes a new window to open for any link <a> that is within class "events-table".
**************************************************************************************************/

function set_new_window_on_events_table_link()
{	
	var elements = getElementsByClass(document, 'events-table', '*');

	for (i = 0; i < elements.length; i++)
	{
		anchors = elements[i].getElementsByTagName("a");

		for (var j = 0; j < anchors.length; j++)
		{	
			anchors[j].onclick = function()
			{
				window.open(this.href); 
				return false;
			}
		}
	}
}

/**************************************************************************************************
This function causes a new window to open for any link <a> that is within ID "events-table".
**************************************************************************************************/
/***
function set_new_window_on_events_table_link()
{	
	var id = document.getElementById("events-table");
	if (id == null)
		return;

	var anchors = id.getElementsByTagName("a");
	if (anchors == null)
		return;

	alert("found events-table and a");
	
	for (var i = 0; i < anchors.length; i++)
	{	
		anchors[i].onclick = function()
		{
			window.open(this.href); 
			return false;
		}
	}
}
***/

/*******************************************************************************
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(node, searchClass, 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("\\b"+searchClass+"\\b");
	for (i = 0, j = 0; i < elsLen; i++) 
	{
		if ( pattern.test(els[i].className) ) 
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/**************************************************************************************************
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");
	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++)
	{	
		var href = getSimpleHref(page[i].href)	
	
		if (href == currentHref)
		{	
			page[i].style.background = "#aebcd7 url(images/navbar_bg.gif) repeat-x top left";
			//page[i].parentNode.style.background = "#aebcd7 url(images/navbar_bg.gif) repeat-x";
			page[i].style.color = "#000";
			break;
		}
	}
	
	display_av_samples_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 displays all the RH Systems products in a sidebar. These products 
are repeated on many pages, so each page only needs a function call to this 
routine to display.

The end of the routine enables the urhere colors for the navigation bar when any
of the products subpages are viewed. Except for the Solutions/Industries page. In
that case, the navigation_flag is set on the solutions_industries.html page.
*******************************************************************************/

function display_av_samples_subnav_urhere()
{	if (!document.getElementById)
		return;

	var list = document.getElementById("subnav");
	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++)
	{	
		var href = getSimpleHref(page[i].href)	
	
		if (href == currentHref)
		{	
			//page[i].parentNode.style.background = "#f9d030";		// Parent node is <li>
			//page[i].parentNode.style.background = "#aebcd7";		// Parent node is <li>
			//page[i].style.background = "#6e7c97 url(images/subnav_bg.gif repeat-x";		
			page[i].style.color = "#000";
			page[i].style.fontWeight = "bold";

			// Select urhere for top level ("Audio/Video Samples")
			var id = document.getElementById("avID");				
			id.style.background = "#aebcd7 url(images/navbar_bg.gif) repeat-x";
			id.style.color = "#000";

			break;
		}
	}
}

/*******************************************************************************
The following function will validate the form for requesting literature.
*******************************************************************************/

var button_clicked;

function validate_news_form(form)
{
	var NEWS_TITLE_MAXCHARS = 255;
	var NEWS_NOTE_MAXCHARS = 4000;
	
	var i, n, checked;
	var why = "";
	
	if (button_clicked == 'Cancel')
		return(TRUE);	

/**
	//Test for radio buttons
	for (i = 0, checked = 0; i < form.literature.length; i++) 
	{
		if (form.literature[i].checked) 
		{
			checked = 1;
		}
	}
	if (checked == 0)
    {	why += "Please select a product. \n";
    }
**/

	if (form.month.value == '')
		why += "Please fill in month. \n";

	if (form.day.value == '')
		why += "Please fill in day. \n";
	
	if (form.year.value == '')
		why += "Please fill in year. \n";

	if (form.title.value == '')
    	why += "Please fill in news title. \n";
	else if (form.title.value.length > NEWS_TITLE_MAXCHARS)
		why += 'Too many characters in the Title text box. Max is ' + NEWS_TITLE_MAXCHARS + '. \n';

	if (form.note.value == '')
    	why += "Please fill in news text. \n";
	else if (form.note.value.length > NEWS_NOTE_MAXCHARS)
		why += 'Too many characters in the News text box. Max is ' + NEWS_NOTE_MAXCHARS + '. \n';

	if (why == "")
		return(true);
	else
	{	alert(why);
		return(false);
	}
}

/*******************************************************************************
This sets up a multi-dimension array for displaying rotating messages.
*******************************************************************************/

var index = 0;
var next_img;
var folder = 'images/';		// Folder where all images are kept

var img_array = new Array(
	'BradMontegoMichael',
	'JimBelushiKeithFull',
	'VegetableFrame', 
	'brad_keith_jeff',
	'rescue_me', 
	'BradEmmyWinner_1', 
	'BradMatthewBroderickGaye_1', 
	'meegan', 
	'AwardBMIPodium', 
	'C_C_Brad_MJF2', 
	'BirdlandGroupDistant_4', 
	'BradAndSheilaJordan'
	);

var caption_array = new Array(
	'Brad, Montego Glover (soloist) and Michael Krajewski',
	'Jim Belushi and Keith Lockhart<br>(<em>photo by Bill Brett for the Boston Globe</em>)',
	'Brad and Peter Tolan score Primetime Emmy Nomination for Rescue Me Season 5 Featured Song',
	'Brad, Keith Lockhart and Jeff Meegan.',
	'Brad is named co-composer for FX network hit series, <em><strong>Rescue Me</strong></em>',
	'Brad with his Emmy at the 2006 Emmy Awards', 
	'Brad with Matthew Broderick and Gaye Tolan Hatfield at premiere of Finding Amanda',
	'Brad and Jeff Meegan Produce New Christmas Album',
	'Brad receives a <a href="http://www.bmi.com/news/entry/534992" target="_blank">BMI Film/TV Award</a>',
	'Brad and Cassandre at the 2006 Monterey Jazz Festival',
	'Pictured L-R: Brad, Rebecca Parris, Dean Johnson, Matt Gordy @ Birdland NYC',
	'Brad and Sheila Jordan'
);

var description_array = new Array(
								  
	'Brad\'s arrangement and orchestration of <em>Bring Them Home</em> received performances by The Houston and Atlanta Symphony during the 2011 holiday season under the direction of Michael Krajewski. <br><a href="/news.php">Read more...</a>',
	
	'Brad\'s arrangement of <em>Santa Claus is Back in Town</em> was performed by Jim Belushi,The Boston Pops, and Rockapella during the 2011 holiday season. <br><a href="/news.php">Read more...</a>',
								  
	'Brad and series creator/writer/director Peter Tolan have received an Emmy Nomination for their song "How Lovely To Be A Vegetable" sung by actor Steven Pasquale in a season 5 episode. Cross those fingers!',								  
	'Brad\'s arrangement and orchestration of <strong>Bring Them Home</strong> received <strong>standing ovations</strong> throughout the <strong>Boston Pops</strong> 2010 holiday season.<br><a href="news.php">Read more...</a>',
	'Beginning season 5 episode 11,  Brad has been added as co-composer to the successful TV series <em><a href="http://www.fxnetworks.com/shows/originals/rescueme/">Rescue Me</a></em> starring Denis Leary. Great show!',								  
	'Brad Hatfield and co-writer <a href="http://www.michaelkisur.com/" target="_blank">Michael Kisur</a> have won an Emmy for Outstanding Original Song. Their song, "Sunshine," was written for The Young and the Restless. <br><a href="news.php">Read more...</a>',
	'Brad and Gaye contributed several featured songs and arrangements to the new movie Finding Amanda starring Matthew Broderick and Brittany Snow, which premiered at the Tribeca Film Festival in NYC. <a href="http://www.apple.com/trailers/magnolia/findingamanda/trailer/">Watch the Trailer</a>.',
	'Singer/Songwriter <a href="http://cdbaby.com/cd/meegan" target="_blank">Jeff Meegan</a> has teamed up with Emmy Award winning Brad Hatfield and his wife Gaye Tolan Hatfield to create 11 new Christmas Songs. The CD features the single, <em>Bring Them Home</em>.',
	'Brad at the 2007 BMI Film/TV Awards. L to R: Del Bryant President & CEO of BMI Brad with Award; Doreen Ringer Ross BMI Vice President of Film & Television Relations',
	'Brad and Cassandre performed in the Bose Pavillion at the Monterey Jazz Festival. Clint Eastwood stopped by to hear a little rendition of Mystic River and some material from <a href="http://maxjazz.com/mckinley/card/index.html" target="_blank">Cass\' new CD</a>.',
	'Brad performed at Birdland, NYC with Rebecca Parris in November for a week. a <a href="reviews/RpReviewNYTimes.pdf">NY Times critic raved</a> about the performances by Brad, Rebecca and the group.',
	'Brad performed with Jazz Legend <a href="http://www.sheilajordanjazz.com/">Sheila Jordan</a> at the Acton Jazz Cafe October, 2007'
);

/***************************************************************************************************
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_img = document.getElementById('hp-news-img');
	id_caption = document.getElementById('hp-news-caption');
	id_description = document.getElementById('hp-news-description');

	// Preload next image
	index = 1;
	var pic = new Image();
	next_img = folder + img_array[index] + '.jpg'; 
	pic.src = next_img; 

	setTimeout("fadeOut(id_img, id_caption, id_description, 100)", 8 * 1000)
}

/***************************************************************************************************
This function displays a series of text on various pages. 
***************************************************************************************************/

function display_message()
{	
	id_img.src = next_img;

	fadeIn(id_img, id_caption, id_description, 0);

	id_caption.innerHTML = "<strong>" + caption_array[index] + "</strong>";
	id_description.innerHTML = description_array[index];

	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_img, id_caption, id_description, 100)", 8 * 1000)		// 5 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_img, id_caption, id_description, opacity)
{
	if (opacity <= 100)
	{
		setOpacity(id_img, opacity);
		setOpacity(id_caption, opacity);
		setOpacity(id_description, opacity);
		opacity += 5;
		window.setTimeout(function() { fadeIn(id_img, id_caption, id_description, opacity) }, 10);		// 50
	}
}


function fadeOut(id_img, id_caption, id_description, opacity)
{
	if (opacity > 0) 
	{
		setOpacity(id_img, opacity);
		setOpacity(id_caption, opacity);
		setOpacity(id_description, opacity);
		opacity -= 5;
		window.setTimeout(function() { fadeOut(id_img, id_caption, id_description, 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;
}


// end hiding contents from old browsers  -->
// </script>





