var toggleFader = new Class({
        options: {
			slides: [],
			startIndex: 0,
			nextBtn: false,
			onShow: Class.empty, //$empty in Mootools 1.2
			wrap: true
        },
        initialize: function(options){
			this.setOptions(options)
			this.slides = [];
			this.effects = [];
			this.addNextBtn($(this.options.nextBtn));
			this.addSlides(this.options.slides);
			if(this.slides.length) this.showSlide(this.options.startIndex);
        },
		addNextBtn: function(element){
			this.toggleBtn = $(element);
			this.toggleBtn.addEvent('click', this.cycleForward.bind(this));			
		},
		addSlides: function(slides){
			$$(slides).each(function(slide){
				this.slides.include($(slide));
				this.effects[this.slides.indexOf(slide)] = new Fx.Style(slide, 'opacity');
				//slide.addEvent('click', this.cycleForward.bind(this));
				slide.setStyle('display', 'none');
			}, this);
		},
		addSlide: function(slide){
			this.addSlides([slide]);
        },
		cycleForward: function(){
			if($chk(this.now) && this.now < this.slides.length-1) this.showSlide(this.now+1);
			else if (this.now && this.options.wrap) this.showSlide(0);
			else if(!$defined(this.now)) this.showSlide(this.options.startIndex);
		},
        cycleBack: function(){
			if(this.now > 0) this.showSlide(this.now-1);
			else if(this.options.wrap) this.showSlide(this.slides.length-1);
        },
		showSlide: function(iToShow){
			var now = this.now;
			var currentSlide = this.slides[now];
			var slide = this.slides[iToShow];
			function fadeIn(s){
				s.setStyles({
					display:'block',
					visibility: 'visible',
					opacity: 0
				});
				this.effects[this.slides.indexOf(s)].start(1);
				this.fireEvent('onShow', [slide, iToShow]);
			};
			if(slide) {
				if($chk(now) && now != iToShow){
					this.effects[now].start(0).chain(function(){
						this.slides[now].setStyle('display', 'none');
						fadeIn.apply(this, [slide]);
					}.bind(this));
				} 
				else fadeIn.apply(this, [slide]);
				this.now = iToShow;
			}
		}
});

toggleFader.implement(new Options, new Events);

/* Simple function to auto-select a form element
---------------------------------------------------------------------------------*/
function selectInput(theInput)
{
	if(theInput.clientHeight > 0)
	{
	//alert(theInput);
	theInput.focus();
	theInput.select();
	}
}
