var popups_list = new Hash();
var Popup = Class.create();
Popup.prototype = {
	initialize: function(element) {
		this.popup = element;
		this.bg='';
		this.opened = false;
		if (typeof($(this.popup.id+'-bg'))!='undefined') {
			this.bg = $(this.popup.id+'-bg');
		}

		//Esc
		Event.observe(document, 'keydown', function(event){
			if (event.keyCode == 27) {
				this.close();
			}
		}.bind(this));

		Event.observe(this.popup.select('.close')[0], 'click', function(event){
			this.close();
		}.bind(this));

		if (this.bg!='')
			Event.observe(this.bg, 'click', function(event){
				this.close();
			}.bind(this));

		this.open();
	},

	myTranslate: function(txt) {
		if (typeof(Translator) != 'undefined')
			return Translator.translate(txt);
		else
			return txt;
	},

	open: function(){

		Effect.Appear(this.popup);
		if (!this.opened) {
			if (this.bg!='')
				Effect.Appear(this.bg);
		}
	},

	close: function() {
		Effect.Fade(this.popup);
		if (this.bg!='')
			Effect.Fade(this.bg);
		this.opened = false;
	}
};
function loadPopup(element) {
	if (typeof(popups_list.get(element.id))=='undefined') {
		popups_list.set(element.id,new Popup(element));
	} else {
		popups_list.get(element.id).open();
	}
}
