var PopUp = { 'layer' : Class.create(), 'window' : Class.create(), 'getWindowHeight' : function() { var h = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0; return h; }, 'getWindowWidth' : function() { var w = self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0; return w; } } PopUp.layer.prototype = { 'initialize' : function(element,options) { var element = this.element = $(element).hide(); element.setStyle({position:'absolute'}); this.delay = (options.delay) ? options.delay*1000 : 0; this.duration = (options.duration) ? options.duration*1000 : null; if(options.style) element.setStyle(options.style); if(options.className) element.className = element.classNames().toArray().concat(options.className).join(" "); this.setHandlers(options); this.setDimension(options); this.setPosition(options); this.setDepth(options); if(this.delay) setTimeout(this.popUp.bind(this),this.delay); else this.popUp(); Event.observe(window,'resize',this.setPosition.bind(this,options)); }, //------------------------------------------------------------------ 'popUp' : function() { this.handleEvent('onPopUp'); this.element.show(); if(this.duration) setTimeout(this.popOut.bind(this),this.duration); return true; }, //------------------------------------------------------------------ 'popOut' : function() { this.handleEvent('onPopOut'); this.element.hide(); return true; }, //------------------------------------------------------------------ 'popClose' : function() { this.handleEvent('onClose'); this.element.hide(); return true; }, //------------------------------------------------------------------ 'handleEvent' : function(evt) { if(this[evt]) this[evt](this.element); }, //------------------------------------------------------------------ 'setHandlers' : function(opt) { this.onPopUp = (opt.onPopUp) ? opt.onPopUp : null; this.onPopOut = (opt.onPopOut) ? opt.onPopOut : null; this.onClose = (opt.onClose) ? opt.onClose : null; if(opt.closeButton) $(opt.closeButton).observe('click',this.popClose.bind(this)); if(opt.linkButton && opt.url) $(opt.linkButton).observe('click',this.openUrl.bind(this,opt.url)); else if(opt.url) this.element.observe('click',this.openUrl.bind(this,opt.url)); }, //------------------------------------------------------------------ 'openUrl' : function(u) { new PopUp.window(u,"",{}); }, //------------------------------------------------------------------ 'setDimension' : function(opt) { var elm = this.element; if(opt.width) (typeof(opt.width)=='number') ? elm.setStyle({width:opt.width+'px'}) : elm.setStyle({width:opt.width}); if(opt.height) (typeof(opt.height)=='number') ? elm.setStyle({height:opt.height+'px'}) : elm.setStyle({height:opt.height}); return true }, //------------------------------------------------------------------ 'setPosition' : function(opt) { var elm = this.element; if(opt.x) { if(typeof(opt.x)=='string') { switch(opt.x) { case 'left' : elm.setStyle({left:'0px',right:'auto'}); break; case 'right' : elm.setStyle({right:'0px',left:'auto'}); break; case 'center' : elm.setStyle({left:(PopUp.getWindowWidth()-elm.getWidth())/2+'px',right:'auto'}); break; default : elm.setStyle({left:opt.x}); } } else if(typeof(opt.x)=='number') elm.setStyle({left:opt.x+'px'}); } if(opt.y) { if(typeof(opt.y)=='string') { switch(opt.y) { case 'top' : elm.setStyle({top:'0px',bottom:'auto'}); break; case 'bottom' : elm.setStyle({bottom:'0px',top:'auto'}); break; case 'middle' : elm.setStyle({top:(PopUp.getWindowHeight()-elm.getHeight())/2+'px',bottom:'auto'}); break; default : elm.setStyle({top:opt.y}); } } else if(typeof(opt.y)=='number') elm.setStyle({top:opt.y+'px'}); } return true; }, //------------------------------------------------------------------ 'setDepth' : function(opt) { var elm = this.element; if(opt.z) elm.setStyle({zIndex:opt.z}); else if(typeof(opt)=='number') elm.setStyle({zIndex:opt}); else elm.setStyle({zIndex:2000}); return true; } }