/*
   Milonic DHTML Menu - Treemenu module version 1.12 - December 2 2004
   This module is only compatible with the Milonic DHTML Menu version 5.62 or higher

   Copyright 2004 (c) Milonic Solutions Limited. All Rights Reserved.
   This is a commercial software product, please visit http://www.milonic.com/ for more information.
   
   SYNTAX: <script type="text/javascript" src="/treemenu.js"></script>
*/



function treeMenuDisplay(_mnu,_show){                      // This function hides or shows the menu

	_m[_mnu][7]=_show                                      // Set the menus visibility property to Show or Hide 
	menuDisplay(_mnu,_show); }                             // Display the menu to open


function _cAA(_N,_O,_i)
{
	_I=_mi[_i]
	if(_I[_N])
	{
		_tmp=_I[_N]
		_I[_N]=_I[_O]
		_I[_O]=_tmp
	}
	if(_N==80&&_I[8])
	{
		gmobj("lnk"+_i).oC=_I[8]
		gmobj("lnk"+_i).style.color=_I[8]
	}
	
	// **** Need to edit these lines to get the images working better for collapse menu.
	
	if(_N==83&&_I[24]&&_I[3])gmobj("simg"+_i).src=_I[24]
	if(_N==82&&_I[29])gmobj("img"+_i).src=_I[29]
}

_lastItem=-1
function _oTree()
{	
	_Oi=_itemRef
	_otA(_Oi)
	
	if(!_m[_mi[_Oi][0]].parentItemN&&_W.singleMasterMenu)
	{
		_I=_mi[_Oi]
		for (var _ai=0;_ai<_m[_I[0]][0].length;_ai++)
		{			
			if(_mi[_ai].childN&&_ai!=_Oi)
			{
				if($tU(_mi[_ai].child.style.visibility)=="VISIBLE")
				{
					_otA(_ai)
					itemOff(_ai)
					itemOn(_ai)
					itemOff(_ai)
				}
			}
		}
	}
}
/*
a_Tree=0
function autoOT()
{
	if(!a_Tree)
	{
		if(_cip.length>0)
		{
			for(_c=0;_c<_cip.length;_c++)
			{
				_ci=_cip[_c];
				_mni=getParentItemByItem(_ci);
				if(_mni==-1)_mni=_ci
				
				if(_mni+" "!=$u)
				{
					while(_mni!=-1)
					{
						_I=_mi[_mni]
						_setCPage(_I)
						itemOff(_mni);
						_mni=getParentItemByItem(_mni);
						if(_mni+" "==$u)_mni=-1
					}
				}
			}
		}
	}
	a_Tree=1
	
}

*/
function _otA(_i)
{
	_dB=_d.body;
	_dBT=_dB.offsetTop
	_dBL=_dB.offsetLeft	
	_cAA(80,8,_i)
	_cAA(81,7,_i)
	_cAA(82,29,_i)
	_cAA(83,24,_i)
	_I=_mi[_i]                                             // set menu item shorthand to _I
	if(!_I[27])_I[27]=1
	
	if(!_I[3]||!_I[34])return                              // If no showmenu has been specified or not a treemenu go back
	if(!_I.child)                                          // Set the menu that this item will open.
	{		
		_I.childN=getMenuByName(_I[3])
		_I.child=gmobj("menu"+_I.childN)
	}
	
	hmL(_I.childN)
	
	//if(mac){if(!_I.obj)_I.obj=gmobj("pTR"+_i)              // IE on the The Apple Mac needs to use <TR> for positioning
	//}else{if(!_I.obj)_I.obj=gmobj("OtI"+_i)}                // All other browsers can use <TD>
	_I.obj=gmobj("OtI"+_i)
	_mnuO=_m[_I.childN]                                    // This is the object reference to the menu we are about to open
	_io=_I.obj                                             // Set _io as shorthand object reference to this menu item 
	
	
	_Pmenu=getMenuByItem(_i)
	
	if(_mnuO[7])                                           // If the DISPLAY attribute is on the menu is shown and must now be hidden
	{
		if(ie&&!mac)_io.style.display="none"
		_tAct=0
		treeMenuDisplay(_I.childN,0)                       // Hide this menu
		_CH=_m[_I.childN].HGT-_m[_I.childN].OHGT           // Set _CH as the variable to store this menus height, used for adjusting child and siblings
		closeTMenu(_i)
	}
	else                                                   // Display this child menu
	{
		if(ie&&!mac)_io.style.display="block"
		_tAct=1
		treeMenuDisplay(_I.childN,1)
		_PiGP=gpos(_io)                                    // get the Dimensions of parent menu item
		_cD=gpos(_I.child)                                 // Get the Dimensions of menu we are about to open
		//_I.ttop=_PiGP[0]+_PiGP[2]+(_m[_I.childN][6][65]+_I[68]+_I[27]) // set temporary top property for the 
		_I.ttop=_PiGP[0]+_PiGP[2]-_I[27] // set temporary top property for the 
		_m[_I.childN].ttop=_I.ttop
		
		_I.tleft=_PiGP[1]+treeOffset
		if(mac)_I.tleft-=_I[27]
		
		
	
		
		if(sfri)
		{
			if(_m[_Pmenu][14]=="relative")
			{
				_I.tleft=(_I.tleft)+_dBL
				_I.ttop=(_I.ttop)+_dBT
				
			}
		else
			_I.tleft-=_I[27]
		}
		
		
		_m[_I.childN].tleft=_I.tleft
		spos(_I.child,_I.ttop,_I.tleft)         // set the position of the menu to open
		

		if(!_m[_I.childN].parentItem)
		{
			_m[_I.childN].parentItem=_io
			_m[_I.childN].OHGT=_PiGP[2]
			_m[_I.childN].parentItemN=_i
		}			
		_m[_I.childN].HGT=_cD[2]+_PiGP[2]-2

		_OH=_m[_mi[_i].childN].HGT-_m[_mi[_i].childN].OHGT

		if(_I.children)
		{
			for(_tm=0;_tm<_I.children.length;_tm++)
			{
				_mnu=_I.children[_tm] // this items menu
				_GP=gpos(_m[_mnu].parentItem) // get position of OtI
				_m[_mnu].ttop=_GP[0]+_m[_mnu].OHGT-_I[27] 
				spos(gmobj("menu"+_mnu),_m[_mnu].ttop,_m[_mnu].tleft) // set the position of this items menu
				treeMenuDisplay(_mnu,1) // show the menu
			}
		}
	}
	resetParents(_i)
}

function resetChildren(_i)
{	
	_ar=getChildrenByItem(_i)
	for (var _ai=1; _ai<_ar.length; _ai++)
	{
		_AI=_ar[_ai]
		if(_tAct)_m[_AI].ttop+=_OH; else _m[_AI].ttop-=_CH;
		spos(gmobj("menu"+_AI),_m[_AI].ttop)
	}
}


function resetSiblings(_i)
{
	var _I=_mi[_i]
	var _ar=_m[_I[0]][0]
	for (var _ai=0; _ai<_ar.length; _ai++)
	{
		_AI=_ar[_ai]
		if(_i<_AI)
		{
			if(_mi[_AI].childN)
			{
				_mnu=_mi[_AI].childN
				if(_tAct)_m[_mnu].ttop+=_OH; else _m[_mnu].ttop-=_CH;
				spos(gmobj("menu"+_mnu),_m[_mnu].ttop)
				resetChildren(_AI)
			}
		}
	}
}

function resetParents(_i)
{
	_I=_mi[_i]                                             // menu item
	_mnu=_I.childN
	_th=0
	while(_m[_mnu].parentItem)
	{
		if(_tAct)
		{
			_m[_mnu].HGT=_m[_mnu].HGT+_th	
			if(_th==0)_th=_m[_mnu].HGT-_m[_I.childN].OHGT;			
		}
		else
		{
			_m[_mnu].HGT=_m[_mnu].HGT-_CH
		}
		spos(_m[_mnu].parentItem,_n,_n,_m[_mnu].HGT)
		_fixMenu(_mnu)
		resetSiblings(_m[_mnu].parentItemN)
		_mnu=_mi[_m[_mnu].parentItemN][0]
	}
	
	if(mac)
	{	
		_macP=gpos(gmobj("tbl"+_mnu))
		spos(gmobj("menu"+_mnu),_n,_n,_macP[2])
	}
}



function closeTMenu(_i)
{	
	_ar=getChildrenByItem(_i)
	_I=_mi[_i]
	_I.children=_ar	
	for(_tm=0;_tm<_ar.length;_tm++)
	{		
		treeMenuDisplay(_ar[_tm],0)
		
	}	
	spos(_m[_I.childN].parentItem,_n,_n,_m[_I.childN].OHGT)
}



gChildren=new Array();
function crawlChildren(_i) // returns menus that are children of declared menu item
{	
	_cHm=_mi[_i].childN
	if(!_cHm)return
	var _ar=_m[_cHm][0]
	if(_mi[_i].childN && _m[_mi[_i].childN][7])gChildren[gChildren.length]=_mi[_i].childN;
	for (var _ai=_ar[0]; _ai<_ar[_ar.length-1]+1; _ai++)
	{		
		if(_mi[_ai].childN && _m[_mi[_ai].childN][7])crawlChildren(_ai)
	}
}


function getChildrenByItem(_i)
{
	gChildren=new Array();
	crawlChildren(_i)
	return gChildren;
}






