var OM_mooMsgBox = new Class({
	Implements: [Options, Events],
	options: {
		boxElement: null,
		closeButton: null,
		animParams: {
			duration: 500,
			transition: Fx.Transitions.Quad.easeInOut
		},
		cookieParams: {
			name: '',
			value: '',
			duration: 0,
			domain: '',
			path: '/'
		}
	},
	initialize: function(options){
		this.cookie = null;
		this.setOptions(options);
		window.addEvent('domready', this.domReady.bind(this));
	},
	domReady: function(){
		this.boxElement = $(this.options.boxElement);
		this.closeButton = $$(this.options.closeButton);
		if($defined(this.boxElement)&&$defined(this.closeButton)){
			this.attachCloseEvent();
		};
	},
	attachCloseEvent: function(){
		this.closeButton.addEvent('click', function(event){
			event.stop();
			this.fireCloseEvent();
		}.bind(this));
	},
	fireCloseEvent: function(){
		var chainParams = this.options.animParams;
		var eventChain = new Chain();
		
		this.boxElement.set('morph', {
			duration: chainParams.duration,
			transition: chainParams.transition,
			onComplete: function(){ eventChain.callChain(); }
		});
		
		eventChain.chain(
			function(){ this.boxElement.morph({'opacity': 0}); }.bind(this),
			function(){ var boxHeight = this.boxElement.getSize().y; this.boxElement.setStyle('height', boxHeight); this.boxElement.morph({'height': '0px'}); }.bind(this),
			function(){ this.boxElement.destroy(); eventChain.callChain(); }.bind(this),
			function(){ this.handleCookie(); }.bind(this)
		);
		
		eventChain.callChain();
	},
	handleCookie: function(){
		this.cookie = this.options.cookieParams;
		var localCookie = Cookie.write(this.cookie.name, this.cookie.value, {
			duration: this.cookie.duration,
			domain: this.cookie.domain,
			path: this.cookie.path
		});
	}
});
