var NaSkroty = {

	duration: 0.3,
	lastElement: null,
	lastSource: null,
	running: false,

	toggle: function(id, source, duration)
	{
		if (this.running)
			return;

		if (typeof duration == 'undefined')
			duration = this.duration;

		var element = $(id);
		if (!Object.isElement(element))
			return;

		var _this = this;

		if (this.lastElement == null) {

			this.running = true;
			$(source).addClassName('enabled');
			effect = Effect.SlideDown(element, { 
				duration: duration, 
				afterFinish: function() {
					_this.lastSource = source;
					_this.lastElement = element;
					_this.running = false;
				},
				queue: { scope: 'NaSkroty' }
			});

		} else if (element == this.lastElement) {
			
			this.running = true;
			Effect.SlideUp(element, { 
				duration: duration, 
				afterFinish: function() {
					$(source).removeClassName('enabled');
					_this.lastSource = null;
					_this.lastElement = null;
					_this.running = false;
				},
				queue: { scope: 'NaSkroty' }
			});
			return;
		
		} else {
			
			this.running = true;
			Effect.SlideUp(this.lastElement, { 
				afterFinish: function() { 
					$(_this.lastSource).removeClassName('enabled');
					$(source).addClassName('enabled');
					Effect.SlideDown(element, { 
						duration: duration,
						afterFinish: function() {
							_this.lastSource = source;
							_this.lastElement = element;
							_this.running = false;
						},
						queue: { scope: 'NaSkroty' }
					});
				},
				duration: duration,
				queue: { scope: 'NaSkroty' }
			});
		}

	}

};
