var active_menu      = 0;
var active_menu_disp = 0;
var active_nav_id    = 0;
var active_nav_name  = '';

var IE50 = (navigator.appVersion.indexOf('MSIE 5.0')>-1 ? true : false);

function lib_bwcheck()
{
	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.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie8=(this.ver.indexOf("MSIE 8")>-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.ie7||this.ie8
	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.ie7 || this.ie8 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

// FoldNumber = 9
var stayFolded = true
foldImg = 1
mainOffsetY = 0
menuHeight = 330

var unImg=new Image();
unImg.src='/Images/plus.gif'

var exImg=new Image();
exImg.src='/Images/minus.gif'


var px = bw.ns4||window.opera?"":"px";

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;
			initFoldout();
		}
	};
}


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.opera5)?this.css.left:this.el.offsetLeft;
	this.y= (bw.ns4||bw.opera5)?this.css.top:this.el.offsetTop;
	this.h= (bw.ie||bw.ns6)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.opera5?this.css.pixelHeight:29;
    this.vis= b_vis;
	this.hideIt= b_hideIt;
    this.showIt= b_showIt;
    this.moveIt= b_moveIt;
	return this;
}


function makeObj(obj)
{
	this.el= bw.ie4?document.all[obj]:bw.ns4?eval('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.opera5)?this.css.left:this.el.offsetLeft;
	this.y= (bw.ns4||bw.opera5)?this.css.top:this.el.offsetTop;
	this.h= (bw.ie||bw.ns6)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.opera5?this.css.pixelHeight:0;
	this.height= (bw.ie||bw.ns6)?this.el.style.height:bw.ns4?this.el.style.height:bw.opera5?this.el.style.height:0;
    this.vis= b_vis;
	this.hideIt= b_hideIt;
    this.showIt= b_showIt;
    this.moveIt= b_moveIt;
	return this;
}

function b_showIt(){this.css.visibility='visible';this.css.display='block';}
function b_hideIt(){this.css.visibility='hidden';this.css.display='none';}
function b_vis(){if(this.css.visibility=='hidden' || 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+px;
		this.css.top=this.y+px;
}

function menu(num)
{
	var cont  = document.getElementById('left-content');

	
	if( bw.bw )
	{
		if( !stayFolded )
		{
			for( var i=0 ; i<oSub.length ; i++ )
			{
				if( i!=num )
				{
					oSub[i].hideIt();

					if( foldImg ) oTop[i].ref["imgA"+i].src = unImg.src;
				}
			}

			for( var i=1 ; i<oTop.length ; i++ )
			{
				oTop[i].moveIt( 0, oTop[i-1].y+oTop[i-1].h );
			}
		}

		if( oSub[num].vis() )
		{
			// OPEN A SUBMENU
/*
			if( cont!=null )
			{
				cont.style.height = (menuHeight + oSub[num].h) + px;
			}
*/

			oSub[num].showIt();

			if( foldImg ) oTop[num].ref["imgA"+num].src = exImg.src;
		} else {
			// CLOSE A SUBMENU
/*
			if( cont!=null )
			{
				cont.style.height = (menuHeight - oSub[num].h) + px;
			}
*/

			oSub[num].hideIt();

			if( foldImg ) oTop[num].ref["imgA"+num].src = unImg.src;
		}

		// Move all the menu items to account for the newly expanded one.
		var sum;
		sum = mainOffsetY

		for( var i=1 ; i<oTop.length ; i++ )
		{
			sum += oTop[i-1].h + (!oSub[i-1].vis() ? oSub[i-1].h : 0);
			oTop[i].moveIt(0, sum)
		}

		// Add the last menu item height to the total.
		sum += oTop[i-1].h + (!oSub[i-1].vis() ? oSub[i-1].h : 0);

		// Resize the cell holding the menu.  This is so we can ensure
		// there is enough space for the menu to be displayed without
		// overlapping anything.
		cont.style.height = sum + 'px';
	}
	else{
		/////////////////////////////////////
		// SC - if we're here then bw object not created
		// Ensure that the browser is detected correctly in lib_bwcheck() above
		alert("Sorry, unsupported browser");
	}
}


function initFoldout()
{
	bw.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false;
	if (bw.opera5) bw.ns6 = 0;

	oTop = new Array();
	oSub = new Array();

	for( var i=0 ; i<FoldNumber ; i++ )
	{
		oTop[i] = new makeMenu('divTop'+i,'divCont');
		oSub[i] = new makeMenu('divSub'+i,'divCont.document.divTop'+i);
		oSub[i].hideIt();
	}

	oTop[0].moveIt(0,0);

	// Move all the menu items to be correctly spaced
	// Show each one after it is positioned.
	var sum;
	sum = mainOffsetY;

	// First one doesn't need moving.
	oTop[0].showIt();

	for( var i=1 ; i<oTop.length ; i++ )
	{
		sum += oTop[i-1].h;
		oTop[i].moveIt(0, sum);
		oTop[i].showIt();
	}

	// Add the last menu item height to the total.
	sum += oTop[i-1].h;

	var cont = document.getElementById('left-content');
	cont.style.height = sum + 'px';

	// Show the content layer.
	oCont = new makeMenu('divCont');
	oCont.showIt();
}
