
var isNav4, isNav6, isIE4, isMac;
function setBrowser(){
	if ( navigator.appVersion.charAt( 0 ) == "4" ){
		if ( navigator.appName.indexOf( "Explorer" ) >= 0 ){
			isIE4 = true;
		}
		else{
			isNav4 = true;
		}
	}
	else if ( navigator.appVersion.charAt( 0 )>"4" ){
		isNav6 = true;
	}
// following code from browser sniffer from webreference.com
	var agt = navigator.userAgent.toLowerCase();
	isMac = ( agt.indexOf( "mac" ) !=  - 1 );
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------


var memory = false;
var memory2 = false;
var menuDiv;

function subMenu( src ){
	actionMenu( src );
	memory = src.parentNode.id;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function actionMenu( src ){
	var menuWrapper = window.document.getElementById( "menuWrapper" );
	var linkList = menuWrapper.getElementsByTagName( "A" );
	for ( var i = 0; i<linkList.length; i ++ ){

		if ( linkList[i].parentNode.id && linkList[i].parentNode.id.length>0 && linkList[i].parentNode.id != src.parentNode.id ){
			closeMenu( linkList[i] );
		}
		else if ( linkList[i].parentNode.id && linkList[i].parentNode.id.length>0 && linkList[i].parentNode.id == src.parentNode.id ){
			openMenu( linkList[i] );
		}
	}
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function closeAll(){
	var menuWrapper = window.document.getElementById( "menuWrapper" );
	var linkList = menuWrapper.getElementsByTagName( "A" );
	for ( var i = 0; i<linkList.length; i ++ ){

		if ( linkList[i].parentNode.id && linkList[i].parentNode.id.length>0 ){
			closeMenu( linkList[i] );
		}
	}
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function closeMenu( src ){
	var background = "#7A98BE";
	var subDisplay = "none";
	var colour = "#FFFFFF";
	var subMenu = src.parentNode.childNodes[2];
	src.parentNode.style.backgroundColor = background;
	src.style.color = colour;
	if ( subMenu ){
		subMenu.style.display = subDisplay;
	}
	memory = false;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function openMenu( src ){
	var background = "#B9D6E8";
	var subDisplay = "block";
	var colour = "#5B7896";
	var subMenu = src.parentNode.childNodes[2];
	src.parentNode.style.backgroundColor = background;
	src.style.color = colour;
	if ( subMenu ){
		subMenu.style.display = subDisplay;
	}
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function menuDivOut( evt ){
	if ( isIE4 ){
		if ( window.event.fromElement.nodeName != "DIV" ){
			return false;
		}
	}
	else if ( isNav6 ){
		var fail = true;
//var mystring="target node = "+evt.target.nodeName+"\n related target ="+evt.relatedTarget.nodeName;
		if ( evt.target.nodeName == "DIV" && ( evt.relatedTarget.nodeName == "DIV" || evt.relatedTarget.nodeName == "H2" || evt.relatedTarget.nodeName == "BODY" ) ){
			fail = false;
		}if ( fail ){
			return false;
		}
	}
	var tmp;
	if ( memory2 ){
		tmp = window.document.getElementById( memory2 ).firstChild;
	}if ( tmp ){
		actionMenu( tmp );
	}
	else{
		closeAll();
	}
	return true;

}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function menuDivOver( evt ){

	if ( isIE4 ){
		if ( window.event && window.event.fromElement ){
			var srcType = window.event.fromElement.nodeName;
		}if ( !srcType ){
			return false;
		}if ( srcType == "A" || srcType == "LI" || srcType == "UL" ){
			return false;
		}
	}
	else if ( isNav6 ){
		var fail = true;
		if ( !evt.relatedTarget ){
			return false;
		}
//var mystring="target node = "+evt.target.nodeName+"\n related target ="+evt.relatedTarget.nodeName;
//alert(mystring);
		if ( evt.target.nodeName == "DIV" && ( evt.relatedTarget.nodeName == "DIV" || evt.relatedTarget.nodeName == "H2" || evt.relatedTarget.nodeName == "BODY" ) ){
			fail = false;
		}if ( fail ){
			return false;
		}
	}
	if ( memory ){
		closeMenu( window.document.getElementById( memory ).firstChild );
	}
	if ( memory2 ){
		var tmp = window.document.getElementById( memory2 ).firstChild;
	}
	else{
		return false;
	}
//if (tmp) openMenu(tmp);
	if ( tmp ){
		actionMenu( tmp );
	}
	memory = memory2;
	return true;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------



function prepMenu(){
	menuDiv = window.document.getElementById( "menuWrapper" );
	if ( isIE4 ){
		if ( isMac ){
			menuDiv.onmouseout = menuDivOut;
			menuDiv.onmouseover = menuDivOver;
		}
		else{
			menuDiv.attachEvent( "onmouseout", menuDivOut );
			menuDiv.attachEvent( "onmouseover", menuDivOver );
		}
	}
	else if ( isNav6 ){
		menuDiv.addEventListener( "mouseout", menuDivOut, false );
		menuDiv.addEventListener( "mouseover", menuDivOver, false );
	}
	var linkList = menuDiv.getElementsByTagName( "A" );
	for ( var i = 0; i<linkList.length; i ++ ){
		if ( linkList[i].parentNode.className=="active" ){
			var parentMenu = findNode( linkList[i].parentNode, "LI", "up" );
			if ( parentMenu ){
				//parentMenu.className="";
				openMenu( parentMenu.firstChild );
				memory = memory2 = parentMenu.id;
				linkList[i].parentNode.className = "active";
			}
			else{
				//linkList[i].parentNode.className="";
				openMenu( linkList[i] );
				memory = memory2 = linkList[i].parentNode.id;
			}
			return ;
		}
	}
}

/* page scrolling */
var debug;
var Yrange, contentDiv, scrollDiv, scrollFunc;
var scrollY = 10; //scroll increment
var Ycounter = 0; //vertical scroll distance
var scrollInterval = 90; //time (ms) between increments
var scrollBottomMargin = 5; //bottom margin in pixels
function scroller( src ){
	var srcLi = src.parentNode;
	var d,scroll1;
	while ( srcLi.nodeName != "LI" ){
		if ( srcLi.nodeName == "BODY" ){
			alert( "Major error!" );
			return false;
		}
	}
	if ( srcLi.id == "leftDown" || srcLi.id == "rightDown" ){
		scrollUp();
		scroll1 = window.setTimeout( "scrollUp()", parseInt( scrollInterval / 2 ) );
		scrollFunc = window.setInterval( "scrollUp()", scrollInterval );
		d = window.document.getElementById( "leftUp" );
		d.className = "";
	}
	else if ( srcLi.id == "leftUp" || srcLi.id == "rightUp" ){
		scrollDown();
		scroll1 = window.setTimeout( "scrollDown()", parseInt( scrollInterval / 2 ) );
		scrollFunc = window.setInterval( "scrollDown()", scrollInterval );
		d = window.document.getElementById( "leftDown" );
		d.className = "";
	}
	return true;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function configScroll(){
	contentDiv = window.document.getElementById( "leftContent" );
	scrollDiv = contentDiv.firstChild;
	var leftScrollControls;
	if ( scrollDiv.nodeName != "DIV" ){
		scrollDiv = scrollDiv.nextSibling;
	}if ( scrollDiv.nodeName != "DIV" ){
		scrollDiv = scrollDiv.nextSibling;
	}Yrange = contentDiv.clientHeight - contentDiv.scrollHeight - scrollBottomMargin;
	if ( Yrange> - 15 ){
		leftScrollControls = window.document.getElementById( "leftScrollControls" );
		leftScrollControls.style.display = "none";
		leftScrollUpControls = window.document.getElementById( "pageUp" );
		if ( leftScrollUpControls ){
			leftScrollUpControls.style.display = "none";
		}
	}
	else
	{ //actively revealing controls if JS is on
		leftScrollControls = window.document.getElementById( "leftScrollControls" );
		leftScrollControls.style.display = "block";
		var leftScrollUpControls = window.document.getElementById( "pageUp" );
		leftScrollUpControls.style.display = "block";
		contentDiv.style.overflow = "hidden";
		var shortCutLink = document.getElementById( "pageUp" );
		shortCutLink.style.visibility = "visible";
	}
//debug=window.document.getElementById("debug");
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function scrollUp(){
	if ( Ycounter>Yrange ){
		Ycounter = Ycounter - scrollY;
		scrollDiv.style.marginTop = Ycounter + "px";
	}
	else{
		window.clearInterval( scrollFunc );
		var d = window.document.getElementById( "leftDown" );
		d.className = "off";
	}

}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function scrollDown(){
	if ( contentDiv.scrollTop ){
		if ( contentDiv.scrollTop>0 ){
			contentDiv.scrollTop = 0;
		}
	}
	if ( Ycounter<0 ){
		Ycounter = Ycounter + scrollY;
		scrollDiv.style.marginTop = Ycounter + "px";
	}
	else{
		window.clearInterval( scrollFunc );
		var d = window.document.getElementById( "leftUp" );
		d.className = "off";
	}

}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function getTopMargin( obj ){
	var x = obj.style.marginTop;
	x = x.replace(/px/,"");
	x = x.replace(/\s/g,"");
	x = parseInt( x );
	return x;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------



function scrollStop(){
	window.clearInterval( scrollFunc );
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function topContent(){
	scrollDiv.style.marginTop = 0;
	Ycounter = 0;
	if ( contentDiv.scrollTop ){
		if ( contentDiv.scrollTop>0 ){
			contentDiv.scrollTop = 0;
		}
	}
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

function findNode( obj, tag, dir ){
	do{
		if ( dir == "up" ){
			obj = obj.parentNode;
		}if ( dir == "down" ){
			obj = obj.firstChild;
		}if ( !obj.nodeName || obj.nodeName == "BODY" ){
			return false;
		}
	}
	while ( obj.nodeName != tag );
	return obj;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

var newpopup;
function popupWindow( src ){
//newWin = window.open(launchString);
	newpopup = window.open( src.href, "popupWindow", "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=450,height=500, left=100, top=120" );
	newpopup.focus();
	return false;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

var newWin;
function newWindow( src ){
//newWin = window.open(launchString);
	newWin = window.open( src.href, "popupWindow" );
	newWin.focus();
	return false;
}

//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------

var printwin;

function printWindow( src ){
	printwin = window.open( src.href, "popupWindow", "toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=0,width=800,height=600, left=20, top=20" );
	printwin.focus();
	return false;
}
