// JavaScript Document
var Spinner=Class({
	Implements: [Options, Events],
	options: {
		container: null,
		tagname: "img",
		fadespeed: 2.5,
		spinspeed: 5
	},
	initialize: function(options) {
		this.setOptions(options);
		this.container=$E(this.options.container);
		if (this.container) {
			this.items=this.container.getElements(this.options.tagname);
			this.items.each(function(i) {
				 i.setStyle("display","none");
			 });
			this.currentIndex=0;
			if (this.items.length>0) {
				this.spin();
			}
		}
	},
	spin:function() {
		var currentSlide=this.items[this.currentIndex];
		currentSlide.set("tween",{
		   duration:this.options.fadespeed * 1000
		   });

		currentSlide.fade("out");
		this.currentIndex+=1;
		if (this.currentIndex>=this.items.length) {this.currentIndex=0;}
		currentSlide=this.items[this.currentIndex];
		currentSlide.set("tween",{
		   duration:this.options.fadespeed * 1000
		   });

		currentSlide.set("opacity",0).setStyles({display:"block", position: "absolute"}).inject(this.container);
		currentSlide.fade("in");
		this.spin.delay(this.options.spinspeed*1000,this);
	}
});
