/* this file stores all javascript that should run on page load */

window.onload = initAll;

function initAll() {

	// Main Navigation Page Indicator 
	// get document domain and file name	
	if (document.documentURI) {
		var thisFileName = document.documentURI;
		if (location.pathname == "/") {	// if domain only
			thisFileName = thisFileName + "index.php"; // add default file
		} 
		else {
			thisFileName = thisFileName; // else use actual file name
		} 
	}
	else {  // msie
		var hostName = location.hostname;
		var pathName = location.pathname;
		var searchName = location.search;
		var thisFileName = "http://" + hostName + pathName + searchName;
		if (pathName == "/") {
			pathName = "/index.php";
			thisFileName = "http://" + hostName + pathName + searchName;
		}
		else {
			thisFileName = thisFileName;
		}						
	} // end: msie
		
	var referringPage = document.referrer; 
	var allLinks = document.getElementsByTagName("a");	
	
	var articlesLink = document.getElementById("articlesMainPage");
	var servicesLink = document.getElementById("servicesMainPage");
	
	var selectedTabLink = (allLinks.className = "selectedTab");
	var mainNavLink = (allLinks.className = "main-nav");
	
	for (var i = 0; i < allLinks.length; i++) {	// find all a tags
		if (allLinks[i].className.indexOf("main-nav") > -1) { // if any a tags with the class name 'main-nav' are found...
			var allNavLinks = allLinks // new var for nav links only
			
			if (allNavLinks[i] == thisFileName) { 	// if the main nav contains a link match to this file name
				var pageMatch = allNavLinks[i];		// store the match in var pageMatch
				pageMatch.className = "selectedTab"; // change the CSS class for the nav tab of the match (current page) 
			}
			// if the referring page is Articles and this file does not match one of the main nav links, highlight the articles tab
			if ((referringPage == articlesLink) && 
				(thisFileName != 'http://www.zernerlaw.com') &&
				(thisFileName != 'http://www.zernerlaw.com/index.php') && 
				(thisFileName != 'http://www.zernerlaw.com/about.php') &&
				(thisFileName != 'http://www.zernerlaw.com/#') &&
				(thisFileName != 'http://www.zernerlaw.com/bio.php') &&
				(thisFileName != 'http://www.zernerlaw.com/clients.php') &&
				(thisFileName != 'http://www.zernerlaw.com/j/index.php?option=com_content&task=view&id=27&Itemid=32') &&
				(thisFileName != 'http://www.zernerlaw.com/links.php') && 
				(thisFileName != 'http://www.zernerlaw.com/legal-services/copyright-law.php') && 
				(thisFileName != 'http://www.zernerlaw.com/legal-services/trademark-law.php') && 
				(thisFileName != 'http://www.zernerlaw.com/legal-services/entertainment-law.php') && 
				(thisFileName != 'http://www.zernerlaw.com/legal-services/litigation.php')) { 
				articlesLink.className = "selectedTab"; 
			}
			// if this file is one of the services sub pages, highlight the services tab
			if ((thisFileName == 'http://www.zernerlaw.com/legal-services/copyright-law.php') ||  
				(thisFileName == 'http://www.zernerlaw.com/legal-services/trademark-law.php') || 
				(thisFileName == 'http://www.zernerlaw.com/legal-services/entertainment-law.php') || 
				(thisFileName == 'http://www.zernerlaw.com/legal-services/litigation.php') ) {
				servicesLink.className = "selectedTab";
			}
		}
	}

	/* 	main nav
	http://www.zernerlaw.com/index.php	
	http://www.zernerlaw.com/about.php
	http://www.zernerlaw.com/#
	http://www.zernerlaw.com/bio.php
	http://www.zernerlaw.com/clients.php
	http://www.zernerlaw.com/j/index.php?option=com_content&task=view&id=27&Itemid=32
	http://www.zernerlaw.com/links.php
	*/
	
	/* services
	http://www.zernerlaw.com/legal-services/copyright-law.php
	http://www.zernerlaw.com/legal-services/trademark-law.php
	http://www.zernerlaw.com/legal-services/entertainment-law.php
	http://www.zernerlaw.com/legal-services/litigation.php
	*/
}	
