Popups = new Class ({
	initialize: function(){
		this.popups = {};
	},

	createPopup: function(el,popupHeading){
		this.popup = {};
		this.popup.el = el | document.body;
		this.popup.popupBase = new Element('div',{'class':'popupBase'});
		this.popup.popupFrame = new Element('div',{'class':'popupFrame'}).inject(this.popup.popupBase);
		this.popup.heading = new Element('div',{'class':'popupHeading','text':popupHeading}).inject(this.popup.popupFrame);

		var totalWidth = window.innerWidth;
		var totalHeight = window.innerHeight;
		var hcenter = totalWidth / 2;
		var vcenter = totalHeight / 1.8;
		var mfwidth = /*size.x*/ (totalWidth / 100 * 30);
		var mfheight = /*size.y*/ (totalHeight / 100 * 20);

		this.popup.popupFrame.setStyle('width',mfwidth);
 		this.popup.popupFrame.setStyle('height',mfheight);
		this.popup.popupFrame.setStyle('left',(hcenter - (mfwidth / 2)));
		this.popup.popupFrame.setStyle('top',((vcenter / 1.1 ) - (mfheight / 2)));

		this.popup.popupBase.setStyle('width',totalWidth);
		this.popup.popupBase.setStyle('height',totalHeight);
		this.popup.popupBase.setStyle('left',0);
		this.popup.popupBase.setStyle('top',0);
		el.fade(0.5);
 		this.popup.el.disabled = true;
		this.popup.popupBase.inject(document.body);

		return this.popup;
	},

	showPopup: function (popup){
		var popup = eval("show" + popup + "();");
		popup.popupBase.inject(popup.el);
	},

	showLogin:function(popup){
//  		var popup = this.createPopup(el);
		
		var ltable = new Element('table',{ 'class':'login','border':'0','align':'center'});
		var namerow = new Element('tr').inject(ltable);
		var namecell1 = new Element('td',{'text':'Name','align':'right'}).inject(namerow);
		var namecell2 = new Element('td',{'align':'left'}).inject(namerow);
		var nameinput = new Element('input',{'id':'loginname','type':'text','maxsize':'50'}).inject(namecell2);

		var pwrow = new Element('tr').inject(ltable);
		var pwcell1 = new Element('td',{'text':'Password','align':'right'}).inject(pwrow);
		var pwcell2 = new Element('td',{'align':'left'}).inject(pwrow);
		var pwinput = new Element('input',{'type':'password','maxsize':'50'}).inject(pwcell2);

		nameinput.addEvent('keyup',function(ev){
			if((ev.code == 13) && (nameinput.value)){
				pwinput.focus();
			}
		}.bindWithEvent(this));

		pwinput.addEvent('keyup',function(ev){
			if(ev.code == 13){
				if(!nameinput.value || !pwinput.value )
					return false;

				popup.popupBase.fireEvent('loginRequest',"name=" + nameinput.value + "&pw=" + pwinput.value);
// 				this.loginRequest.send("name=" + nameinput.value + "&pw=" + pwinput.value);
			}
		}.bindWithEvent(this));

		this.lbox = new Element('div',{'class':'stdbox'});
		this.lbox.addEvent('loggedIn',function(resp){
				console.log("Event triggered: logged in" + resp);
 			});
		ltable.inject(popup.popupFrame);

// 		return ltable;

	},
});
