
//.clFoldSub		{left:20px; width:270px; BACKGROUND: #ffffcc; text-indent: 1em;}
/**********************************************************************************   
FoldoutMenu2 
*   Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a>
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a> 
*********************************************************************************/

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=((this.ver.indexOf("MSIE 6")>-1 || this.ver.indexOf("MSIE 7")>-1) && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}


if(document.layers){ //NS4 resize fix...
	scrX= innerWidth; scrY= innerHeight;
	onresize= function(){if(scrX!= innerWidth || scrY!= innerHeight){history.go(0)} }
}

if(navigator.userAgent.indexOf('Opera')>-1 && document.getElementById){ //Opera 5 resize fix.
	scrX= innerWidth; scrY= innerHeight;
	document.onmousemove= function(){
		if(scrX<innerWidth-10 || scrY<innerHeight-10 || scrX>innerWidth+10 || scrY>innerHeight+10){
			scrX = innerWidth;
			scrY = innerHeight;
			foldInit();
		}
	};
}
/************************************************************************************
This is the new foldoutmenu, with more levels!
This is in some ways a rather advanced menu so please read every
note in this script and in the comments in the page to understand how
it works.

NOTE: if you change the position of dfCont from absolute to relative, 
you can put the menu in a table. HOWEVER it will no longer work in netscape 4.
If you wish to support netscape 4, you have to use absolute positioning.
************************************************************************************/

/************************************************************************************
Making cross-browser objects
************************************************************************************/
function makeMenu(obj,nest){
	nest=(!nest) ? "":'document.'+nest+'.';
   	this.css= bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;
	this.elm= bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
	this.ref= bw.dom || bw.ie4? document:bw.ns4?eval(nest+"document.layers." +obj+".document"):0;
	//this.x= bw.ns4?this.css.left:bw.opera5?this.css.pixelLeft:this.elm.offsetLeft;
	this.x= 0;
	this.y= bw.ns4?this.css.top:bw.opera5?this.css.pixelTop:this.elm.offsetTop;
	this.height= bw.ns4?this.ref.height:bw.opera5?this.css.pixelHeight:this.elm.offsetHeight;
	this.hideIt= b_hideIt;
	this.showIt= b_showIt;
	this.moveIt= b_moveIt;
	this.status= 0;
	return this;
}

function b_showIt(){this.css.visibility="visible"; this.status=1}
function b_hideIt(){this.css.visibility="hidden"; this.status=0}
function b_moveIt(x,y){this.x=0; this.y=y; /*this.css.left=this.x+px;*/ this.css.top=this.y+px;}
/************************************************************************************
Initiating the page and making the menu
************************************************************************************/
function foldInit(){
	//Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
	bw.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (bw.opera5) bw.ns6 = 0
	
	//Creating the foldoutmenu
	oFold = new Array();
	y = 0;
	pos = 0;
	for (var i=0; i<mainmenus; i++){
		oFold[i] = new makeMenu('df'+i,'dfCont');
		oFold[i].moveIt(0,y);
		oFold[i].size = oFold[i].height;
		y += oFold[i].height+pxbetweenmain;
		if (bw.ns4) oFold[i].css.clip.bottom = 500;
		oFold[i].sub = new Array();
		oFold[i].subs = top_subs;
		if(submenus[i]==0){
			oFold[i].lead = new makeMenu('dfs'+i+'_'+0,'dfCont.document.df'+i);
			oFold[i].lead.hideIt();
		}
		suby = oFold[i].height+pxbetweensub;
		for (var j=0; j<submenus[i]; j++){
			oFold[i].sub[j] = new makeMenu('dfs'+i+'_'+j,'dfCont.document.df'+i);
			oFold[i].sub[j].sub = new Array();
			oFold[i].sub[j].hideIt();
			oFold[i].sub[j].moveIt(0,suby);
			suby += oFold[i].sub[j].height+pxbetweensub;
			oFold[i].sub[j].subs = top_subs;
			//if(submenus2[pos]==0){
				oFold[i].sub[j].lead = new makeMenu('dfs'+ i +'_'+ j +'_'+ 0, 'dfCont.document.df'+i+'.document.dfs'+i+'_'+j);
				oFold[i].sub[j].lead.hideIt();
			//}
			sub2y = oFold[i].sub[j].height+pxbetweensub;
			/*
			for (var k=0; k<submenus2[pos]; k++){
				oFold[i].sub[j].sub[k] = new makeMenu('dfs'+ i +'_'+ j +'_'+ k, 'dfCont.document.df'+i+'.document.dfs'+i+'_'+j);
				oFold[i].sub[j].sub[k].sub = new Array();
				oFold[i].sub[j].sub[k].hideIt();
				oFold[i].sub[j].sub[k].moveIt(0,sub2y);
				sub2y += oFold[i].sub[j].sub[k].height+pxbetweensub;
				oFold[i].sub[j].sub[k].subs = top_subs;
				oFold[i].sub[j].sub[k].lead = new makeMenu('dfs'+ i +'_'+ j +'_'+k+'_'+ 0, 'dfCont.document.df'+i+'.document.dfs'+i+'_'+j+'.document.dfs'+i+'_'+j+'_'+k);
				oFold[i].sub[j].sub[k].lead.hideIt();
			}
			*/
			pos++;
		}
	}
  	oFoldCont = new makeMenu('dfCont');
	if (bw.ns4) oFoldCont.css.clip.bottom = 800;
  	oFoldCont.showIt(); //Showing the menu when the menu have been "created"
}
/************************************************************************************
Object function to the top of the menus.
************************************************************************************/
function top_subs(show, sImg){
	if(show){
		if (foldImg && this.sub.length>0) this.ref[sImg].src = foldoutImg.src
	}
	else{
		if (foldImg && this.sub.length>0) this.ref[sImg].src = foldinImg.src
	}
	if(this.sub.length==0){
		if(show){
			if (foldImg && this.lead.height>0) this.ref[sImg].src = foldoutImg.src
			this.lead.showIt();
		}
		else{
			if (foldImg && this.lead.height>0) this.ref[sImg].src = foldinImg.src
			//alert(this.lead.height+' '+this.lead.elm.id);
			this.lead.hideIt();
		}
	}
	else{
		for(var j=0; j<this.sub.length; j++){
			if(show){
				this.sub[j].showIt()
				if(this.sub[j].sub.length==0){
					if (substayfolded){
						if(this.sub[j].lead.status) this.sub[j].lead.showIt()
					}
					else{
						this.sub[j].lead.hideIt()
					}
				}
			}
			else{
				this.sub[j].hideIt()
				if(this.sub[j].sub.length==0){
					if (!substayfolded) this.sub[j].lead.hideIt()
					else if (substayfolded) this.sub[j].lead.css.visibility="hidden"
				}
			}
			this.sub[j].subs(0, sImg+'_'+j)
		}
	}
}
/************************************************************************************
Checking height of the menus, and moves them to the correct position.
************************************************************************************/
function checkheight(org){
	if(mainstayfolded) istart=org; else istart=0
	for(i=istart;i<oFold.length;i++){
		oFold[i].size=oFold[i].height
		// El nodo es una hoja
		if(oFold[i].sub.length==0 && oFold[i].lead.status){
			oFold[i].size +=oFold[i].lead.height +pxbetweensub
		}
		for(j=0;j<oFold[i].sub.length;j++){
			oFold[i].sub[j].size=oFold[i].sub[j].height +pxbetweensub
			if(oFold[i].sub[j].status){
				oFold[i].size+=oFold[i].sub[j].size
				// El nodo es una hoja
				if(oFold[i].sub[j].sub.length==0 && oFold[i].sub[j].lead.status){
					oFold[i].size +=oFold[i].sub[j].lead.height +pxbetweensub
					oFold[i].sub[j].size+=oFold[i].sub[j].lead.height +pxbetweensub
				}
				for(k=0; k<oFold[i].sub[j].sub.length; k++){
					oFold[i].sub[j].sub[k].size=oFold[i].sub[j].sub[k].height +pxbetweensub
					if(oFold[i].sub[j].sub[k].status){
						oFold[i].size+=oFold[i].sub[j].sub[k].height+pxbetweensub
						oFold[i].sub[j].size+=oFold[i].sub[j].sub[k].height +pxbetweensub
						// El nodo es una hoja
						if(oFold[i].sub[j].sub[k].sub.length==0 && oFold[i].sub[j].sub[k].lead.status){
							oFold[i].size +=oFold[i].sub[j].sub[k].lead.height +pxbetweensub
							oFold[i].sub[j].size +=oFold[i].sub[j].sub[k].lead.height +pxbetweensub
							oFold[i].sub[j].sub[k].size +=oFold[i].sub[j].sub[k].lead.height +pxbetweensub
						}
					}
					if(k>0) oFold[i].sub[j].sub[k].moveIt(0,oFold[i].sub[j].sub[k-1].y+oFold[i].sub[j].sub[k-1].size)
				}
			}
			if(j>0) oFold[i].sub[j].moveIt(0,oFold[i].sub[j-1].y+oFold[i].sub[j-1].size)
		}
		if(i>0) oFold[i].moveIt(0,oFold[i-1].y+oFold[i-1].size+pxbetweenmain)
	}
}
/************************************************************************************
Fold in and out the submenus of nivel 2.
************************************************************************************/
function subfoldmenu2(main, sub, sub2){
	if(oFold){
		if (!substayfolded){
			for (var i=0; i<oFold[main].sub[sub].sub.length; i++){
				if (i!=sub2){
					oFold[main].sub[sub].sub[i].subs(0, "if"+main+'_'+sub+'_'+i)
				}
			}
		}
		// verifico si el nodo es hoja
		if(oFold[main].sub[sub].sub[sub2].sub.length==0){
			if(!oFold[main].sub[sub].sub[sub2].lead.status){
				oFold[main].sub[sub].sub[sub2].lead.showIt()
				if(foldImg) oFold[main].sub[sub].sub[sub2].ref["if"+main+'_'+sub+'_'+sub2].src = foldsuboutImg.src
			}
			else{
				oFold[main].sub[sub].sub[sub2].lead.hideIt()
				if(foldImg) oFold[main].sub[sub].sub[sub2].ref["if"+main+'_'+sub+'_'+sub2].src = foldsubinImg.src
			}
		}
		for (var i=0; i<oFold[main].sub[sub].sub[sub2].sub.length; i++){
			if (!oFold[main].sub[sub].sub[sub2].sub[i].status){
				oFold[main].sub[sub].sub[sub2].sub[i].showIt()
				if(foldImg){
					if(oFold[main].sub[sub].sub[sub2].sub[i].sub.length>0){
						oFold[main].sub[sub].sub[sub2].ref["if"+main+'_'+sub+'_'+sub2].src = foldsuboutImg.src
					}
					else if(oFold[main].sub[sub].sub[sub2].sub[i].lead.height>0){
						oFold[main].sub[sub].sub[sub2].ref["if"+main+'_'+sub+'_'+sub2].src = foldsuboutImg.src
					}
				}
			}
		}
		checkheight(main)
	}
}
/************************************************************************************
Fold in and out the submenus.
************************************************************************************/
function subfoldmenu(main,sub){
	if(oFold){
		if (!substayfolded){
			for (var i=0; i<oFold[main].sub.length; i++){
				if (i!=sub){
					oFold[main].sub[i].subs(0, "if"+main+'_'+i)
				}
			}
		}
		// verifico si el nodo es hoja
		if(oFold[main].sub[sub].sub.length==0){
			if(!oFold[main].sub[sub].lead.status){
				oFold[main].sub[sub].lead.showIt()
				if(foldImg) oFold[main].sub[sub].ref["if"+main+'_'+sub].src = foldsuboutImg.src
			}
			else{
				oFold[main].sub[sub].lead.hideIt()
				if(foldImg) oFold[main].sub[sub].ref["if"+main+'_'+sub].src = foldsubinImg.src
			}
		}
		else if(oFold[main].sub[sub].sub[0].status){
			oFold[main].sub[sub].subs(0, "if"+main+'_'+sub)
		}
		else{
			for (var i=0; i<oFold[main].sub[sub].sub.length; i++){
				if (!oFold[main].sub[sub].sub[i].status){
					oFold[main].sub[sub].sub[i].showIt()
					if(foldImg) oFold[main].sub[sub].ref["if"+main+'_'+sub].src = foldsuboutImg.src
				}
			}
		}
		checkheight(main)
	}
}
/************************************************************************************
Fold in and out the mainmenus
************************************************************************************/
function foldmenu(num){
	if(oFold){
		if (!mainstayfolded){
			for(var i=0; i<oFold.length; i++){
				if(i!=num){
					oFold[i].status = 0
					oFold[i].subs(0,"if"+i)
				}
			}
		}
		if (!oFold[num].status){
			oFold[num].status=1
			oFold[num].subs(1,"if"+num)
		}
		else{
			oFold[num].status=0
			oFold[num].subs(0,"if"+num)
		}
		checkheight(num)
	}
}


