var Openmoomenu = new Class ({
	Implements : Options,

	options : {
		delay: 400,
		animate: {
			props: ['opacity', 'width', 'height'],
			options: {
				duration:500,
				fps: 100,
				transition: 'sine:out'
			}
		}
	},
	
	initialize: function(container, options) {
		this.setOptions(options);
		this.container = document.getElement(container);
		this.titles = this.container.getChildren(); 
		this.open = '';
		this.titles.each(function(title){
			if (title.getElement('ul')) {
				title.getElement('ul').setStyle('overflow', 'hidden');
				
				var width = title.getElement('ul').getStyle('width')
				var height =  title.getElement('ul').getStyle('height');
				if (height == "auto") {
					var padding = parseInt(title.getElement('ul').getStyle('padding-top')) + parseInt(title.getElement('ul').getStyle('padding-bottom'));
					var border = parseInt(title.getElement('ul').getStyle('border-top')) + parseInt(title.getElement('ul').getStyle('border-bottom'));
					var height = title.getElement('ul').getSize().y;
					height = height - padding - border;
				}
				
				title.store('w',width);
				title.store('h',height);
				
				title.addEvent('mouseenter',function(title){
					$clear(this.remove_d);
					if (!title.hasClass('sfhover')) {
						if (this.open != ''){
							if (this.open.getElement('ul'))
								this.open.removeClass('sfhover'); 
							this.open = '';
						}
						this.menu = title.getElement('ul');
						this.open = title;
						this.transitions = {};
						this.options.animate.props.each(function (prop) {
							this.menu.setStyle(prop,0);
							if (prop == 'opacity')
								this.transitions.opacity = 1; 
							if (prop == 'width')
								this.transitions.width = title.retrieve('w'); 
							if (prop == 'height')
								this.transitions.height = title.retrieve('h'); 
						},this); 
						title.addClass('sfhover');
						this.menu.set('morph',this.options.animate.options);
						this.menu.get('morph').start(this.transitions);
					}
				}.bind(this,title));
				
				title.addEvent('mouseleave',function(title){
					this.remove_d = (function(){title.removeClass('sfhover'); this.open = '';}).delay(this.options.delay);
				}.bind(this,title)); 
			}
			else {
				title.addClass('');
				title.addEvent('mouseenter',function(title){
					$clear(this.remove_d);
					if (this.open != title) {
						if (this.open != ''){
							if (this.open.getElement('ul'))
								this.open.removeClass('sfhover'); 
							this.open = '';
						}
					}
					this.open = title;
				}.bind(this,title));
			}
		},this);
			
	}
});



