window.onload = initAll;

var thisMenuID = 0; // set thisMenuID to be global so toggleDIvOn and toggleDivOff can access it once it is set
var thisURL = 0;
// start get current page file name
var startPage = location.href.lastIndexOf("/")+1;
var endPage = location.href.lastIndexOf(".");
var currentFileName = location.href.substring(startPage,endPage); 
// end get current page file name

function initAll() {
	var allLinks = document.getElementsByTagName("a");
	
	for (var i=0; i<allLinks.length; i++) {
		if (allLinks[i].className.indexOf("pullDown") > -1) {
			//allLinks[i].onclick = retFalse; // uncomment this line if you don't want anything to happen when a main parent link is clicked
			allLinks[i].onmouseover = toggleMenu;
		}
	}
}

function toggleMenu() {
	var startMenu = this.href.lastIndexOf("/")+1;
	var stopMenu = this.href.lastIndexOf(".");
	var thisMenuName = this.href.substring(startMenu,stopMenu);
	
	thisMenuID = this.id;
	thisURL = thisMenuName;
	//this.style.backgroundPosition = 'bottom';

	document.getElementById(thisMenuName).style.display = "block";

	this.parentNode.className = thisMenuName;
	this.parentNode.onmouseout = toggleDivOff;
	this.parentNode.onmouseover = toggleDivOn;	
}

function toggleDivOn() {
	document.getElementById(this.className).style.display = "block";
	if(thisMenuID == "link-about") {
		document.getElementById(thisMenuID).style.backgroundPosition = '0 0';
	}
	if(thisMenuID == "link-estate-planning") {
		document.getElementById(thisMenuID).style.backgroundPosition = '-191px 0';
	}
	if(thisMenuID == "link-news") {
		document.getElementById(thisMenuID).style.backgroundPosition = '-377px 0';
	}
	if(thisMenuID == "link-resources") {
		document.getElementById(thisMenuID).style.backgroundPosition = '-527px 0';
	}
	if(thisMenuID == "link-contact") {
		document.getElementById(thisMenuID).style.backgroundPosition = '-675px 0';
	}
}

function toggleDivOff() {
	document.getElementById(this.className).style.display = "none";
	if(thisMenuID == "link-about") {
		if(thisURL == currentFileName || "collari-attorney-at-law-testimonials" == currentFileName) {
			
		} else {
			document.getElementById(thisMenuID).style.backgroundPosition = '0 -26px';
		}
	}
	if(thisMenuID == "link-estate-planning") {
		if(thisURL == currentFileName || "estate-planning-probate" == currentFileName || "estate-planning-revocable-living-trusts" == currentFileName || "estate-planning-estate-taxes" == currentFileName) {
			
		} else {
			document.getElementById(thisMenuID).style.backgroundPosition = '-191px -26px';
		}
	}
	if(thisMenuID == "link-news") {
		if(thisURL == currentFileName) {
			
		} else {
			document.getElementById(thisMenuID).style.backgroundPosition = '-377px -26px';
		}
	}
	if(thisMenuID == "link-resources") {
		if(thisURL == currentFileName || "collari-attorney-at-law-resources-downloads" == currentFileName) {
			
		} else {		
			document.getElementById(thisMenuID).style.backgroundPosition = '-527px -26px';
		}
	}
	if(thisMenuID == "link-contact") {
		if(thisURL == currentFileName) {
			
		} else {
			document.getElementById(thisMenuID).style.backgroundPosition = '-675px -26px';
		}
	}
}

function retFalse() {
	return false;
}
