// Capability Menu fix - M. Mayoorathen 3 May 2009
// By default setting the menu for click event
//window.onload = function ()
//{
	var mainMenu = document.getElementById("Menu");
	//alert(getLastPage(""+document.location + ""));
	if(mainMenu)
	{
		var mainMenuUL = mainMenu.getElementsByTagName("ul");
		
		if(mainMenuUL)
		{
			
				var ulLi = mainMenuUL[0].getElementsByTagName("li");
				
				if(ulLi)
				{
					 highlightLink(ulLi,getLastPage(""+document.location + ""));
					for(var i = 0; i < ulLi.length; i++)
					
					{
						
						
						var ulLiUL = ulLi[i].getElementsByTagName("ul");
						
						
						
						if(ulLiUL)
						{
							if(ulLiUL.length > 0)
							{
								var ulLiA = ulLi[i].getElementsByTagName("a");
								
								
								
								if(ulLiA)
								{
									//ulLiA[0].href = "#";
									/*
									ulLiA[0].onclick = function ()
									{
										//alert(this.parentNode);
										disableDisplay(ulLi);
										styleClear(ulLi);
										styleClearAnchor(ulLi);
										if(this.parentNode)
										{
										 var tempUL = this.parentNode.getElementsByTagName("ul");
										// this.style.color = "#FFFFFF";
										 this.style.backgroundRepeat="no-repeat";
										this.style.backgroundImage="url(http://www.aquafruit.com.au/staging/capability/templates/Capability/styles/arr_menu.gif)";
										this.style.backgroundPosition="right 5px";
										
											for(var x = 0; x < tempUL.length; x++)
											{
												tempUL[x].style.display = "block";
												
											}
										
										}
									}
									*/
									
								}
								
								
							//alert(i + "-" + ulLiUL.length);
							}
						}
					}
				}
		}
	}
	
	
//}

//Disable/hide display of sub navigation for first click
function disableDisplay(varULLI)
{
	if(varULLI)
				{
					for(var i = 0; i < varULLI.length; i++)
					
					{
						var ulLiUL = varULLI[i].getElementsByTagName("ul");
						
						
						
						if(ulLiUL)
						{
							if(ulLiUL.length > 0)
							{
								ulLiUL[0].style.display = "none";
							}
						}
					}
				}
}
//Clearing the background horizontal bar of the last li element
function styleClear(varULLI)
{
	if(varULLI)
				{
					for(var i = 0; i < varULLI.length; i++)
					
					{
						var ulLiUL = varULLI[i].getElementsByTagName("ul");
						
						if(ulLiUL)
						{
							if(ulLiUL.length > 0)
							{
								
							var navLi = ulLiUL[0].getElementsByTagName("li");
								for(var x = 0; x < navLi.length; x++)
								{
									
									if(x == (navLi.length - 1))
									{
										navLi[x].style.background = "none";
									}
								}
							
							}
						}
					}
				}
}
//
function highlightLink(varULLI,hLink)
{
	
	if(varULLI)
				{
					for(var i = 0; i < varULLI.length; i++)
					
					{
						var ulLiUL = varULLI[i].getElementsByTagName("ul");
						
						
						
						if(ulLiUL)
						{
							if(ulLiUL.length > 0)
							{
								
							var navLi = ulLiUL[0].getElementsByTagName("li");
								for(var x = 0; x < navLi.length; x++)
								{
									
									var navLiA = navLi[x].getElementsByTagName("a");
									//alert(x);
									if(navLiA)
									{
										
										if(navLiA.length > 0)
										{
											//alert(getLastPage(navLiA[0].href));
											//Main Link Highlight
											var ulLiA = varULLI[i].getElementsByTagName("a");
											
											if(hLink == getLastPage(""+ulLiA[0].href+""))
											{
												styleClear(varULLI);
												
												if(ulLiA)
												{
													if(ulLiA.length > 0)
													{
														ulLiA[0].style.backgroundRepeat="no-repeat";
														ulLiA[0].style.backgroundImage="url(http://www.capability.com.au/templates/Capability/styles/arr_menu.gif)";
														ulLiA[0].style.backgroundPosition="right 5px";
													}
												}
												ulLiUL[0].style.display = "block";

											}
											
											//Sub Link Highlight
											if(hLink == getLastPage(""+navLiA[0].href+""))
											{
												styleClear(varULLI);
												if(ulLiA)
												{
													if(ulLiA.length > 0)
													{
														ulLiA[0].style.backgroundRepeat="no-repeat";
														ulLiA[0].style.backgroundImage="url(http://www.capability.com.au/templates/Capability/styles/arr_menu.gif)";
														ulLiA[0].style.backgroundPosition="right 5px";
													}
												}
												ulLiUL[0].style.display = "block";
												navLiA[0].style.color = "#A21B53";
												navLiA[0].style.fontWeight = "bold";
											}
										}
									}
								}
							
							}
						}
					}
				}
}

//
function getLastPage(docLink)
{
	var tempDocSplit = docLink.split("/");
	
	if(tempDocSplit.length > 0)
	{
		return (tempDocSplit[tempDocSplit.length -1]).replace(/#/,"");
	}
	
	return "";
}
//
function styleClearAnchor(varULLI)
{
	if(varULLI)
				{
					for(var i = 0; i < varULLI.length; i++)
					
					{
						var ulLiA = varULLI[i].getElementsByTagName("a");
						if(ulLiA)
						{
							if(ulLiA.length > 0)
							{
								ulLiA[0].style.background = "none";
								
							}
						}
						
					}
				}
}

