1 // ------------------------------------------------------------------
2 // AUTHOR: Ryan J. Salva
3 // MODIFIED: December 22, 2007
6 // creates a single, rotating image on a page
9 // <div id="Container">
10 // <img src="1.jpg" /><img src="2.jpg" /><img src="3.gif" />
12 // <script type="text/javascript">
13 // window.addEvent('domready',function() {
14 // var f = new Fader('Container');
20 var Fader = new Class({
26 onComplete: Class.empty,
29 initialize: function(container,options) {
30 this.setOptions(options);
31 this.container = $(container);
32 this.imgs = this.container.getElements('img');
34 'position':'absolute',
39 this.imgs[0].setStyle('opacity',1);
40 this.el = new Element('div',{'styles': {
43 this.el.injectInside(this.container);
44 this.el.adopt(this.imgs);
49 this.periodical = this.show.bind(this).periodical(this.options.pause);
52 $clear(this.periodical);
55 if (!this.options.loop && this.next==this.imgs.length-1) this.stop();
56 this.next = (this.next==this.imgs.length-1)?0:this.next+1;
57 var prev = (this.next==0)?this.imgs.length-1:this.next-1;
59 this.imgs[this.next].fade('in');
60 this.imgs[prev].fade('out');