/*  
'---------------------------------------
' Websound MenuBuilder v. 1.0.0
' (c) Copyright www.websound.dk 2007
' Last modified: 27-07-2007
'---------------------------------------
*/
var img_minus = 'common/images/icons/minus.gif'; var txt_minus = 'Sammentręk menu';
var img_plus  = 'common/images/icons/plus.gif'; var txt_plus  = 'Udvid menu';

function initMenu(root, setActivePage){
var root = document.getElementById(root)
var menulevel = null
// If menutype is TreeView, add expand/collapse functionality
if(root.className.indexOf("mn_tree")!=-1){ 
	var uls = root.getElementsByTagName('UL');
	for (var i = 0; i < uls.length; i++){
		var newImg = document.createElement('img');
		newImg.setAttribute('src', img_plus);
		newImg.onclick = clickExpandCollapse;
		uls[i].parentNode.insertBefore(newImg, uls[i])
		uls[i].className='collapsed'
	};
		// Create Expand/Collapse:All element
		var nElm = document.createElement('a');
		nElm.setAttribute('href', '#');
		nElm.setAttribute('id', String(root.id)+'_expcol');
		nElm.setAttribute((document.all ? 'className':'class'),'expandcollapse'); //IE class-bug
		nElm.onclick = function(){expandAll(String(root.id)+'_expcol',root.id);};
		nElm.innerHTML=txt_plus;
		root.parentNode.insertBefore(nElm, root)
}else{ 
// Add hover functionality-support for IE
	doHover = function(){
	var lis = root.getElementsByTagName("LI");
		for (var i=0; i<lis.length; i++){lis[i].onmouseover=function(){this.className+=" doHover";}
			lis[i].onmouseout=function(){this.className=this.className.replace(new RegExp(" doHover\\b"), "");}
		}
	}
if(window.attachEvent) window.attachEvent("onload", doHover);
}
if(setActivePage){
	
// Add click-event to all HREF-elements to set coookie with id of active page
	var as = root.getElementsByTagName('A');
	for (var i = 0; i < as.length; i++){
		if(as[i].className.indexOf("activelink")!=-1){menulevel = String(root.id)+'_a'+i;}
		as[i].id=String(root.id)+'_a'+i
		as[i].onclick = clickPageLink;}

// Get active page id from cookie
	if(menulevel!=null){menulevel=document.getElementById(menulevel)} else {menulevel= document.getElementById(getCookie(root.id))};
	if(menulevel!=null && menulevel!=''){
		menulevel.className='activepage'
		
		// If TreeView, expand all parentlevels
		if(root.className.indexOf("mn_tree")!=-1){
			if(menulevel.id!=root.id){	
				while(menulevel.id!=root.id){
					if(menulevel.tagName=='UL'){menulevel.className='expanded';menulevel.previousSibling.src=img_minus}
		    menulevel = menulevel.parentNode; }}}}}
	return true; 
}

function clickPageLink(){	
	var rootid = this.id.split("_")
	setCookie(rootid[0], this.id, 1) 
}

function collapseAll(aElm, root){
var uls = document.getElementById(root).getElementsByTagName('UL');
var aElm = document.getElementById(aElm)
for (var i = 0; i < uls.length; i++){
	uls[i].className='collapsed';
	uls[i].previousSibling.src=img_plus;}
	aElm.innerHTML=txt_plus; aElm.onclick= function(){expandAll(aElm.id, root);};	
}

function expandAll(aElm, root){
var uls = document.getElementById(root).getElementsByTagName('UL');
var aElm = document.getElementById(aElm)
for (var i = 0; i < uls.length; i++){
	uls[i].className='expanded';
	uls[i].previousSibling.src=img_minus;}
	aElm.innerHTML=txt_minus;	aElm.onclick = function(){collapseAll(aElm.id, root);};
}

function clickExpandCollapse(){
	if(this.nextSibling.className=='collapsed'){this.nextSibling.className='expanded';this.src=img_minus;}
	else {this.nextSibling.className='collapsed';this.src=img_plus;}
return false;	
}