/*	Function to set navigation link style based on URL
	And Set Mouse Events */
function navigation(){
	if (document.getElementsByTagName){
		
		// Define Pattern Matching
		pagePattern										= /\w+\.php/gi;
		queryPattern									= /\w+\.php/gi;
		anchorPattern									= /\#/gi;
		extensionPattern								= /\.php/gi;
				
		// Get Navigation Menu
		navMenu											= document.getElementById("menu").getElementsByTagName("ul")[0].getElementsByTagName("li");
		for (n=0; n<navMenu.length; n++){
			aObj										= navMenu[n].getElementsByTagName("a")[0];
			menuStr										= aObj.href.match(pagePattern)[0].replace(extensionPattern,"");
			if (menuStr != "home"){
				aObj.setAttribute("menuStr", menuStr);
				aObj.onmouseover						= function(){ buildMenu(this.attributes["menuStr"].value); };
			} else {
				aObj.onmouseover						= function(){
					
					// Remove Existing Menus
					menuNames						= new Array("about","attorneys","areas","cases","multimedia","contact");
					for (m in menuNames){
						if (document.getElementById(menuNames[m] + "menu")){
							oldMenu					= document.getElementById(menuNames[m] + "menu");
							oldMenu.parentNode.removeChild(oldMenu);
						}
					}
				};
			}
		}
		
	} else {
		// Legacy Browsers
		return false;
	}
}

//	Function To Build Menus
function buildMenu(menuStr){
	
	// If This Menu Already Exists
	if (document.getElementById(menuStr + "menu")){
		return false;
	}
	
	// Clear Existing Timers
	try {
		clearInterval(menuTimer);
	} catch(err) {
	}
	
	// Remove Existing Menus
	menuNames											= new Array("about","attorneys","areas","cases","multimedia","contact");
	for (m in menuNames){
		if (document.getElementById(menuNames[m] + "menu")){
			oldMenu										= document.getElementById(menuNames[m] + "menu");
			oldMenu.parentNode.removeChild(oldMenu);
		}
	}

	// Create New Div Tag
	menuDiv												= document.createElement("div");
			
	// Set ID For Div Tag
	menuDiv.id											= menuStr + "menu";
	
	// Set Div Tag Class
	menuDiv.className									= "menu";
	
	// Set Div Tag Transparency
	menuDiv.style.opacity								= "0.95";
	menuDiv.style["-moz-opacity"]						= "0.95";
	menuDiv.style.filter								= "alpha(opacity=95)";
	
	// Attach Div To Document
	document.body.appendChild(menuDiv);
	
	newUL												= document.createElement("ul");
	menuDiv.appendChild(newUL);
	
	// Get Content
	if (menuStr!="home"){
		
		menuContent										= new Array();	
		ulObj											= document.getElementById("footer").getElementsByTagName("ul");
		
		for (u in ulObj){
			if (ulObj[u].className == menuStr){
				liObj 									= ulObj[u].getElementsByTagName("li")
				for (L=0; L<liObj.length; L++){
					aHref								= liObj[L].getElementsByTagName("a")[0].href;
					aText								= liObj[L].getElementsByTagName("a")[0].innerHTML;
					aTarget								= liObj[L].getElementsByTagName("a")[0].target;
					if (aTarget == "_blank"){
						menuContent[menuContent.length]	= '<a href="' + aHref + '" target="_blank">' + aText + '</a>';
					} else {
						menuContent[menuContent.length]	= '<a href="' + aHref + '">' + aText + '</a>';
					}
				}
			}
		}
	}
	
	// Remove Empty Menus
	if (!menuContent.length>0){
		menuDiv.parentNode.removeChild(menuDiv);
	} else {
			
		// Add Conetnt To Menu
		menuTimer				 						= setInterval("addMenuContent(menuDiv, menuContent);", 10);
	}
}
// Function To Add Content To Menus
function addMenuContent(menuDiv, menuContent){
	
	if (menuDiv.getElementsByTagName("ul")[0].getElementsByTagName("li").length < menuContent.length){
	
		// Build New Menu Item
		newLI											= document.createElement("li");
		newLI.innerHTML									= menuContent[menuDiv.getElementsByTagName("ul")[0].getElementsByTagName("li").length];
		
		// Attach Menu Item To Menu
		menuDiv.getElementsByTagName("ul")[0].appendChild(newLI);
		
		// Set Event Handler
		newLI.onmouseover								= function(){
			
			// Reset Timer
			clearInterval(menuTimer);
			menuTimer									= setInterval("removeMenus();", 2500);
		}

	} else {
		
		// Set Timer To Remove Menu
		clearInterval(menuTimer);
		menuTimer 										= setInterval("removeMenus();", 2500);
	}
}
// Function to Remove Menus
function removeMenus(){
	
	// Clear Existing Timers
	try {
		clearInterval(menuTimer);
	} catch(err) {
	}
	
	// Check All Menus
	menuNames											= new Array("about","attorneys","areas","cases","multimedia","contact");
	for (m in menuNames){
		if (document.getElementById(menuNames[m] + "menu")){
			// Remove Existing Menu
			menuDiv										= document.getElementById(menuNames[m] + "menu");
		}
	}
	
	// Set Timer To Remove Menu Content
	menuTimer											= setInterval("removeMenuContent(menuDiv);", 10);
}
// Function To Remove Content From Menus
function removeMenuContent(menuDiv){
	
	// Get Menu UL Tag
	ulObj												= menuDiv.getElementsByTagName("ul")[0];
	
	// Get Menu LI Tags
	liObj												= ulObj.getElementsByTagName("li");
	
	if (liObj.length > 0){
		// Remove Last LI Tag From Menu
		lastLi											= liObj[liObj.length - 1];
		ulObj.removeChild(lastLi);
		
	} else {
		// When There Are No More LI Tags In Menu Remove Empty Menu
		clearInterval(menuTimer);
		menuDiv.parentNode.removeChild(menuDiv);
	}
}