// ==============================
// SET VARIABLES
// ==============================


// Extract the URL minus the domain name.
// Find the index of the first '/' AFTER the 'http://' and extract everything that follows
var url = document.URL.substr(document.URL.indexOf('/',7));

// Handle any '#' or '?' in the url. They have to be removed for the on-state detection to work.
if (url.indexOf('#') != -1) {
	var urlSplit = url.split('#');
	url = urlSplit[0];
} else if (url.indexOf('?') != -1) {
	var urlSplit = url.split('?');
	url = urlSplit[0];
}

// Extract the first directory of the URL
// This is used to activate the main button on states
// Extract everthing up to but not including the 2nd '/'
var pathParts = url.split('/');
var urlMainDir = pathParts[1]; // Switch to [1] prior to launch
urlMainDir = '/' + urlMainDir; // Switch '/' to '/' prior to launch
// This is used in the news page when arriving from the news spotlight box

// ==============================
// RUN ALL ONLOAD JQUERY COMMANDS
// ==============================
$(document).ready(function() {
						   
	// ========================================================
	// SET THE ON CLASS TO THE APPROPRIATE MENU BUTTONs
	// ========================================================	
	// Set the on state for the left margion buttons
	$("div#subnav ul#leftNav li a[href='" + url + "']").parent().addClass('on');
	
	// Set the on state for the main menu buttons
	// Match any href that begins with the loaded main directory
	// We test first for an empty varible to prevent on-states on the home page
	//if (urlMainDir != '') {
		$("ul#mainNav li a[href^='" + urlMainDir + "']").parent().addClass('on');
	//}
});


