menus = []



function menu_class(id) {
	this.id = id;
	this.top_ul = undefined;
	
	this.delay_show = 350;
	this.delay_hide = 500;
	this.show_speed = 200;
	this.hide_speed = 200;
	
	
	
	this.init = function() {
		var object = this;
		
		object.top_ul = $('#'+object.id+' > ul');
		
		$('li', object.top_ul).each(function() {
			var
				li = $(this),
				ul = $('> ul', li),
				depth = li.parents('ul', object.top_ul).size();
			
			li
				.mouseenter(function(event) {
					event.stopPropagation();
					
					clearTimeout(object.timeout_show);
					clearTimeout(object.timeout_hide);
					
					$('ul:visible', li.siblings()).fadeOut(object.hide_speed);
					
					if (ul.size() > 0) {
						object.timeout_show = setTimeout(function() {
							ul.fadeIn(object.show_speed);
							
							if (depth > 1) {
								ul.position({my: 'left top', at: 'right top', of: li});
							}
						}, object.delay_show);
					}
				})
				
				.mouseleave(function() {
					if (depth == 1) {
						clearTimeout(object.timeout_show);
						
						object.timeout_hide = setTimeout(function() {
							$('ul', object.top_ul).fadeOut(object.hide_speed);
						}, object.delay_hide);
					}
				});
		});
	}
}
