//Utilityfunctions
// browser detection
var agent = navigator.userAgent.toLowerCase();
var opera = agent.indexOf("opera") != -1 ? true : false;
function getId ( element ) { // return object reference
		if ( document.layers ) { // one nesting deep
			if ( document.layers[element] ) return document.layers [ element ];
			else { var i=0; while ( i < document.layers.length ) {
				if ( document.layers[i].document.layers[ element ] ) {
					return document.layers[i].document.layers[ element ]; break; } i++ }}
		}
		else if ( document.all ) return document.all [ element ];
		else return document.getElementById ( element );
}
function getStyle ( element ) { // return style property access syntax
		return document.layers ? getId ( element ) : getId (element).style;
}
function getTags ( tagType ) { // return element collection
		if ( document.getElementsByTagName ) return document.getElementsByTagName ( tagType );
		if ( document.all && !document.getElementsByTagName ) return document.all.tags ( tagType );
		if ( document.layers && tagType == "div" ) return document.layers;
}
function getParent ( object ) { // something not right here...
		if ( document.layers ) return;
		else return ( document.all && !opera ) ? object.offsetParent : object.parentNode;
}
function documentDump ( element, dump ) { // target element & insert string [not supported by Opera]
	    if ( document.layers ) { with ( getId( element ).document ) { open(); write ( dump ); close(); }}
		else return getId ( element ).innerHTML = dump;
}
function isChildOfParent ( element, parent ) { // determine whether or not an element is a child of another [DOM only]
		return ( getId(parent).contains(element) );
}
function globalOffsetLeft ( object ) { // return global x coordinate
		if ( document.layers ) return object.x;
		else return ( document.all && !opera && object.tagName.indexOf ("td") == 0 ? 0 : object.offsetLeft ) 
			+ ( object.offsetParent && object.offsetParent.tagName != "html" ? globalOffsetLeft ( object.offsetParent ) : 0 );
}
function globalOffsetTop ( object ) { // return global y coordinate
		if ( document.layers ) return object.y;
  		else return ( document.all && !opera && object.tagName.indexOf ("td") == 0 ? 0 : object.offsetTop ) 
			+ ( object.offsetParent && object.offsetParent.tagName != "html" ? globalOffsetTop ( object.offsetParent ) : 0 );
}
function getMouse (e) { // read mouse coordinates
		window.xPos = ( document.layers ? e.x : ( document.all ? event.clientX : e.clientX ));
		window.yPos = ( document.layers ? e.y : ( document.all ? event.clientY : e.clientY ));
}
function characterEncode ( string ) { // convert danish letters to html character entities [ for MacIE4 ]
	danishLetters = new Array ( "Æ", "Ø", "Å", "æ", "ø", "å" );
	htmlEncodings = new Array ( "&AElig;", "&Oslash;", "&Aring;", "&aelig;", "&oslash;", "&aring;" );
	for ( a=0; a<string.length; a++ ) {
		for ( b=0; b < danishLetters.length; b++ ) {
			if ( string.charAt (a) == danishLetters[b] ) 
				string = string.replace ( string.charAt (a), htmlEncodings[b] );
		}
	}
	return string;
}
function newWindow ( object ) {
	window.open ( object.href );
}
//The Actual menufunctions
// declaration
var topMenuItems 		= new Array ();
var topMenuBars 		= new Array ();
var topMenuLinks 		= new Array ();
var topMenuWords 		= new Array ();
var topAcount 			= -1;
var topMenuBarsCount 	= -1;
var topMenuLinksCount 	= 0;
var topMenuWordsCount 	= 0;
if ( document.layers ) colorChildMenu = false;
// TRACE TOPMENU
function traceTopMenu ( top1, top2, top3 ,top4) { // dump parameters to global array - actual trace inititated onLoad
	var currentArgument; var offsetDump;
	window.documentLocation = new Array ();
	for ( i=0; i < arguments.length; i++ ) {
		window.documentLocation [i] = arguments [i] ? arguments [i].split ( "_" ) [ 1 ]  : null;
	}
}
function performTraceTopMenu () { // unfold topMenu and trace path to current site location
	for ( a=0; a < topMenuLinks.length; a++ ) {
	
		for ( b=0; b < documentLocation.length; b++ ) {
			if ( topMenuWords [a] == documentLocation [b] 
			&& ( this.parentMenuIndex ? this.parentMenuIndex == topMenuLinks [a].charAt(13) : 1==1 )) { // search only children of active menu
			
				// show menuBars
				var indexInteger = Number ( topMenuLinks [a].charAt (11) ) -1;
				var indexString = topMenuLinks [a].replace ( "topMenuLink", "topMenuBar" );
				var postionofChar = indexString.lastIndexOf('-');
				var lastnum = indexString.substr(postionofChar);
				var sliceLength = -(lastnum.length);
				var indexTarget = indexString.replace ( indexString.charAt ( 10 ) , String ( indexInteger )).slice ( 0, sliceLength );
				if ( indexInteger == b +1 ) {
					getStyle ( indexTarget ).visibility = "visible";
					
					this.currentIndex = indexTarget.split ("topMenuBar" ) [1]
					
					if ( b < documentLocation.length - 1 ) {
					// color menuLinks
					if ( document.layers )
						getStyle ( topMenuLinks [a] ).bgColor = colorActive;
					else if ( opera ) {
						getStyle ( topMenuLinks [a] ).backgroundColor = colorActive;
						getStyle ( topMenuLinks [a] ).color = colorTextOn;
					}
					else 
						getId ( topMenuLinks [a] ).className = "topMenuOn";
					}
				}
					
				this.parentMenuIndex = topMenuLinks [a].charAt(13);
			}
		}
	}
}
// TOPMENU PERFORMANCE
function topMenuShow ( element ) { // show target menuBar and color selected menuItem
	var colorChildMenu;
	window.topMenuActive = true;
	cancelInterception ( "topMenu" ); // handle clickInterceptor function
	
	// hide and show menuBars
	var barIndex = element.slice (0,11);
	for ( i=0; i<topMenuBars.length; i++ ) {
		if ( topMenuBars[i].indexOf ( barIndex ) != -1 || topMenuBars[i].indexOf ( "topMenuBar3" ) != -1 ) 
			getStyle( topMenuBars[i] ).visibility = "hidden";
	}
	
	if ( colorChildMenu && window.currentTopReadyBar ) { 
		if ( opera ) 
			getStyle ( window.currentTopReadyBar ).backgroundColor = 
			eval ( "colorBar" + window.currentTopReadyBar.charAt(10) );
		else  
			getId ( window.currentTopReadyBar ).className = getId ( window.currentTopReadyBar ).className.split ("Ready") [0];
	}
	
	getStyle ( element ).visibility = "visible";
	
	// color menuBars?
	if ( colorChildMenu ) {
		if ( opera ) getStyle ( element ).backgroundColor = colorActive;
		else getId ( element ).className += "Ready";
		window.currentTopReadyBar = element;
	}
	// color menuLinks
	var elementIndex = Number ( element.charAt(10) );
	var elementSubIndex = Number ( element.charAt(12) );
	var elementSubSubIndex = element.length >= 14 ? Number ( element.charAt(14) ) : null;
			
	var sourceLinkString = 
		"topMenuLink" + elementIndex + ( elementIndex > 2 ? "-" + elementSubIndex : "" );
	var targetLinkString = 
		"topMenuLink" + ( elementIndex + 1 ) + "-" + elementSubIndex + 
		( elementSubSubIndex != null ? "-" + elementSubSubIndex : "" );
	for ( i=0; i < topMenuLinks.length; i++ ) {
				
		if ( topMenuLinks [i].indexOf ( sourceLinkString ) != -1 ) {
			if ( opera ) {
				getStyle ( topMenuLinks[i] ).backgroundColor = 
				eval ( "colorBar" + String (( Number ( topMenuLinks[i].charAt(11)) - 1 )));
				getStyle ( topMenuLinks[i] ).color = colorTextOff;
			} 
			else if ( document.layers ) getId ( topMenuLinks[i] ).bgColor = null;
			else getId ( topMenuLinks[i] ).className = "topMenuOff";
		}
		
		if ( !document.layers && colorChildMenu && topMenuLinks [i].indexOf ( targetLinkString ) != -1 ) {
			if ( opera ) {
				getStyle ( topMenuLinks[i] ).backgroundColor = colorActive;
				getStyle ( topMenuLinks[i] ).color = colorTextOn;
			}
			else getId ( topMenuLinks[i] ).className = "topMenuReady";
		}
	}
	
	// color sourceLink
	
	var sourceLink = element.replace ( "topMenuBar", "topMenuLink" ); 
	
	if ( opera ) {
		getStyle ( sourceLink ).backgroundColor = colorActive;
		getStyle ( sourceLink ).color = colorTextOn;
	}
	else if ( document.layers ) getId ( sourceLink ).bgColor = colorActive;
	else getId ( sourceLink ).className = "topMenuOn";
	
	// collapse topMenu if idle
	if ( window.topMenuHideTimeout ) clearTimeout ( window.topMenuHideTimeout );
	if ( !document.layers ) window.topMenuHideTimeout = setTimeout ( "resetTopMenu()", 16000 );
}
function resetTopMenu () { // reset topMenu
	window.topMenuActive = false;
	if ( window.topMenuHideTimeout ) clearTimeout ( topMenuHideTimeout );
	for ( i=0; i<topMenuBars.length; i++ ) {
		if ( ! topMenuBars[i].indexOf ( "topMenuBar1" ) != -1 ) 
			getStyle( topMenuBars[i] ).visibility = "hidden";
	}
	
	if ( opera ) {
		for ( i=0; i<topMenuLinks.length; i++ ) {
			getStyle ( topMenuLinks [i] ).backgroundColor = eval ( "colorBar" + ( topMenuLinks[i].charAt (11) - 1 ) );
			getStyle ( topMenuLinks [i] ).color = colorTextOff;
		}	
		if ( colorChildMenu ) 
			for ( i=0; i<topMenuBars.length; i++ )
				getStyle( topMenuBars[i] ).backgroundColor = eval ( "colorBar" + topMenuBars[i].charAt(10) );
	}
	
	else { 
		for ( i=0; i<topMenuLinks.length; i++ ) 
			getId ( topMenuLinks[i] ).className = "topMenuOff";
		if ( window.currentTopReadyBar ) 
			getId ( window.currentTopReadyBar ).className = getId ( window.currentTopReadyBar ).className.split ("Ready") [0];
	}
	performTraceTopMenu();
}
// GENERATE TOPMENU
function top1 ( menuText, menuTarget ) { // top level menuItem
	topBcount = 1;
	topAcount ++;
	topMenuItems [ topAcount ] = new Array ( menuText);
	if ( menuTarget ) topMenuItems [ topAcount ] [1] = menuTarget;

}
function top2 ( menuText, menuTarget ) { // medium level menuItem
	topCcount = 1;
	topBcount ++;
	topMenuItems [ topAcount ] [ topBcount ] = new Array ( menuText);
	if ( menuTarget ) topMenuItems [ topAcount ] [ topBcount ] [1] = menuTarget;
}
function top3 ( menuText, menuTarget ) { // bottom level menuItem
	topCcount ++;
	topMenuItems [ topAcount ] [ topBcount ] [ topCcount ] = new Array ( menuText, menuTarget );
}
function summonTopMenu () { // generate topMenu markup
	// menuA
	window.dump = '<div class="topMenuBar1" id="topMenuBar1">';
	topMenuBars [ topMenuBarsCount ++ ] = 'topMenuBar1';
	dump += '<div class="topMenuItems">';
	for ( a=0; a < topMenuItems.length; a++ ) {
		if ( document.layers ) dump += '<ilayer name="topMenuLink2-'+a+'">';
		dump += '<a id="topMenuLink2-'+a+'" class="topMenuOff" href="';
		if ( topMenuItems [a][1] ) dump += topMenuItems [a][1] + '">'
		else dump += 'javascript: topMenuShow (\'topMenuBar2-'+a+'\')">'; 
		//dump += '&nbsp;&nbsp;&nbsp;' + topMenuItems [a][0].split ( "_" ) [ 0 ] + '&nbsp;&nbsp;&nbsp;</a>';
dump +=  topMenuItems [a][0].split ( "_" ) [ 0 ] + '</a>';		
if ( document.layers ) dump += '</ilayer>';
		topMenuLinks [ topMenuLinksCount ++ ] = 'topMenuLink2-'+a;
		topMenuWords [ topMenuWordsCount ++ ] = topMenuItems [a][0].split ( "_" ) [ 1 ];
	}
	dump += '</div></div>';
	
	// menuB
	for ( a=0; a < topMenuItems.length; a++ ) {
		dump += '<div class="topMenuBar2" id="topMenuBar2-'+a+'">';
		topMenuBars [ topMenuBarsCount ++ ] = 'topMenuBar2-'+ a;
		dump += '<div class="topMenuItems">';
			for ( b=2; b < topMenuItems[a].length; b++ ) {
				if ( document.layers ) dump += '<ilayer name="topMenuLink3-'+a+'-'+b+'">';
				dump += '<a class="topMenuOff" id="topMenuLink3-'+a+'-'+b+'" href="'
				dump += ( topMenuItems [a][b][1] ? topMenuItems [a][b][1] : 
					'javascript: topMenuShow (\'topMenuBar3-'+a+'-'+b+'\');' ) + '">';
				dump +=  topMenuItems [a][b][0].split ( "_" ) [ 0 ] + '</a>';
				if ( document.layers ) dump += '</ilayer>';
				topMenuLinks [ topMenuLinksCount ++ ] = 'topMenuLink3-'+a+'-'+b;
				topMenuWords [ topMenuWordsCount ++ ] = topMenuItems [a][b][0].split ( "_" ) [ 1 ];
			}
		dump += '</div></div>';
	}
	
	// menuC
	for ( a=0; a < topMenuItems.length; a++ ) {
		for ( b=2; b < topMenuItems[a].length; b++ ) {
			if ( topMenuItems [a][b].length > 2 ) {
				dump += '<div class="topMenuBar3" id="topMenuBar3-'+a+'-'+b+'">';
				topMenuBars [ topMenuBarsCount ++ ] = 'topMenuBar3-'+a+'-'+b+'';
				dump += '<div class="topMenuItems">';
				for ( c=2; c < topMenuItems [a][b].length; c++ ) {
					if ( document.layers ) dump += '<ilayer name="topMenuLink4-'+a+'-'+b+'-'+c+'">';
					dump += '<a class="topMenuOff" id="topMenuLink4-'+a+'-'+b+'-'+c+'" href="'+ topMenuItems [a][b][c][1] +'">';
					dump +=  topMenuItems [a][b][c][0].split ( "_" ) [ 0 ] + '</a>';
					if ( document.layers ) dump += '</ilayer>';
					topMenuLinks [ topMenuLinksCount ++ ] = 'topMenuLink4-'+a+'-'+b+'-'+c;
					topMenuWords [ topMenuWordsCount ++ ] = topMenuItems [a][b][c][0].split ( "_" ) [ 1 ];
				}
				dump += '</div></div>';
			}
		}
	}
	dump += '<div class="clear"></div>';
	
	if ( opera || document.layers ) document.write ( dump ); // else wait for function initialize()
}
// ADDED FOR BANKDATA 
// listeners
window.onload = initialize;
document.onclick = documentClick;
// declarations
var clickCheck = null;
var interceptors = new Array();
var interceptorCount = 0;
function documentClick () { // perform stuff onMouseClick
		setTimeout ( "clickInterception()", 50 );
}
function cancelInterception ( elementType ) { // nullify interception
		window.clicked = elementType;
}
function clickInterception () { // hide irelevant elements
		if ( window.clicked != "topMenu" && window.topMenuActive == true ) resetTopMenu ();
		window.clicked = null;
}
function initialize() { // onLoad actions
		if (!document.layers && !opera && window.dump ) documentDump ( "topMenu", dump ); // implant topMenu		
		performTraceTopMenu (); // trace topMenu [function resides in topmenu.js]
}
