if(!Nibynic) {
	var Nibynic = { };
}

Nibynic.Notice = Class.create({
	defaultOptions: {
		type: 'notice',
		duration: 10
	},
	
	initialize: function(message, options) {
		this.message = message;
		this.options = Object.extend(Object.extend({ }, this.defaultOptions), options || { });
		
		this.show();
	},
	
	createElement: function() {
		this.element = new Element('li', {
			className: this.options.type,
			style: 'display: none'
		});
		
		this.close = new Element('a', {
			className: 'close',
			href: '#'
		});
		this.close.observe('click', function(event) {
			this.hide();
			event.stop();
		}.bind(this));

		this.element.update(this.message);
		this.element.insert(this.close);
		Nibynic.Notice.container.insert(this.element);
		
		return this.element;
	},
	
	show: function() {
		if(!this.element) {
			this.createElement();
		}
		
		new Nibynic.Notice.options.showEffect.effect(this.element, Nibynic.Notice.options.showEffect.options);
		if(this.options.duration > 0 && !this.hidden) {
			this.timeoutId = setTimeout(this.hide.bind(this), this.options.duration * 1000);
		}
	},
	
	hide: function() {
		new Nibynic.Notice.options.hideEffect.effect(this.element, Nibynic.Notice.options.hideEffect.options);
		this.hidden = true;
	}
});

Nibynic.Notice.defaultOptions = {
	showEffect: { effect: Effect.Appear, options: { } },
	hideEffect: { effect: Effect.Fade, options: { } }
}

Nibynic.Notice.init = function(container, messages, options) {
	this.container = $(container);
	this.options = Object.extend(Object.extend({ }, this.defaultOptions), options || { });
	
	if(Object.isArray(messages)) {
		messages.each(function(message) {
			this.show(message);
		}.bind(this))
	}
}

Nibynic.Notice.show = function(message, options) {
	new Nibynic.Notice(message, options)
}

Nibynic.Notice.error = function(message, options) {
	options = Object.extend(options || { }, { type: 'error' });
	new Nibynic.Notice(message, options);
}

Nibynic.Notice.warning = function(message, options) {
	options = Object.extend(options || { }, { type: 'warning' });
	new Nibynic.Notice(message, options);
}
