//# This code is released under the MIT License
//# (c) 2006 e-TF1, (c) 2006 Rémi Lanvin, (c) 2006 Yannick Croissant
//# Based on the MooTools framework (c) 2006 Valerio Proietti, <http://mad4milk.net>, MIT-style license
var Overlay={};
Overlay=new Class({
getOptions:function(){
return{
fxDuration:150,
maxOpacity:.5,
className:'overlay',
zIndex:10000
};
},
initialize:function(options){
this.element=this.element || null;
this.options=Object.extend(this.getOptions(),options ||{});
this.setOverlay();
},
setOverlay:function(){
this.overlay=new Element('div').setStyles({
display:'none',
position:'absolute',
top:0,
left:0,
'z-index':this.options.zIndex
}).addClass(this.options.className).injectInside(document.body);
this.overlay.addEvent('click',this.hideFn.bind(this));
this.overlayFx=this.overlay.effect('opacity',{
duration:this.options.fxDuration,
wait:false,
onComplete:this.callBack.bind(this)
}).hide();
},
hideFn:function(e){
this.hide();
new Event(e).stop();
},
zIndex:function(){
return this.overlay.getStyle('z-index').toInt()|| 0;
},
show:function(el){
if(this.showed)return;
this.showed=true;
this.el=$(el).setStyles({
position:'absolute',
'z-index': this.zIndex() + 1 // positionne l'élément un cran au dessus du fond
});
this.overlay.setStyles({
display:'block',
width:Window.getWidth()+'px',
height:Math.max(Window.getScrollHeight(),Window.getHeight())+'px'
});
this.overlayFx.start(0,this.options.maxOpacity);
this.showHide(1);
},
hide:function(){
this.showed=false;
this.el.setStyle('display','none');
this.overlayFx.start(this.options.maxOpacity,0);
},
showEl:function(el){
el.setStyles({
display:'block',
visibility:'hidden'
}).setStyles({
visibility:'visible',
top:((Window.getHeight()-el.offsetHeight)/2)+Window.getScrollTop()+'px',
left:((Window.getWidth()-el.offsetWidth)/2)+'px'
});
},
hideEl:function(){
this.overlay.setStyle('display','none');
this.showHide();
},
callBack:function(){
if(this.showed)this.showEl(this.el);
else this.hideEl();
},
showHide:function(open){
var els=$$('object, embed' + (window.ie && !window.ie7 ? ',select' : ''));
$A(els).each(function(el){el.style.visibility=open?'hidden' : '';});
}
});
