// (c) 2001 - 2007, EIKONA AG, it.x informationssysteme gmbh, Alle Rechte vorbehalten.

if(!TextSlider) {

	var TextSlider = Class.create({
		
		initialize: function(eContainer, options) {
			
			this.options = Object.extend({
				'minHeight': 10,
				'maxHeight': 100,
				'link': '',
				'target': '_self',
				'onStart': Prototype.emptyFunction,
				'onOpen': Prototype.emptyFunction,
				'afterOpen': Prototype.emptyFunction,
				'onClose': Prototype.emptyFunction,
				'afterClose': Prototype.emptyFunction,
				'duration': 0.1
				}, options || {});
			
			this.container = $(eContainer) || new Element('div');
			
			this.container.observe('mouseover', this.open.bindAsEventListener(this));
			this.container.observe('mouseout', this.close.bindAsEventListener(this));
			if (this.options.link != '')
				this.container.observe('click', this.openLink.bindAsEventListener(this));
			
			this.state = 'closed';
			
			this.options.onStart();
			
			this.effect = new Effect.Morph(this.container, {
				'duration': 0,
				'style': 'top: '.concat(this.container.getHeight() - this.options.minHeight, 'pt'),
				'afterFinish': function(){ this.state = 'closed'; }.bind(this)
				});
		},
		
		
		open: function(event) {
			Event.stop(event);
			
			if (this.effect)
				this.effect.cancel();
			
			this.options.onOpen();
			
			this.effect = new Effect.Morph(this.container, {
				'duration': this.options.duration,
				'style': 'top: '.concat(this.container.getHeight() - this.options.maxHeight, 'pt'),
				'afterFinish': function(){ this.state = 'open'; this.options.afterOpen(); }.bind(this)
				});
		},
		
		
		close: function(event) {
			Event.stop(event);
			
			if (this.effect)
				this.effect.cancel();
			
			this.options.onClose();
			
			this.effect = new Effect.Morph(this.container, {
				'duration': this.options.duration * 3,
				'style': 'top: '.concat(this.container.getHeight() - this.options.minHeight, 'pt'),
				'transition': Effect.Transitions.spring,
				'afterFinish': function(){ this.state = 'closed'; this.options.afterClose(); }.bind(this) });
		},
		
		
		openLink: function() {
			if (this.options.target.empty())
				this.options.target = '_self';
			
			window.open(this.options.link, this.options.target);
		},
		
		
		isOpen: function() {
			return this.state == 'open';
		}
	});
}
