window.addEvent('domready', function() {
	$each($$('.submenu'), function(el) {
		pos = $(el.parentNode).getPosition();
		dim = el.parentNode.getSize();
		
		el.style.display="none";
		el.style.top = (pos.y + dim.y).toString() + 'px';
		el.style.left = pos.x.toString() + 'px';
		
		el.parentNode.addEvent('mouseenter', function(e){
			pos = $(this).getPosition();
			dim = this.getSize();
			
			c = this.children[1];
			c.style.top = (pos.y + dim.y).toString() + 'px';
			c.style.left = pos.x.toString() + 'px';
			
			dim2 = this.getSize();
			c.style.minWidth = (dim2.x - 4).toString() + 'px';
			
			c.style.display = 'block';
		});
		
		el.parentNode.addEvent('mouseleave', function(e){
			pos = $(this).getPosition();
			dim = this.getSize();
			
			c = this.children[1];
			c.style.display="none";
			c.style.top = (pos.y + dim.y).toString() + 'px';
			c.style.left = pos.x.toString() + 'px';
		});
	});
	
	$each($$('.subsubmenu'), function(el) {
		pos = $(el.parentNode).getPosition();
		ppos = $(el.parentNode.parentNode).getPosition();
		dim = el.parentNode.getSize();
		
		el.style.display="none";
		el.style.top = (pos.y - ppos.y).toString() + 'px';
		el.style.left = (dim.x).toString() + 'px';
		
		el.parentNode.addEvent('mouseenter', function(e){
			pos = $(this).getPosition();
			ppos = $(this.parentNode).getPosition();
			dim = this.getSize();
			
			c = this.children[1];
			c.style.top = (pos.y - ppos.y).toString() + 'px';
			c.style.left = (dim.x).toString() + 'px';
			
			dim2 = this.getSize();
			//c.style.minWidth = (dim2.x - 4).toString() + 'px';
			
			c.style.display = 'block';
		});
		
		el.parentNode.addEvent('mouseleave', function(e){
			pos = $(this).getPosition();
			dim = this.getSize();
			
			c = this.children[1];
			c.style.display="none";
			//c.style.top = (pos.y).toString() + 'px';
			//c.style.left = (pos.x + dim.x).toString() + 'px';
		});
	});
});

