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.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
}
var bw=new lib_bwcheck()

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 divFoldCont 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.
************************************************************************************/

//Here are the images for the top links.
clickedImg=new Image(); clickedImg.src="images/clicked.gif"		//The image for the closed state.
outImg=new Image(); outImg.src="images/out.gif"	                //The image for the open state.
overImg=new Image(); overImg.src="images/over.gif"
bkgClicked=new Image(); bkgClicked.src="images/bkg_clicked.gif"

mainmenus=8 //How many main menus do you have?

//How many submenus do you have beneath each main level.
submenus=new Array(0,0,2,0,0,0,0,0)
//In this example I have 3 submenus in the first top menu,
//3, in the second, 2 submenus in the third top menu and 3 in the forth.
//It's really important that these numbers are correct.

pxbetweenmain = 1 //How much space should there be between the main menus
pxbetweensub = 1 //How much space should there be between the sub menus

/************************************************************************************
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.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;
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

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=x; 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;
	
	for (var i=0; i<mainmenus; i++){
		oFold[i] = new makeMenu('divFold'+i,'divFoldCont');
		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;
		suby = oFold[i].height+pxbetweensub;
		for (var j=0; j<submenus[i]; j++){
			oFold[i].sub[j] = new makeMenu('divFoldSub'+i+'_'+j,'divFoldCont.document.divFold'+i);
			oFold[i].sub[j].hideIt();
			oFold[i].sub[j].moveIt(10,suby);
			suby += oFold[i].sub[j].height+pxbetweensub;
		}
	}
  	oFoldCont = new makeMenu('divFoldCont');
	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, num, subNum){
	if(show) {
		if(subNum == -1) this.ref["imgFold"+num].src = clickedImg.src
		else this.ref["imgFold"+num].src = outImg.src
	}

	for (var j=0; j<this.sub.length; j++){
		if (show){
			this.sub[j].showIt()
			if(subNum != -1 && subNum==j) this.sub[j].ref["imgFold"+num+"Sub"+j].src = clickedImg.src
			else this.sub[j].ref["imgFold"+num+"Sub"+j].src = outImg.src
		}else{
			this.sub[j].hideIt()
			this.ref["imgFold"+num].src = outImg.src
		}
	}
}
/************************************************************************************
Checking height of the menus, and moves them to the correct position.
************************************************************************************/
function checkheight(org,subNum){
	istart=0
	for(i=istart;i<oFold.length;i++){
		oFold[i].size=oFold[i].height
		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
			}
			if(j!=0) oFold[i].sub[j].moveIt(10,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 mainmenus
************************************************************************************/
function foldmenu(num,subNum){
	for(var i=0; i<oFold.length; i++){
		if(i!=num) oFold[i].subs(0,i,subNum)
	}

	var subStatus=1;
	if (oFold[num].sub[0] == undefined) subStatus=0;
	else subStatus=oFold[num].sub[0].status;

	if (!subStatus) oFold[num].subs(1,num,subNum)
	else oFold[num].subs(0,num)

	checkheight(num,subNum)
}
//Initiating the menus onload, if the browser is ok.
	//if(bw.bw) onload = foldInit;
function start(hasSub,main,sub){
	if(bw.bw) {
		foldInit();
		if(hasSub) {
			foldmenu(main,sub)
		}
	}
}
//Date related functions
function dispDate(dateVal) {
	DaystoAdd=dateVal
	TodaysDate = new Date();
	TodaysDay = new Array('Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday');
	TodaysMonth = new Array('January', 'February', 'March','April', 'May','June', 'July', 'August', 'September','October', 'November', 'December');
	DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
	function LeapYearTest (Year) {
		if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0)) {
			return true;
		}
		else {
			return false;
		}
	}
	CurrentYear = TodaysDate.getYear();
	if (CurrentYear < 2000) CurrentYear = CurrentYear + 1900;
	currentMonth = TodaysDate.getMonth();
	DayOffset = TodaysDate.getDay();
	currentDay = TodaysDate.getDate();
	month = TodaysMonth[currentMonth];
	if (month == 'February') {
		if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) {
			DaysinMonth[1] = 29;
		}
		else {
			DaysinMonth[1] = 28;
		}
	}
	days = DaysinMonth[currentMonth];
	currentDay += DaystoAdd;
	if (currentDay > days) {
		if (currentMonth == 11) {
			currentMonth = 0;
			month = TodaysMonth[currentMonth];
			CurrentYear = CurrentYear + 1
		}
		else {
			month = TodaysMonth[currentMonth+1];
		}
		currentDay = currentDay - days;
	}
	DayOffset += DaystoAdd;
	function offsettheDate (offsetCurrentDay) {
		if (offsetCurrentDay > 6) {
			offsetCurrentDay -= 6;
			DayOffset = TodaysDay[offsetCurrentDay-1];
			offsettheDate(offsetCurrentDay-1);
		}
		else {
			DayOffset = TodaysDay[offsetCurrentDay];
			return true;
		}
	}
	offsettheDate(DayOffset);TheDate  = DayOffset.substring(0,3) + ', ';
	TheDate += month + ' ';
	TheDate += currentDay + ', ';
	if (CurrentYear<100) CurrentYear="19" + CurrentYear;
	TheDate += CurrentYear;
	document.write(' '+TheDate);
}

//Mouse Events
function over(elem1_id, overBkgImage, elem2_id, elemHref)
{
	document.getElementById(elem1_id).style.background=overBkgImage;
	document.getElementById(elem2_id).src=overImg.src;
	document.getElementById(elemHref).style.color = "white";
}

function out(elem1_id, outBkgImage, elem2_id, elemHref)
{
	document.getElementById(elem1_id).style.background=outBkgImage;
	document.getElementById(elem2_id).src=outImg.src;
	document.getElementById(elemHref).style.color = "#000033";
}