/* moo.fx, simple effects library built with prototype.js (http://prototype.conio.net). by valerio proietti (http://mad4milk.net) mit-style license. for more info (http://moofx.mad4milk.net). sunday, march 05, 2006 v 1.2.3 */ var fx = new object(); //base fx.base = function(){}; fx.base.prototype = { setoptions: function(options) { this.options = { duration: 500, oncomplete: '', transition: fx.sinoidal } object.extend(this.options, options || {}); }, step: function() { var time = (new date).gettime(); if (time >= this.options.duration+this.starttime) { this.now = this.to; clearinterval (this.timer); this.timer = null; if (this.options.oncomplete) settimeout(this.options.oncomplete.bind(this), 10); } else { var tpos = (time - this.starttime) / (this.options.duration); this.now = this.options.transition(tpos) * (this.to-this.from) + this.from; } this.increase(); }, custom: function(from, to) { if (this.timer != null) return; this.from = from; this.to = to; this.starttime = (new date).gettime(); this.timer = setinterval (this.step.bind(this), 13); }, hide: function() { this.now = 0; this.increase(); }, cleartimer: function() { clearinterval(this.timer); this.timer = null; } } //stretchers fx.layout = class.create(); fx.layout.prototype = object.extend(new fx.base(), { initialize: function(el, options) { this.el = $(el); this.el.style.overflow = "hidden"; this.iniwidth = this.el.offsetwidth; this.iniheight = this.el.offsetheight; this.setoptions(options); } }); fx.height = class.create(); object.extend(object.extend(fx.height.prototype, fx.layout.prototype), { increase: function() { this.el.style.height = this.now + "px"; }, toggle: function() { if (this.el.offsetheight > 0) this.custom(this.el.offsetheight, 0); else this.custom(0, this.el.scrollheight); } }); fx.width = class.create(); object.extend(object.extend(fx.width.prototype, fx.layout.prototype), { increase: function() { this.el.style.width = this.now + "px"; }, toggle: function(){ if (this.el.offsetwidth > 0) this.custom(this.el.offsetwidth, 0); else this.custom(0, this.iniwidth); } }); //fader fx.opacity = class.create(); fx.opacity.prototype = object.extend(new fx.base(), { initialize: function(el, options) { this.el = $(el); this.now = 1; this.increase(); this.setoptions(options); }, increase: function() { if (this.now == 1 && (/firefox/.test(navigator.useragent))) this.now = 0.9999; this.setopacity(this.now); }, setopacity: function(opacity) { if (opacity == 0 && this.el.style.visibility != "hidden") this.el.style.visibility = "hidden"; else if (this.el.style.visibility != "visible") this.el.style.visibility = "visible"; if (window.activexobject) this.el.style.filter = "alpha(opacity=" + opacity*100 + ")"; this.el.style.opacity = opacity; }, toggle: function() { if (this.now > 0) this.custom(1, 0); else this.custom(0, 1); } }); //transitions fx.sinoidal = function(pos){ return ((-math.cos(pos*math.pi)/2) + 0.5); //this transition is from script.aculo.us } fx.linear = function(pos){ return pos; } fx.cubic = function(pos){ return math.pow(pos, 3); } fx.circ = function(pos){ return math.sqrt(pos); }