/*++++++++ Accessible DHTML Menu ++++++++++
Copyright 2006 Christian Jacobsson
Feel free to use but this notice must remain
+++++++++++++++++++++++++++++++++++++++++++*/

if(document.getElementById && !(window.opera && !document.createComment))
{
	// CSS som bara bör användas tillsammans med javascript
	// och som bör användas före window.onload:

	document.write('<link rel="stylesheet" type="text\/css" href="navmenu.css" ');
	document.write('media="screen, projection">');
	document.write('<style type="text\/css" media="screen, projection">');
	document.write('ul#top li {display: inline;}');
	document.write('ul#top li ul {display: none;}');
	document.write('<\/style>');

	window.onload=function()
	{
		menu();
	}	
}

function menu()
{
	var top = document.getElementById('top');
	var topLI = top.getElementsByTagName('li');

	// Skapa submeny:
	var ul = document.createElement('ul');
	document.getElementById('headerB').appendChild(ul);
	ul.id='sub';
	var subUL = document.getElementById('sub');
	subUL.innerHTML+=''; // Safari < 1.3 buggfix?

	for(var i=0; i<topLI.length; i++)
	{	
		function openMenu(curItem)
		{

			// inaktivera tidigare aktiva
			for(var j=0; j<topLI.length; j++)
			{
				topLI[j].className='';
			}

			// nuvarande aktiva
			curItem.parentNode.className='active'; // hamnar på LI
			subUL.className=curItem.className; // för olika vänstermarginal	

			// skapa submeny
			var parentUL=curItem.parentNode.getElementsByTagName('ul');
			if(parentUL.length>0)
			{
				subUL.innerHTML=parentUL[0].innerHTML;
			}			
			else // om subkategorier saknas
			{
				subUL.innerHTML='<li><\/li>';
			}


			// ändra nuvarande sidas länk till span:	
			var subLink = subUL.getElementsByTagName('a');
			for(var i=0; i<subLink.length; i++)
			{	
				if(subLink[i].href==document.location.href)
				{
					var span=document.createElement('span');
					span.innerHTML=subLink[i].innerHTML;
					subLink[i].parentNode.replaceChild(span, subLink[i]);
				}
			}

		} // end function openMenu()

		var topLink=topLI[i].getElementsByTagName('a')[0];
		topLink.tabIndex=i+1; // setAttribute('tabindex', i+1) fungerar ej i IE6

		// Events 		
		if(topLink.className==document.body.className) // nuvarande kategori
		{
			openMenu(topLink);
		}		
		topLink.onclick=function(){openMenu(this);}
		topLink.onfocus=function(){openMenu(this);}
		
	} // end loop
	
} // end menu()











