/* ==== slider namespace ==== */ var slider = function() { /* ==== private methods ==== */ function getelementsbyclass(object, tag, classname) { var o = object.getelementsbytagname(tag); for ( var i = 0, n = o.length, ret = []; i < n; i++) { if (o[i].classname == classname) ret.push(o[i]); } if (ret.length == 1) ret = ret[0]; return ret; } function setopacity (obj,o) { if (obj.filters) obj.filters.alpha.opacity = math.round(o); else obj.style.opacity = 100; } /* ==== slider constructor ==== */ function slider(ocont, speed, iw, ih, op) { this.slides = []; this.over = false; this.s = this.s0 = speed; this.iw = iw; this.ih = ih; this.op = op; this.oc = document.getelementbyid(ocont); this.frm = getelementsbyclass(this.oc, 'div', 'slide'); this.nf = this.frm.length; this.resize(); for (var i = 0; i < this.nf; i++) { this.slides[i] = new slide(this, i); } this.oc.parent = this; this.view = this.slides[0]; this.z = this.mx; /* ==== on mouse out event ==== */ this.oc.onmouseout = function () { this.parent.mouseout(); return false; } } slider.prototype = { /* ==== animation loop ==== */ run : function () { this.z += this.over ? (this.mn - this.z) * .5 : (this.mx - this.z) * .5; this.view.calc(); var i = this.nf; while (i--) this.slides[i].move(); }, /* ==== resize ==== */ resize : function () { this.wh = this.oc.clientwidth; this.ht = this.oc.clientheight; this.wr = this.wh * this.iw; this.r = this.ht / this.wr; this.mx = this.wh / this.nf; this.mn = (this.wh * (1 - this.iw)) / (this.nf - 1); }, /* ==== rest ==== */ mouseout : function () { this.over = false; setopacity(this.view.img, this.op); } } /* ==== slide constructor ==== */ slide = function (parent, n) { this.parent = parent; this.n = n; this.x0 = this.x1 = n * parent.mx; this.v = 0; this.loaded = false; this.cpt = 0; this.start = new date(); this.obj = parent.frm[n]; this.txt = getelementsbyclass(this.obj, 'div', 'text'); this.img = getelementsbyclass(this.obj, 'img', 'diapo'); this.bkg = document.createelement('div'); this.bkg.classname = 'backgroundtext'; this.obj.insertbefore(this.bkg, this.txt); if (n == 0) this.obj.style.borderleft = 'none'; this.obj.style.left = math.floor(this.x0) + 'px'; setopacity(this.img, parent.op); /* ==== mouse events ==== */ this.obj.parent = this; this.obj.onmouseover = function() { this.parent.over(); return false; } } slide.prototype = { /* ==== target positions ==== */ calc : function() { var that = this.parent; // left slides for (var i = 0; i <= this.n; i++) { that.slides[i].x1 = i * that.z; } // right slides for (var i = this.n + 1; i < that.nf; i++) { that.slides[i].x1 = that.wh - (that.nf - i) * that.z; } }, /* ==== html animation : move slides ==== */ move : function() { var that = this.parent; var s = (this.x1 - this.x0) / that.s; /* ==== lateral slide ==== */ if (this.n && math.abs(s) > .5) { this.obj.style.left = math.floor(this.x0 += s) + 'px'; } /* ==== vertical text ==== */ var v = (this.n < that.nf - 1) ? that.slides[this.n + 1].x0 - this.x0 : that.wh - this.x0; if (math.abs(v - this.v) > .5) { this.bkg.style.top = this.txt.style.top = math.floor(2 + that.ht - (v - that.z) * that.ih * that.r) + 'px'; this.v = v; this.cpt++; } else { if (!this.pro) { /* ==== adjust speed ==== */ this.pro = true; var tps = new date() - this.start; if(this.cpt > 1) { that.s = math.max(2, (28 / (tps / this.cpt)) * that.s0); } } } if (!this.loaded) { if (this.img.complete) { this.img.style.visibility = 'visible'; this.loaded = true; } } }, /* ==== light ==== */ over : function () { this.parent.resize(); this.parent.over = true; setopacity(this.parent.view.img, this.parent.op); this.parent.view = this; this.start = new date(); this.cpt = 0; this.pro = false; this.calc(); setopacity(this.img, 100); } } /* ==== public method - script initialization ==== */ return { init : function() { // create instances of sliders here // parameters : htmlcontainer name, speed (2 fast - 20 slow), horizontal ratio, vertical text ratio, opacity this.s1 = new slider("slider", 12, 1.84/3, 1/3.2, 70); setinterval("slider.s1.run();", 16); } } }();