var menuIdiomasActivo;

function createMenu(name) {
	var el = Ext.get(name+'-link');
	var tid = 0, menuIdiomas, doc = Ext.get(document);
	
	var handleOver = function(e, t){
		if(t != el.dom && t != menuIdiomas.dom && !e.within(el) && !e.within(menuIdiomas)){
			hideMenu();
		}	
	};
			
	var hideMenu = function(){
		if(menuIdiomas){
			menuIdiomas.hide();
			el.setStyle('text-decoration', '');
			doc.un('mouseover', handleOver);
			doc.un('mousedown', handleDown);
		}
	}
	
	var handleDown = function(e){
		if(!e.within(menuIdiomas)){
			hideMenu();
		}
	}
	
	var showMenu = function(){
		clearTimeout(tid);
		tid = 0;
		if (!menuIdiomas) {
			menuIdiomas = new Ext.Layer({shadow:'sides',hideMode: 'display'}, name+'-menu');
		}
		menuIdiomas.hideMenu = hideMenu;
		menuIdiomas.el = el;
		if(menuIdiomasActivo && menuIdiomas != menuIdiomasActivo){
			menuIdiomasActivo.hideMenu();
		}
		menuIdiomasActivo = menuIdiomas;
		
		if (!menuIdiomas.isVisible()) {
			menuIdiomas.show();
			menuIdiomas.alignTo(el, 'tl-bl?');
			menuIdiomas.sync();
			el.setStyle('text-decoration', 'underline');
			doc.on('mouseover', handleOver, null, {buffer:150});
			doc.on('mousedown', handleDown);
		}
	}
	
	el.on('mouseover', function(e){
		if(!tid){
			tid = showMenu.defer(150);				
		}
	});
	
	el.on('mouseout', function(e){
		if(tid && !e.within(el, true)){
			clearTimeout(tid);
			tid = 0;				
		}
	});
	
}