var ma = false, pe = false;
Event.observe(document, 'dom:loaded', function (ev)
{
	$('lista-menu').select('.item_menu').each(function(i){
		divMenu = i.select('div.submenu');
		if(divMenu.length)
			divMenu[0].insert(
				new Element('div', {className: 'borda_baixo'}).insert(
					new Element('div', {className: 'ponta-esq'})
				).insert(
					new Element('div', {className: 'ponta-dir'})
				).insert(
					new Element('div', {className: 'centro'})
				)
			);
		
		Event.observe(i, 'mouseover', function(ev){
			ev.stop();
			var sm = this.select('div.submenu');
			cf(ev);
			
			if(ma){
				ma.hide();
			}
			if(sm.length){
				if(this.getWidth() > sm[0].getWidth()){
					sm[0].down().setStyle({width: this.getWidth()+'px'});
				}else{
					sm[0].down().setStyle({width: sm[0].getWidth()+'px'});
					sm[0].down().next().setStyle({width: sm[0].getWidth()+'px'});
				}
				sm[0].show();
				ma = sm[0];
			}
		}.bind(i));
		
		Event.observe(i, 'mouseout', df);
	});
		
	$('lista-menu').select('ul').each(function(i){
		Event.observe(i, 'mouseover', cf);
		Event.observe(i, 'mouseout', df);
	});
});
function df(ev){ev.stop();if(!pe){pe = new PeriodicalExecuter(fc, 0.2);}}
function cf(ev){if(ev){ev.stop();}if(pe){pe.stop();pe = false;}}
function fc(){if(ma){ma.hide();ma = false;cf();}}
