var Notifier = new Class({
	Implements: [Options],
	options: {
		delay: 5000,
		duration: 500,
		position: {x: 'center', y: '0px'},
		width: 300,
		className: null
	},
	el: null,
	self: this,
	
	initialize: function(options) {
		this.setOptions(options);
		this.build();
	},
	
	build: function() {
		this.el = new Element('ul', {
			id: 'notify_' + new Date().getTime(),
			styles: this.options.className == null ? {
				'position': 'fixed',
				'left': this.getX(),
				'top': this.options.position.y,
				'width': this.options.width,
				'margin': '0px',
				'padding': '0px',
				'list-style': 'none'
			} : null,
			'class': this.options.className
		});
		$$('body').grab(this.el);
	},
	
	getX: function() {
		switch(this.options.position.x) {
			case 'center':
				viewport = document.getCoordinates();
				x = (viewport.width / 2) - (this.options.width / 2);
				return x;
				break;
			case 'left':
				x = 100;
				return x;
				break;
			case 'right':
				viewport = document.getCoordinates();
				x = viewport.width - 100 - (this.options.width);
				return x;
				break;

			default:
				return this.options.position.x;
				break;
		};
	},
	
	notify: function(message, delay, duration) {
		message = new Element('li',{
			html: message,
			id: 'notify_' + new Date().getTime(),
			styles: this.options.className == null ? {
				'background-color': '#eee',
				'margin-bottom': '5px',
				'padding': '5px',
				'opacity': '0'
			} : { 'opacity': '0'}
			
		});
		op = this.options
		fx = new Fx.Morph(message, {
			duration: this.options.duration
		}).start({
			'opacity': [0,1]
		}).chain(function() {
			this.start.delay(op.delay, this, {
				'opacity': [1,0]
			});
		}).chain(function(){
			message.dispose();
		});
		
		this.el.grab(message);
		
	}
});
