
var lastmenuID= new Array();
function toggleMenu(menuID)
{
	for(var depth= 0, pos= menuID.indexOf('_',pos)+1; pos > 0; pos= menuID.indexOf('_',pos)+1) depth++;
	var link= document.getElementById(menuID+'_a');
	var menu= document.getElementById(menuID);
	var lastlink= document.getElementById(lastmenuID[depth]+'_a');
	var lastmenu= document.getElementById(lastmenuID[depth]);
	if(!(link&&menu)) return false;
	if(link.className == 'selected') // deselect
	{ lastlink.className= ''; lastmenu.className= ''; lastmenuID[depth]= null; menu.className= ''; link.className= ''; }
	else
	{ 
		if(lastlink) lastlink.className= '';
		if(lastmenu) lastmenu.className= '';
		lastmenuID[depth]= menuID;
		link.className= 'selected';
		menu.className= 'selected';
	}
	adjustColumns();
	return true;
}

function setStyle(style)
{
	if(!document.styleSheets||!document.styleSheets.length) return;
	for(var i= 0; i < document.styleSheets.length; i++)
		document.styleSheets[i].disabled= !(document.styleSheets[i].title == style);
}

function goOption(sel)
{
	var opt= sel.options[sel.selectedIndex];
	sel.selectedIndex= 0;
	if(opt.ondblclick) opt.ondblclick();
	else window.open(opt.value,'_top');
	return false;
}

function initMenu()
{
	if(!document.getElementById) return;
	var nav= document.getElementById('nav');
	if(!nav) return;
	var navlinks= nav.getElementsByTagName('A');
	var link, up, uphref_rel;
	var uphref= document.getElementById('link_up');
	if(uphref) uphref= uphref.href;
	for(var i= navlinks.length-1 ; i >= 0; i--)
		if((navlinks[i].href==document.URL)||(navlinks[i].href==window.location.pathname)||(('/'+navlinks[i].href)==window.location.pathname)) 
			{ link= navlinks[i]; break; }
		else if((navlinks[i].href==uphref)||('/'+navlinks[i].pathname==uphref))
			{ up= navlinks[i]; }
	if(!link) link= up;
	if(!link) return;
	for(var node= link.parentNode; node && node != nav; node= node.parentNode)
		if(node.tagName=='UL') toggleMenu(node.id);
	link.className= 'selected';
	var submenu= link.nextSibling;
	if(!submenu) return;
	if(submenu.tagName!='UL') return;
	submenu.className= 'selected';
	var menuID= link.nextSibling.id;
	if(!menuID) return;
	for(var depth= 0, pos= menuID.indexOf('_',pos)+1; pos > 0; pos= menuID.indexOf('_',pos)+1) depth++;
	lastmenuID[depth]= menuID;
}

function adjustColumns()
{
	if(!document.getElementById) return;
	var RHC= document.getElementById('sidebar2')||document.getElementById('sidebar'), 
		Body= document.getElementById('body2')||document.getElementById('body'),
		Nav= document.getElementById('navbar');
	if(!Body||!Nav) return;
	if(document.defaultView && document.defaultView.getComputedStyle)
	{
		Body.style.height= 'auto';
		var RHCHeight= (RHC?parseInt(document.defaultView.getComputedStyle(RHC,'').height):0), 
			NavHeight= parseInt(document.defaultView.getComputedStyle(Nav,'').height);
		if(parseInt(document.defaultView.getComputedStyle(Body,'').height) < RHCHeight) Body.style.height= RHCHeight + 'px';
		if(parseInt(document.defaultView.getComputedStyle(Body,'').height) < NavHeight) Body.style.height= NavHeight + 'px';
	}
	else if(window.getComputedStyle)
	{
		Body.style.height= 'auto';
		var RHCHeight= (RHC?parseInt(getComputedStyle(RHC,'').height):0), 
			NavHeight= parseInt(getComputedStyle(Nav,'').height);
		alert(NavHeight);
		if(parseInt(getComputedStyle(Body,'').height) < RHCHeight) Body.style.height= RHCHeight + 'px';
		if(parseInt(getComputedStyle(Body,'').height) < NavHeight) Body.style.height= NavHeight + 'px';
	}
	else if(Body.offsetHeight)
	{
		var Foot= document.getElementById('footer'), Head= document.getElementById('header'), 
			SteveHeight= document.getElementById('cover') ? Body.lastChild.offsetHeight : 0;
		if(!Foot||!Head) return;
		Body.style.position='relative'; 
		Body.style.top= 0;
		var RHCBottom= (RHC?RHC.offsetTop + RHC.offsetHeight + 8:0),
			NavBottom= Nav.offsetTop + Nav.offsetHeight + 8;
		if(Foot.offsetTop < RHCBottom) Body.style.height= RHCBottom - Foot.offsetHeight;
		if(Foot.offsetTop < NavBottom) Body.style.height= NavBottom - Foot.offsetHeight;
		if(SteveHeight) Body.lastChild.style.height= SteveHeight;
	}
}

function init()
{
	if(document.cookie.search(/\bstyle=([^;]+)/) > -1) 
		setStyle(unescape(RegExp.$1.replace('+',' ')));
	if(document.layers) return;
	initMenu();
	adjustColumns();
	if(document.cookie.indexOf('noflash=True')>-1) return;
	if(typeof(initHeadBanner)=='function') initHeadBanner();
	if(typeof(initcover)=='function') { initcover(); adjustColumns(); }
	if(typeof(initapply)=='function') initapply();
}
window.onload= init;
