
var highlight = 0;
var maxNav = 9;
var i;
for (i=1; i<=maxNav; i++)
{
	
	if (window.location == document.getElementById("navMa"+i).href)
	{
	
		highlight = i;
		break;
	}

}

if (highlight == 0)
{
	var pathName = window.location.pathname;

	if (pathName=="" || pathName =="/")	//www.phosphor.co.nz or www.phosphor.co.nz/
	{
		highlight = 1;
	}
	else
	{
		// matching for subnav
		for (i=1; i<=maxNav; i++)
		{
			var navHref = document.getElementById("navMa"+i).href;
			// add the / in front to prevent possible clashes
			var prefix = '/' + navHref.substr(navHref.lastIndexOf("/") + 1).substring(0,5).toLowerCase();
			
			if (pathName.indexOf(prefix) > -1)
			{
				highlight=i;
				break;
			}
		}
	}
}

for (i=1; i<=10; i++)
{
	var subnav = document.getElementById("navSubA" + i);
	if (subnav)
	{
		if (window.location == subnav.href)
		{
			//highlight subnav
			subnav.style.backgroundImage = "url(images/subnav-highlight.gif)";
			subnav.style.color = "#ddd";

			break;
		}
	}
	else
		break;
}

for (i=1; i<=10; i++)
{
	var subnav = document.getElementById("navSideA" + i);
	if (subnav)
	{
		if (window.location == subnav.href)
		{
			//highlight subnav
			subnav.style.backgroundImage = "url(images/sidenav-highlight.gif)";
			subnav.style.color = "#ddd";

			break;
		}
	}
	else
		break;
}


if (highlight>0)
{
	document.getElementById("navMa"+ highlight).style.backgroundColor = '#8dd02a';
}



/*

function prev()
{
	if (highlight > 1)	// can't go prev at 1
	{
		window.location = document.getElementById("am"+(highlight-1)).href;
	}
}

function next()
{
	if (highlight < maxNav)	//can't go next at maxNav
	{
		window.location = document.getElementById("am"+(highlight+1)).href;
	}
}
*/