
/**
* Extend the Element object.
*/

Element.implement({
	wrap: function() {
		if (this.wrapper == null) {
			this.wrapper = new Element('div', {'class': 'wrapper'});
		
			this.wrapper.inject(this, 'before');
			this.wrapper.grab(this);

			this.wrapper.setStyles({
				'overflow': 'hidden'
			});
		}

		return this.wrapper;
	},

	slideToggle: function(min, max) {
		var wrapper = this.wrap();

		if (wrapper.getSize().y == 0)
			this.slideDown();
		else
			this.slideUp();
	},

	slideUp: function(min) {
		var wrapper = this.wrap();

		wrapper.morph({
			'height': min ? min : 0,
//			'opacity': 0
		});
	},

	slideDown: function(max) {
		var wrapper = this.wrap();

		wrapper.get('morph').addEvent('complete',	function() {
				wrapper.get('morph').removeEvents("complete");
				wrapper.setStyle('height', null);
		});
		 
		wrapper.setStyle('height', 0).morph({
			'height': max ? max : this.getSize().y,
//					'opacity': 1
		});
	}
});


