// jQuery
$(document).ready(function(){
	// gracefully handle errors
	function handleError() {
		return true;
	}
	window.onerror = handleError; // uncomment for deploy
	
	// For the Nav
	$.swapImage(".swapImage");
	
	
	// Override the main tabs for the sub nav
	var charAfterTheUrl = 1; // used for developement to crop the start of the url. change to 0 to deploy
	var path = location.pathname.substring(charAfterTheUrl);
	var defaultHome = true;
	var expInd = /^index/i;
	var expWho = /^whoWe/i;
	var expTea = /^team/i;
	var expSvc = /^svcMain/i;
	var expNew = /^news/i;
	var expCon = /^contact/i;
	var expRec = /^resources/i;
	
	var pageExp = new Array();
	pageExp[0] = expInd;
	pageExp[1] = expWho;
	pageExp[2] = expTea;
	pageExp[3] = expSvc;
	pageExp[4] = expNew;
	pageExp[5] = expCon;
	pageExp[6] = expRec;
	
	for(x in pageExp) {
		if(path.match(pageExp[x])) {
			var navTab = path.match(pageExp[x]);
			//alert(navTab);
			activeLink = $('#navMain a[href$="' + navTab + '.shtml' + '"]').children("img");
			var src = activeLink.attr("src").match(/[^\.]+/) + "b.png";
			activeLink.attr("src", src);
			var defaultHome = false; // the default page must be up 
		}
	}
	
	// see if the default page is up and activate that tab
	if(defaultHome == true) {
		var navTab = "index";
		//alert(navTab);
		activeLink = $('#navMain a[href$="' + navTab + '.shtml' + '"]').children("img");
		var src = activeLink.attr("src").match(/[^\.]+/) + "b.png";
		activeLink.attr("src", src);
	}
	
	// Automatically class active Sub Navs
	$(function(){
		var path = location.pathname.substring(charAfterTheUrl);
		if (path) {
			activeLink2 = $('#navService a[href$="' + path + '"]').children("img");
			var src2 = activeLink2.attr("src").match(/[^\.]+/) + "b.png";
			activeLink2.attr("src", src2);
		}
	});
	 
	
});
