// UDMv4.5 // Horizontal Menus extension v1.01 //
/***************************************************************\

  ULTIMATE DROP DOWN MENU Version 4.5 by Brothercake
  http://www.udm4.com/

\***************************************************************/



//if this is a horizontal navbar, and not rtl
if(um.h&&!um.rtl)
{
	//mac/ie5, win/ie5.0, opera <7.5, and old gecko builds are unsupported,
	//so we need to disable menu and arrow support altogether
	if(um.mie||um.wie50||(um.o7&&!um.o75)||um.og) {um.nm=1;um.nr=1;}
}



//add anonymous receiver for menu pre-initialised event
um.addReceiver(function(menu)
{
	//if this is not a horizontal navbar, or rtl, don't continue
	if(!um.h||um.rtl){return;}

	//identify it to the keyboard navigation module
	//so that keystrokes can be mapped
	um.hmx=true;

	//is this a first-level or deeper menu
	um.first=menu.parentNode.parentNode==um.tr;

	//start computing navbar width
	um.navwidth=0;


	//get child nodes in the main UL
	var nodes=um.tr.childNodes;

	//for each node
	var len=nodes.length;
	for(var i=0;i<len; i++)
	{
		//if it's a list item
		if(/li/i.test(nodes[i].nodeName))
		{
			//add its link width to nav width
			um.navwidth+=um.addToWidth(um.gc(nodes[i]).offsetWidth);
		}
	}


	//if margin is 0 and overflow collapse is in use,
	//add the final border
	if(um.nc){um.navwidth+=um.e[18];}

	//otherwise subtract the final margin
	else{um.navwidth-=um.e[17];}


	//if we're not in quirks mode
	//subtract menu padding and borders
	if(!um.q){um.navwidth-=(um.e[51]+um.e[55])*2;}


	//set the menu width
	menu.style.width=um.navwidth+'px';


},'058');




//add anonymous receiver for menu open event
um.addReceiver(function(menu)
{
	//if this is not a horizontal navbar, or rtl, don't continue
	if(!um.h||um.rtl){return;}


	//start computing menu offsets
	var offset={'left':0,'top':0};

	//get the trigger item
	var trigger=menu.parentNode;

	//subtract its link's left offset from the page, from left offset
	offset.left-=um.getRealPosition(um.gc(trigger),'x');

	//add first item link's left offset from page, to left offset
	offset.left+=um.getRealPosition(um.tr.getElementsByTagName('a')[0],'x');

	//we're using links in those computations
	//because the list-items may be displaced from the actual link

	//if this is IE or Safari 1.0 or Opera
	//and not a first-level menu
	//document.title = um.q;
	if((um.ie||(um.s&&!um.s1)||um.o7)&&!um.first)
	{
		//add the list-item's offset from menu, from left offset
		offset.left+=trigger.offsetLeft;
	}


	//if this is a first-level menu
	if(um.first)
	{
		//add nav->menu y-offset to top offset
		offset.top+=um.e[15];
	}

	//if it's a deeper level
	else
	{
		//add menu->menu y-offset to top offset
		offset.top+=um.e[50];

		//if this is not safari or KDE
		if(!(um.s||um.k))
		{
			//subtract menu border width from left offset
			//for each depth of level we are
			var tmp=menu.parentNode.parentNode;
			while(tmp&&tmp!=um.tr)
			{
				offset.left-=um.e[51];
				tmp=tmp.parentNode.parentNode;
			}
		}

		//add menu border width and padding to top offset
		offset.top+=um.e[51]+um.e[55];
	}


	//set new menu position
	menu.style.marginLeft=offset.left+'px';
	menu.style.marginTop=offset.top+'px';


	//look for shadow and iframe cover layers
	var layers=['udmS','udmC'];
	for(var i=0;i<2;i++)
	{
		//if layer exists
		var layer=um.getRelatedLayer(menu,layers[i]);
		if(layer)
		{
			//hide this layer so you don't
			//see it move as it repositions in moz
			layer.style.visibility = 'hidden';

			//get menu position
			um.mp={
				x:(menu.offsetLeft),
				y:(menu.offsetTop)
				};

			//irrational tweaks for safari 1.0 child menus
			if(um.s&&!um.s1&&!um.first)
			{
				//adjust x and y by menu border
				um.mp.x-=um.e[51];
				um.mp.y-=um.e[51];
			}

			//move layer to menu position
			layer.style.left=um.mp.x+'px';
			layer.style.top=um.mp.y+'px';
		}
	}


	//start a 1ms timer to reshow the layers
	//which is enough so you don't see it move as it repositions
	window.setTimeout(function()
	{
		//for each potential layer
		for(i=0;i<2;i++)
		{
			//if layer exists
			layer=um.getRelatedLayer(menu,layers[i]);
			if(layer)
			{
				//make it visible
				layer.style.visibility = 'visible';

			}
		}
	},1);


},'060');


//add to computed navbar width
um.addToWidth=function(input)
{
	//if margin is 0 and overflow collapse is in use
	if(um.nc)
	{
		//subtract border width
		input-=um.e[18];
	}
	//otherwise
	else
	{
		//add margin
		input+=um.e[17];
	}

	//return value
	return input;
};


//get related layer
um.getRelatedLayer=function(menuNode,menuClass)
{
	//look for node
	var node=menuNode.parentNode.lastChild;

	//if this is ie55 and iframe is in use
	//and we're looking for a shadow node
	//or if the last child is a text node
	if((um.wie55&&(um.e[13]=='default'||um.e[13]=='iframe')&&menuClass=='udmS')||node.nodeName=='#text')
	{
		//we want the previous sibling
		node=node.previousSibling;
	}

	//store node classname,converting null reference for kde's benefit
	var cname=um.es(node.className);

	//if there's a node with a classname there - ie,one we added
	if(cname!='')
	{
		//and it has the right class name
		if(cname.indexOf(menuClass)!=-1)
		{
			//return the node
			return node;
		}
		else{return null;}
	}
	else{return null;}
};

