// UDMv4.5 // Gecko Iframe-shim extension v1.0 //
/***************************************************************\

  ULTIMATE DROP DOWN MENU Version 4.5 by Brothercake
  http://www.udm4.com/
  
\***************************************************************/

/***************************************************************\
 * Set shadow offset [in pixels] for iframe to cover shadow layer
\***************************************************************/

var shadowOffset = 2;

/***************************************************************\
\***************************************************************/






//add receivers for menu opening and closing events
//for Gecko browsers 1.1 or later 
//but exclude Safari, which spoofs as Gecko
if(navigator.product == 'Gecko' && parseInt(navigator.productSub,10) >= 20020826 && navigator.vendor != 'Apple Computer, Inc.') 
{ 
	um.addReceiver(createIframe,'060'); 
	um.addReceiver(removeIframe,'070'); 
}
//in safari, mac/ie5 and msn, the applet still shows through so there's no point
//that's also true for mac mozilla builds, but it still happens to save more sniffing
//in Opera 7 the applet shows through *and* the iframe has infinite z-order so it's above the menu
//in older gecko builds the applet is covered, but the iframe also has infinite z-order


//global object
var ifs = new Object;

//id counter
ifs.ids = 0;


//create iframe layer
function createIframe(menu)
{
	//assign an id to the menu 
	//we're doing this so that we can identify the iframe by its associated menu id
	//and removing from the menu mouseout
	//the other way would be what IE does - append the iframe inside the list-item
	//but invalidating the DOM on the fly, while acceptable for IE (imo), is not really acceptable for moz 
	//and anyway it makes it flicker when it first appears, so I'm doing it this way instead
	menu.id = 'ifsMenu-' + ifs.ids;
	
	//create iframe
	ifs.attrs = { 'class':'iframeShim', 'id' : 'ifsShim-' + ifs.ids };
	ifs.frame = um.createElement('iframe', ifs.attrs);
	
	//increase counter
	ifs.ids ++;
	
	//append to body
	document.getElementsByTagName('body')[0].appendChild(ifs.frame);

	//set dimensions to menu offset dimensions
	ifs.frame.style.width = (menu.offsetWidth+shadowOffset) + 'px';
	ifs.frame.style.height = (menu.offsetHeight+shadowOffset) + 'px';

	//move cover to menu position
	ifs.frame.style.left = um.getRealPosition(menu,'x') + 'px';
	ifs.frame.style.top = um.getRealPosition(menu,'y') + 'px';

};



//remove iframe layer
function removeIframe(menu)
{
	//for all menus within parent of this menu
	ifs.menus = menu.parentNode.getElementsByTagName('ul');
	ifs.menusLen = ifs.menus.length;
	
	//for each menu
	for(i=0; i<ifs.menusLen; i++)
	{
		//if menu ID matches an iframe id
		if(/ifsMenu/.test(ifs.menus[i].id))
		{
			//work out iframe id
			ifs.frameID = ifs.menus[i].id.replace('ifsMenu','ifsShim');
			
			//remove child with that id
			document.getElementsByTagName('body')[0].removeChild(document.getElementById(ifs.frameID));
		
			//reset menu id
			ifs.menus[i].id = '';
		}
	}
};

