var Popup = {
	background: null,
	current: null
};
Popup.initialize = function() {
	$$('div.popup').each(function(element) {
		element.inject(document.body);
		element.setStyles({
			opacity: 0,
			position: 'absolute',
			display: 'none',
			backgroundColor: '#ffffff',
			zIndex: 10
		});
	});
	this.background = new Element('div', {
		styles: {
			position: 'fixed',
			top:0,
			left:0,
			width: '100%',
			height: '100%',
			display: 'none',
			opacity: 0,
			backgroundColor: '#000000'
		}
	});
	this.background.addEvent('click', function() {
		Popup.hide();									
	});
	document.body.appendChild(this.background);
}
Popup.popup = function(name) {
	this.current = $(name);
	this.background.setStyle('display', 'block');
	new Fx.Morph(this.background).start({
		opacity: 0.3
	});
	$(name).setStyles({
		display: 'block'
	});
	$(name).setStyles({
		left: (window.getSize().x - $(name).getSize().x) / 2,
		top:  window.getScroll().y + ((window.getSize().y - $(name).getSize().y) / 2)
	});
	new Fx.Morph($(name)).start({
		opacity: 1
	});
}
Popup.hide = function() {
	new Fx.Morph(this.background).start({
		opacity: 0.0
	}).chain(function() {
		this.background.setStyle('display', 'none');
	}.bind(this));
	new Fx.Morph(this.current).start({
		opacity: 0
	}).chain(function() {
		this.current.setStyle('display', 'block');
	}.bind(this));
}
