function Opacity(elem, oTimer){ this.elem = elem; this.timer = Timer.detectTimer(oTimer); this.currentProcess = "fade"; this.onafterfade = new DOMEvent(); this.onafterappear = new DOMEvent(); this.onchange = new DOMEvent(); this.saveFloat = new Nums.SaveFloatPoint(); this.step = 5; this.IS_DOING = false; this.init(); } Opacity.prototype.init = function(){ this.initTimer(); if(Style._browser == "IE"){ this.elem.style.zoom = 1; } this.currentOpacity = Opacity.getOpacity(this.elem); this.currentVisibility = Opacity.getVisibility(this.elem); } Opacity.prototype.initTimer = function(){ if(this.timer._MUTUAL){ if(this.timer.registerOpacity){ this.timer.registerOpacity(this); }else{ Opacity.handleMutualTimer(this.timer); this.timer.registerOpacity(this); } }else{ this.timer.registerEvent({ name: "changer", func: this.change, oThis: this, args: [] }); } } Opacity.prototype.setOpacity = function(value){ if(typeof value == "undefined" || value > 100 || value < 0) return false; value = this.saveFloat.add(value); var styleValue = Opacity.styleStartText + (value / Opacity.styleCoeff) + Opacity.styleEndText; Style.setElementStyle(this.elem, Opacity.styleProperty, styleValue); this.currentOpacity = value; } Opacity.prototype.setVisible = function(){ Style.setElementStyle(this.elem, "visibility", "visible"); this.currentVisibility = "visible"; } Opacity.prototype.setHidden = function(){ Style.setElementStyle(this.elem, "visibility", "hidden"); this.currentVisibility = "hidden"; } Opacity.prototype.fade = function(value, sVal){ this.toValue = value ? value : 0; this.currentProcess = "fade"; this.step = sVal ? -Math.abs(sVal) : -Math.abs(this.step); this.IS_DOING = true; this.start(); } Opacity.prototype.appear = function(value, sVal){ this.toValue = value ? value : 100; this.currentProcess = "appear"; this.step = sVal ? Math.abs(sVal) : Math.abs(this.step); this.start(); } Opacity.prototype.change = function(){ var stop = false; var nextVal = this.currentOpacity + this.step; if(this.currentProcess == "fade"){ if(nextVal < this.toValue){ nextVal = this.toValue; stop = true; } }else if(this.currentProcess == "appear"){ if(nextVal > this.toValue){ nextVal = this.toValue; stop = true; } } this.setOpacity(nextVal); this.onchange.fire(); if(stop){ this.stop(); this["onafter" + this.currentProcess].fire(); } } Opacity.prototype.start = function(){ this.IS_DOING = true; if(!this.timer._MUTUAL){ this.timer.start(); } } Opacity.prototype.stop = function(){ this.IS_DOING = false; if(!this.timer._MUTUAL){ this.timer.clear(); } } Opacity.getOpacity = function(elem){ var currentOpacity = Style.getElementStyle(elem, Opacity.styleProperty); if(currentOpacity == ''){ currentOpacity = "100"; } var re = new RegExp(" ", "ig"); return Number(currentOpacity.replace(re, '').replace(Opacity.styleStartText, '').replace(Opacity.styleEndText, '')) * Opacity.styleCoeff; } Opacity.setDimensions = function(elem){ with(Style){ setElementStyle(elem, getDimensions(elem), null, true); } } Opacity.getVisibility = function(elem){ return Style.getElementStyle(elem, 'visibility') == 'inherit' ? 'visible' : Style.getElementStyle(elem, 'visibility'); } Opacity.NoGo = false; Opacity.styleStartText = ""; Opacity.styleEndText = ""; Opacity.styleCoeff = 100; Opacity.styleProperty = "opacity"; Opacity.slow = 3; if(Style._browser == "IE"){ Opacity.styleProperty = "filter"; Opacity.styleCoeff = 1; Opacity.styleStartText = "alpha(opacity="; Opacity.styleEndText = ")"; Opacity.slow = 1; }else if(Style._browser == "Gecko" || Style._browser == "Opera"){ //OK }else{ Opacity.NoGo = true; } Opacity.handleMutualTimer = function(oTimer){ oTimer.opacities = []; oTimer.registerOpacity = function(op){ this.opacities.push(op); } oTimer.registerEvent({ name: "opacity", func: function(){ this.opacities.each(function(op){ if(op.IS_DOING){ op.change(); } }) }, oThis: oTimer, args: [] }) } Opacity.handleOwnTimer = function(oTimer){ }