var	morphAction	= Class.create({

	options			: null,
	currentEffect	: null,
	elAnimate		: null,
	elAction		: null,
	state			: 0,

	initialize	: function(elAction, elAnimate, options) {

		elAction		= $(elAction);

		this.elAnimate	= $(elAnimate);
		this.elAction	= $(elAction);

		this.options = Object.extend({

			transitionOpen	: Effect.Transitions.spring,
			transitionClose	: Effect.Transitions.linear,
			durationOpen	: 1,
			durationClose	: 0.3,

			elementClose	: null,
			elementOpen		: null,

			eventClose		: 'mouseout',
			eventOpen		: 'mouseover',

			callBackOpen	: Prototype.emptyFunction,
			callBackClose	: Prototype.emptyFunction,
			
			styleOpen		: '',
			styleClose		: ''

		}, options || {});

		this.elAnimate.setStyle(this.options.styleClose);

		if(this.options.elementOpen !== null) {
			this.options.elementOpen.observe(this.options.eventOpen, this.open.bind(this));
		} else {
			elAction.observe(this.options.eventOpen, this.open.bind(this));
		}

		if(this.options.elementClose !== null) {
			this.options.elementClose.observe(this.options.eventClose, this.close.bind(this));
		} else {
			elAction.observe(this.options.eventClose, this.close.bind(this));
		}

	},

	open		: function() {

		if( this.options.eventOpen !== this.options.eventClose || this.state == 0) {
			if(this.currentEffect != null) {
				this.currentEffect.cancel();
			}

			this.currentEffect	= new Effect.Morph(this.elAnimate,
					{
						duration: this.options.durationOpen,
						style: this.options.styleOpen,
						transition: this.options.transitionOpen,
						afterFinish: function(){this.currentEffect = null; this.state = 1;}.bind(this)
					}
				);

			this.options.callBackOpen.bind(this)();
		}

	},

	close		: function() {

		if( this.options.eventOpen !== this.options.eventClose || this.state == 1) {
			if(this.currentEffect != null) {
				this.currentEffect.cancel();
			}

			this.currentEffect	= new Effect.Morph(this.elAnimate,
					{
						duration: this.options.durationClose,
						style: this.options.styleClose,
						transition: this.options.transitionClose,
						afterFinish: function(){this.currentEffect = null; this.state = 0;}.bind(this)
					}
				);

			this.options.callBackClose.bind(this)();
		}
	}

});


