/********************************************************************************
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!
********************************************************************************/

/********************************************************************************
Making cross-browser objects
********************************************************************************/
function makeObj(obj, nest) {
	if (!bw)
		bw = new checkBrowser();

	nest = (!nest) ? '':'document.'+nest+'.';
	this.el = bw.dom ? document.getElementById(obj) : bw.ie4 ? document.all[obj] : bw.ns4 ? eval(nest+'document.'+obj) : 0;
	this.css = bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? eval(nest+'document.'+obj) : 0;
	this.ref = bw.ns4 ? eval(nest+'document.'+obj+'.document') : eval('document');

//this.height = bw.ns4 ? this.ref.height : eval(obj+'.offsetHeight');
//this.width = bw.ns4 ? this.ref.width : eval(obj+'.offsetWidth');
	this.height = bw.dom ? this.el.offsetHeight : bw.ie4 ? eval(obj+'.offsetHeight') : bw.ns4 ? this.ref.height : 0;
	this.width = bw.dom ? this.el.offsetWidth : bw.ie4 ? eval(obj+'.offsetWidth') : bw.ns4 ? this.ref.width : 0;
//this.x = bw.ns4 ? this.css.left : this.css.pixelLeft;
//this.y = bw.ns4 ? this.css.top : this.css.pixelTop;
	this.x = bw.dom ? this.css.left : bw.ie4 ? this.css.pixelLeft : bw.ns4 ? this.css.left : 0;
	if (!this.x)
		this.x = 0;
	else
		this.x = parseInt(this.x);
	this.y = bw.dom ? this.css.top : bw.ie4 ? this.css.pixelTop : bw.ns4 ? this.css.top : 0;
	if (!this.y)
		this.y = 0;
	else
		this.y = parseInt(this.y);
//alert('this.height: '+this.height);
//alert('this.width: '+this.width);
//alert('this.x: '+this.x);
//alert('this.y: '+this.y);

	this.hideIt=b_hideIt;
	this.showIt=b_showIt;
	this.vis=b_vis;
	this.moveIt=b_moveIt;

	this.obj = obj+"Object";
	eval(this.obj+"=this");
	return this;
}

function b_showIt() { this.css.visibility = bw.ns4 ? 'show' : 'visible'; }
function b_hideIt() { this.css.visibility = bw.ns4 ? 'hide' : 'hidden'; }
function b_vis() { return ((this.css.visibility!=((bw.ns4) ? 'hide' : 'hidden'))) ? true : false; }
function b_moveIt(x,y) { this.x=x; this.y=y; this.css.left=this.x; this.css.top=this.y }

/************************************************************************************
Initiating the page. Just add to the arrays here to get more menuitems
and add divs in the page
************************************************************************************/
var blnFirstTime = true;
var iMenuTimeOut = 1000;

var iTimeoutID = 0;

var active = false;
var active2 = false;
var active3 = false;

var activeNr = -1;
var activeNr2 = -1;
var activeNr3 = -1;

/************************************************************************************
This is the function that changes the sub menus to folded or unfolded state.
************************************************************************************/

function checkActive() {
	iTimeoutID = 0;

	if(!active3) {
		if (activeNr3 != -1)
			hideMenu3(activeNr, activeNr2);
			active3 = false;
	}

	if(!active2) {
		if (activeNr2 != -1)
			hideMenu2(activeNr);
			active2 = false;
	}

	if(!active) {
		if (activeNr != -1)
			hideMenu(activeNr);
			active1 = false;
	}
}

/* 1st level menu functions */
function overMenu(num) {
	if(!bw.bw)
		return;

    if(blnFirstTime)
        initmenu();

    if( !aMenu[num])
		return;

	if (iTimeoutID > 0) {
		clearTimeout(iTimeoutID);
		iTimeoutID = 0;
	}

	// !1 - the same logic
	if(num!=activeNr) {
		hideMenu(activeNr);
	}

	active = true;
	activeNr = num;

	aMenu[num][1].showIt();
	aMenu[num][0].hideIt();

	showAll2(num);
}

function outMenu(num) {
	if( !aMenu[num])
		return;

	if (iTimeoutID > 0) {
		clearTimeout(iTimeoutID);
		iTimeoutID = 0;
	}

	active = false;
	iTimeoutID = setTimeout("checkActive()", iMenuTimeOut);
}

function hideMenu(num) {
	if( !aMenu[num])
		return;

	hideMenu2(num);
	
	aMenu[num][0].showIt();
	aMenu[num][1].hideIt();
}


/* 2nd level menu functions */
function overMenu2(num, num2) {
    if(!aMenu2[0][num] || (!aMenu2[0][num][num2]))
		return;

	if (iTimeoutID > 0) {
		clearTimeout(iTimeoutID);
		iTimeoutID = 0;
	}

	// !1 - the same logic
	if(num2!=activeNr2)
		changeMenu2(activeNr, activeNr2, false);

	active2 = true;
	activeNr2 = num2;

	changeMenu2(activeNr, activeNr2, true);
}

function outMenu2(num, num2) {
	if(!aMenu2[0][num] && (!aMenu2[0][num][num2]))
		return;

	if (iTimeoutID > 0) {
		clearTimeout(iTimeoutID);
		iTimeoutID = 0;
	}

	active2 = false;
	iTimeoutID = setTimeout("checkActive()", iMenuTimeOut);
}

function showAll2(num) {
	if( !aMenu2[0][num])
		return;

	if (bw.ns4)	//workaround for NS4 bugi
		aMenu2[1][num][0].showIt();

	for(i=0;i<aMenu2[0][num].length;i++) {
		aMenu2[0][num][i].showIt();
	}
}

function hideMenu2(num) {
	if( !aMenu2[0][num])
		return;

	for(var i=0; i<aMenu2.length; i++) {
		for(var j=0; j<aMenu2[i][num].length; j++) {
			hideMenu3(num, j);
			aMenu2[i][num][j].hideIt();
		}
	}
}

function changeMenu2(num, num2, pbActivate) {
	if(!aMenu2[0][num] || (!aMenu2[0][num][num2]))
		return;
	var iInd1 = (pbActivate) ? 1 : 0;
	var iInd2 = (pbActivate) ? 0 : 1;
	aMenu2[iInd1][num][num2].showIt();
	aMenu2[iInd2][num][num2].hideIt();
	
	if (pbActivate) {
		showAll3(num, num2);
	}
	else {
		hideMenu3(num, num2);
	}

}

/* 3rd level menu functions */
function overMenu3(num, num2, num3) {
    if(!aMenu3[0][num] || (!aMenu3[0][num][num2]) || (!aMenu3[0][num][num2][num3]))
		return;

	if (iTimeoutID > 0) {
		clearTimeout(iTimeoutID);
		iTimeoutID = 0;
	}

	// !1 - the same logic
	if(num3!=activeNr3)
		changeMenu3(activeNr, activeNr2, activeNr3, false);

	active3 = true;
	activeNr3 = num3;

	changeMenu3(activeNr, activeNr2, activeNr3, true);
}

function outMenu3(num, num2, num3) {
    if(!aMenu3[0][num] || (!aMenu3[0][num][num2]) || (!aMenu3[0][num][num2][num3]))
		return;

	if (iTimeoutID > 0) {
		clearTimeout(iTimeoutID);
		iTimeoutID = 0;
	}

	active3 = false;
	iTimeoutID = setTimeout("checkActive()", iMenuTimeOut);
}

function changeMenu3(num, num2, num3, pbActivate) {
    if(!aMenu3[0][num] || (!aMenu3[0][num][num2]) || (!aMenu3[0][num][num2][num3]))
		return;
	var iInd1 = (pbActivate) ? 1 : 0;
	var iInd2 = (pbActivate) ? 0 : 1;
	aMenu3[iInd1][num][num2][num3].showIt();
	aMenu3[iInd2][num][num2][num3].hideIt();
}

function showAll3(num, num2) {
	if(!aMenu3[0][num] || (!aMenu3[0][num][num2]))
		return;

	if (bw.ns4)	//workaround for NS4 bugi
		aMenu3[1][num][num2][0].showIt();

	for(i=0;i<aMenu3[0][num][num2].length;i++) {
		aMenu3[0][num][num2][i].showIt();
	}
}

function hideMenu3(num, num2) {
	if(!aMenu3[0][num] || (!aMenu3[0][num][num2]))
		return;

	for(i=0;i<aMenu3.length;i++) {
		for(j=0;j<aMenu3[i][num][num2].length;j++) {
			aMenu3[i][num][num2][j].hideIt();
		}
	}
}

function window_resize() {
	if(!blnFirstTime)
		document.location.reload(false);
}

//Initiating the menus onload, if it's a 4.x+ browser.
if(bw.bw) {
	//onload=initmenu;
	onresize=window_resize;
}
