var SlideShow = new Class
({
 options:
 {
 format: 'click',
 duration: 200,
 spacer: '/plugins/editors/tinymce/jscripts/tiny_mce/plugins/inlinepopups/images/spacer.gif'
 },

 initialize: function(el, data, options)
 {
 this.setOptions(options);

 this.images = data.images;
 this.link = data.link;

 this.el = new Element
 (
 'div',
 {
 'class': this.options.format
 }
 ).injectInside(el);

 this.frame = new Element
 (
 'div',
 {
 'class': 'frame'
 }
 ).injectInside(this.el);

 this.bound =
 {
 load: this.load.bind(this),
 launch: this.launch.bind(this)
 };

 this.last = new Element
 (
 'img',
 {
 'src' : this.options.spacer,
 'styles':
 {
 'opacity': 0
 }
 }
 ).injectInside(this.frame);

 this.image = new Element
 (
 'img',
 {
 'src' : this.options.spacer,
 'events':
 {
 'load': this.bound.load,
 'click': this.bound.launch
 }
 }
 ).injectInside(this.frame);

 this.fx = new Fx.Style
 (
 this.image,
 'opacity',
 {
 duration: this.options.duration
 }
 );

 this.lfx = new Fx.Style
 (
 this.last,
 'opacity',
 {
 duration: this.options.duration
 }
 );

 this.pagebar = new Element
 (
 'div',
 {
 'class': 'pagebar'
 }
 ).injectInside(this.el);

 this.disabled = this.images.length < 2;

 var next = new Element
 (
 'div',
 {
 'class': 'next' + ((this.disabled) ? ' disabled' : ''),
 'events':
 {
 'click': this.next.bind(this)
 }
 }
 ).injectInside(this.pagebar);
 next.setText('Next >');

 var prev = new Element
 (
 'div',
 {
 'class': 'prev' + ((this.disabled) ? ' disabled' : ''),
 'events':
 {
 'click': this.prev.bind(this)
 }
 }
 ).injectInside(this.pagebar);
 prev.setText('< Prev');

 if (window.ie6) this.show.delay(1, this, 0);
 else this.show(0);
 },

 next: function()
 {
 var i = this.offset + 1;
 if (i >= this.images.length) i = 0;
 this.show(i);
 },

 prev: function()
 {
 var i = this.offset - 1;
 if (i < 0) i = this.images.length - 1;
 this.show(i);
 },

 load: function()
 {
 this.fx.stop();
 this.lfx.stop();
 this.image.center();
 if (window.ie6) this.frame.setStyle('display', 'none').setStyle('display', 'block');
 this.fx.start(0, 1);
 this.lfx.start(1, 0);
 },

 show: function(i)
 {
 this.offset = i;

 this.last.setStyles(this.image.getStyles('position', 'top', 'left', 'width', 'height'));
 this.last.setStyle('opacity', 1);
 this.last.src = this.image.src;

 this.image.setStyle('opacity', 0);
 this.image.src = this.images[i];
 },

 launch: function(i)
 {
 switch (this.options.format)
 {
 default:
 window.location = this.link;
 break;
 }
 }
});

SlideShow.implement(new Events, new Options);