var active = $('menu').getFirst('.active');
var activeHasChildren = (active != null && active.getChildren('ul')[0] != null)

var showsub = function(event) {
	this.getFirst('ul').addClass('visible');
	if(activeHasChildren) {
		active.getFirst('ul').removeClass('visible');
	}
}
var hidesub = function(event) {
	this.getFirst('ul').removeClass('visible');
	if(activeHasChildren) {
		active.getFirst('ul').addClass('visible');
	}
}

$each($$('#menu > li'), function(item) {
	if(item.hasClass('active')) {
		if(activeHasChildren) {
			item.getFirst('ul').addClass('visible');
		}
	} else if (item.getChildren('ul')[0]) {
		item.addEvents({'mouseover': showsub, 'mouseout':hidesub});
	}
});

