
var SlideMenu = new Class({
	Implements: Options,
	trigger: null,
	target: null,
	slideFx: null,
	fadeFx: null,
	state: 'closed',
	options: {
		duration: 250,
		link: 'cancel',
		mode: 'vertical'
	},
	initialize: function(trigger, options) {
		this.setOptions();
		this.trigger = $(trigger);
		var target = this.trigger ? this.trigger.get('href') : '';
		target = target.indexOf('#') == 0 ? target.replace(/^#/, '') : '';
		this.target = $(target);
		if (!this.trigger || !this.target) {
			return;
		}
		this.prepare();
	},
	prepare: function() {
		this.slideFx = new Fx.Slide(this.target, {
			duration: this.options.duration,
			link: this.options.link,
			mode: this.options.mode
		});
		this.fadeFx = new Fx.Tween(this.target, {
			duration: this.options.duration,
			link: this.options.link,
			property: 'opacity'
		});
		this.slideFx.hide();
		this.fadeFx.set(0);
		this.trigger.getParent().addEvent('mouseenter', function() {
			this.trigger.getParent().addClass('hover');
			this.open();
		}.bindWithEvent(this));
		this.trigger.getParent().addEvent('mouseleave', function() {
			this.trigger.getParent().removeClass('hover');
			this.close();
		}.bindWithEvent(this));
		this.trigger.addEvent('click', function(evt) {
			evt.stop();
			this.state == 'closed' ? this.open() : this.close();
		}.bindWithEvent(this));
	},
	open: function() {
		this.slideFx.slideIn();
		this.fadeFx.start(1);
		this.state = 'open';
	},
	close: function() {
		this.slideFx.slideOut();
		this.fadeFx.start(0);
		this.state = 'closed';
	}
});
