// 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 = 14; // 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 expWho = /^about/i;
	var expSvc = /^services/i;
	var expPro = /^products/i;
	var expIns = /^insurance/i;
	var expDir = /^directions/i;
	var expCon = /^contact/i;
	var expNew = /^news/i;
	
	var pageExp = new Array();
	pageExp[0] = expWho;
	pageExp[1] = expSvc;
	pageExp[2] = expPro;
	pageExp[3] = expIns;
	pageExp[4] = expDir;
	pageExp[5] = expCon;
	pageExp[6] = expNew;
	
	for(x in pageExp) {
		if(path.match(pageExp[x])) {
			var navTab = path.match(pageExp[x]);
			//alert(navTab);
			activeLink = $('#navMain a[href$="' + navTab + '.php' + '"]').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 + '.php' + '"]').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);
		}
	});
	 
	
});
