/********************************************************************************
Modified for NS6 compatibility - Michael Feb 2001
********************************************************************************/
/********************************************************************************
Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/

/*** variables you can configure ***/

FoldNumber=8                    //How many toplinks do you have?
var stayFolded=false            //Stay open when you click a new toplink?
foldImg=1                       //Do you want images (if not set to 0 and remove the images from the body)?

//This is the default image.
//Remember to change the actual images in the page as well, but remember to keep the name of the image.
var unImg=new Image();
unImg.src='images/arrow.gif'

var exImg=new Image();          //Making an image variable...
exImg.src='images/arrow1.gif'   //...this is the source of the image that it changes to when the menu expands.



/*** There should be no need to change anything beyond this. ***/


//browsercheck...
function checkBrowser(){
    this.opera= (navigator.userAgent.indexOf('Opera')>-1);
	this.ie4= (document.all && !document.getElementById);
	this.ie5= (document.all && document.getElementById && !this.opera);
	this.ns4= (document.layers && !document.getElementById);
	this.ns6= (!document.all && document.getElementById && !this.opera);
    this.mac= (navigator.userAgent.indexOf('Mac')>-1);
	this.bw= (this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera)
	return this
}
bw= new checkBrowser()

//object constructor...
function makeMenu(obj,nest){
	nest= (!nest)?'':'document.'+nest+'.';
	this.el= bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):document.getElementById(obj);	
   	this.css= bw.ns4?this.el:this.el.style;
	this.ref= bw.ns4?this.el.document:document;		
	this.x= (bw.ns4||bw.opera)?this.css.left:this.el.offsetLeft;
	this.y= (bw.ns4||bw.opera)?this.css.top:this.el.offsetTop;
	this.height= (bw.ie4||bw.ie5||bw.ns6)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.opera?this.css.pixelHeight:0;
    this.vis= b_vis;
	this.hideIt= b_hideIt;
    this.showIt= b_showIt;
    this.moveIt= b_moveIt;
	return this
}
//object methods...
function b_showIt(){this.css.visibility='visible'}
function b_hideIt(){this.css.visibility='hidden'}
function b_vis(){if(this.css.visibility=='hidden' || this.css.visibility=='hide') return true;}
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x; this.css.top=this.y}

/************************************************************************************
This is the function that changes the sub menus to folded or unfolded state.
************************************************************************************/
function menu(num){
	if(bw.bw){
		if(!stayFolded){
			for(i=0;i<oSub.length;i++){
				if(i!=num){
					oSub[i].hideIt()
					if(foldImg)oTop[i].ref["imgA"+i].src=unImg.src
				}
			}
			for(i=1;i<oTop.length;i++){
				oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
			}
		}
		if(oSub[num].vis()){
			oSub[num].showIt()
			if(foldImg)oTop[num].ref["imgA"+num].src=exImg.src
		}else{
			oSub[num].hideIt()
			if(foldImg)oTop[num].ref["imgA"+num].src=unImg.src
		}
		for(i=1;i<oTop.length;i++){ 
			if(!oSub[i-1].vis()) oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height+oSub[i-1].height) 
			else oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
		}
	}
}

/*********************************************************************
The init function... there should be no need to change anything here.
*********************************************************************/
function initFoldout(){

    //Making the object arrays...
	oTop= new Array()
	oSub= new Array()

    //Making the objects and hiding the subs...
    for(var i=1;i<=FoldNumber;i++){
        oTop[i-1]= new makeMenu('divTop'+i,'divCont')
        oSub[i-1]= new makeMenu('divSub'+i,'divCont.document.divTop'+i)
        oSub[i-1].hideIt()
    }

    //Positioning the top objects...
    oTop[0].moveIt(0,0)
	for(var i=1;i<oTop.length;i++){ oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height) }

    //Making the containing menu object and showing it...
  	oCont= new makeMenu('divCont')
	
	if(!bw.ns4) onresize= function(){setTimeout('positionAll()',100)}
  	oCont.showIt()
}

//If the browser is ok, the script is started onload...
