/**************
flyglobespan.com menu
Developer: G Bradley
© Globespan PLC 2008

Just a simple function, called at onload, that setups up listeners /actions for
the top menu bar.
**************/

FLYG.ready(function(){

	var parentMenu=FLYG.$('menu');
	var _menuActive=false;

	if (navigator.userAgent.match(/msie\s6/i)){

		/* This class is required for IE6, where <select>s always appear over other content. This manages the
		creation / positioning of <iframe>s which sit underneath menu drop-downs, hiding the selectboxes. I hate IE6. */

		FLYG.IE6SelectFix=function(parent){
			this.parent=parent;
			this.iframe=document.createElement("iframe");
			this.load();
			};
		
		FLYG.IE6SelectFix.prototype={
			load:function(){
				this.iframe.setAttribute('src','');
				this.iframe.style.display='block';
				this.iframe.style.visibility='visible';
				this.iframe.style.position='absolute';
				this.parent.appendChild(this.iframe);
				this.iframe=FLYG.$(this.iframe);
				},
			show:function(menu){
				var m=menu[0], t=this.parent;
				var c={x:0,y:0};
				while (m!=t && m.offsetParent){
					c.x+=m.offsetLeft;
					c.y+=m.offsetTop;
					m=m.offsetParent;
					}
				var s={x:menu[0].offsetWidth,y:menu[0].offsetHeight};
				this.iframe.setStyle({top:(c.y-120)+'px',left:(c.x+2)+'px',width:(s.x-2)+'px',height:(s.y-2)+'px',zIndex:'999'});
				this.iframe.show();
				},
			hide:function(){
				this.iframe.hide();
				}
			};
	
		var menuFix=new FLYG.IE6SelectFix(parentMenu[0]);
		var submenuFix=new FLYG.IE6SelectFix(parentMenu[0]);
		}
	
	var tabs=parentMenu.$byClass('submenu',{tagtype:'a'}).mouseover(function(){			// set event for submenus
		hideAll();
		subTabs.removeClass('gradient');
		_menuActive=true;
		var m=FLYG.$(this).addClass('active').next().show();
		if (menuFix) menuFix.show(m);
		});
		
	var submenus=tabs.next();										// submenus
	var menus=tabs.parent();										// menu lists
	var menuTimer=false;

	FLYG.$('menu').mouseover(function(e){							// hide submenus when other menus active
		var el=(FLYG.Event.target(e));
		while (el.parentNode){
			if (Array.prototype.indexOf.call(menus,el)>=0) return;
			el=el.parentNode;
			}
		hideAll();
		});
		
	var subTabs=parentMenu.$byClass('submenu-l2',{tagtype:'a'}).mouseover(function(){
		subTabMenus.hide();
		subTabs.removeClass('gradient');
		var m=FLYG.$(this).addClass('gradient').next();
		m.show();
		_menuActive=true;
		if (submenuFix) submenuFix.show(m);
		});
		
	var subTabMenus=subTabs.next();
	var hideAll=function(){
		tabs.removeClass('active');
		subTabMenus.hide();
		submenus.hide();
		if (menuFix) menuFix.hide();
		if (submenuFix) submenuFix.hide();
		_menuActive=false;
		};

	FLYG.$(document).mouseover(function(e){			// hide submenus when mouse moves away from menu
		if (!_menuActive) return;
		var el=FLYG.Event.target(e);
		while (el && el.parentNode){
			if (el.id=='menu'){
				if (menuTimer){
					clearTimeout(menuTimer);
					menuTimer=false;
					}
				return;
				}
			el=el.parentNode;
			}
		if (!menuTimer) menuTimer=setTimeout(hideAll,400);
		});
	
	FLYG.$('signupemail').focus(function(){if (this.value=='Enter your email address') this.value='';});
	
	});