window.addEvent('domready', function() {

	$$('div#horiz-menu').getChildren('ul').each(function(ul) {
		
		ul.getChildren('li').each(function(li) {
		
			li.addEvent('mouseenter', function() {
	
				$$('div#horiz-menu').getChildren('ul').each(function(ul) {
					
					ul.getChildren('li').each(function(li) {
					
						li.removeClass('active');
					});
				});
				
				this.addClass('active');
			});
		});
	});
	
	var delay;
	
	$$('div#horiz-menu').addEvent('mouseleave', function() {
		
		delay = (function() {
						
			$$('div#horiz-menu').getChildren('ul').each(function(ul) {
				
				ul.getChildren('li').each(function(li) {
					
					li.each(function(el) {
					
						var hasCurrent = el.hasClass('current');
					
						if ( ! hasCurrent)
						{
							el.getElements('li.current').each(function() {
								
								hasCurrent = true;
							});
						}
					
						hasCurrent ? el.addClass('active') : el.removeClass('active');
					});
				});
			});
								
		}).delay(1500);
	});
	
	$$('div#horiz-menu').addEvent('mouseenter', function() {
		
		 $clear(delay); 
	});
});



