var cdrMenu = {

	menu: function() {
		$$('.submenu').setStyle('display', 'none');
			
		$('submenu')
			.setStyles({ top: -50, opacity: 0, display: 'block', visibility: 'visible' })
			.addEvents({
				'mouseenter': cdrMenu.keep,
				'mouseleave': cdrMenu.hide
			});
			
		$$('#menu li').setStyle('cursor', 'default').addEvents({
			'mouseenter': function() {
				cdrMenu.keep();
				var that = this;
				var newLeft = this.getCoordinates().left - 10;
				if ($('submenu').getStyle('left').toInt() === newLeft && $('submenu').getStyle('opacity').toInt() === 1) return;
				
				if ($('submenu').getStyle('opacity').toInt() === 0) {
					$('submenu-content').setStyle('top', -100);
					cdrMenu.show(that, newLeft);
				} else {
					$('submenu-content').set('tween', { duration: 300, onComplete: function() {
						cdrMenu.show(that, newLeft);
					}}).tween('top', 0, -100);
				}
			},
			'mouseleave': cdrMenu.hide
		});
	},

	hide: function() {
		cdrMenu.timeout = (function() {
			$('submenu').morph({ 'opacity': 0, 'top': -100 });
		}).delay(750);
	},

	keep: function() {
		$clear(cdrMenu.timeout);
	},

	show: function(that, newLeft) {
		if ($('submenu-content').getStyle('top').toInt() < 0) {
			$('submenu-content').set('html', that.getElement('.submenu').get('html'));
			
			$$('#submenu-content div').addEvents({
		
				'mouseenter': function() {
					this.set('tween', { duration: 300 }).tween('background-color', '#FFFFFF');
				},
				'mouseleave': function() {
					this.set('tween', { duration: 300 }).tween('background-color', '#DDDDDD');
				}
			
			});
		
			var contentHeight = 24 * $('submenu').getElements('a').length;
			
			if ($('submenu').getStyle('opacity').toInt() === 0) {
				$('submenu').setStyle('left', newLeft);
			}
			
			$('submenu').morph({
					'top': 0,
					'opacity': 1,
					'height': contentHeight,
					'left': newLeft
				});
			$('submenu-content').tween('top', -100, 0);
		}
	}
}
