// JavaScript Document

$(document).ready(function(){
	
	// drop down
	$('#mainNav li').hover( function(){
		$(this).addClass("on");
		$('ul', this).css({display: 'block'});
	}, function(){
		$(this).removeClass("on");
		$('ul', this).css({display: 'none'});
	});
	
	// Friendly classes for menu items
	$("#mainNav > ul > li a span").each(function() {
		classSafe = $(this).html();
		// Strip Matrix Brackets
		classSafe = classSafe.replace(/(\(\()|(\)\))/g, '');
		classSafe = jQuery.trim(classSafe);		
		classSafe = classSafe.toLowerCase().replace(/(\s&amp;\s)|[^a-zA-Z0-9]/g, "-")
		$(this).parent().addClass(classSafe);
	});
	
	// for FontSizer
	var options = { min: -4, max: 0.5};
	//Initialize the font sizer for the site.
	$.FontSizer.Init(options);
	
	// Convert other websites menu to a form
	$(".websiteLinks ul").make_menu();
	$(".otherSites ul").make_menu();
	
	// Add search terms to search results page
	/*
	if ($("#search-results").size()) {
		var searchTerm = $(document).getUrlParam("queries_all_query");
		searchTerm = searchTerm.replace(/\\|\^|\$|\*|\+|\?|\.|\(|\)|\[|\]/g, ' ');
		$("h1#pageHeading").after("<h1>Search results for <em>" + searchTerm + "</em></h1>");
	}*/
	
    // If we are at or past the 4th level or in the 'in your region' section add a back button
	if ( ($(".breadCrumbs").children().size() > 4) || ( ($(".breadCrumbs").children().size() >= 3) && ($("#banner h1").text() == 'In Your Region') ) ) {
		// Get the link of the parent
		var parent = $(".breadCrumbs a:last-child").prev('a');
		var parentLink = $(parent).attr("href");
		var parentTitle =  $(parent).text();
		// Add back to top link
		$(".breadCrumbs").after('<a class="goBack goBackjs" href="' + parentLink  + '" title="Go Back to ' + parentTitle + '">Go Back</a>');
	}
	
	
});