var SimpleSlideShowDemo = new Class({
	options: {
		slides: [],
		startIndex: 0,
		wrap: true,
		onShow: Class.empty //Mootools 1.2: $empty
	},
	initialize: function(options){
		this.setOptions(options)
		this.slides = [];
		this.effects = [];
		this.addSlides(this.options.slides);
		if(this.slides.length) this.showSlide(this.options.startIndex);
		//this.cycleForward.periodical(3000, this);
		setTimeout(this.cycleForward.bind(this), 6000);
	},
	addSlides: function(slides){
		$$(slides).each(function(slide){
			this.slides.include($(slide));
			//slide.addEvent('click', this.cycleForward.bind(this));
			this.effects[this.slides.indexOf(slide)] = new Fx.Style(slide, 'opacity');
		}, 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);
		//this.cycleForward.periodical(1000, this);
		setTimeout(this.cycleForward.bind(this), 6000);
	},
	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;
		}
	}
});


SimpleSlideShowDemo.implement(new Options, new Events);


var VideoSwitch = new Class({
	options: {
		slides: [],
		startIndex: 0,
		wrap: true,
		onShow: Class.empty //Mootools 1.2: $empty
	},
	initialize: function(options){
		this.setOptions(options)
		this.slides = [];
		this.effects = [];
		this.addSlides(this.options.slides);
		if(this.slides.length) this.showSlide(this.options.startIndex);
		//this.cycleForward.periodical(3000, this);
		//setTimeout(this.cycleForward.bind(this), 6000);
	},
	addSlides: function(slides){
		$$(slides).each(function(slide){
			this.slides.include($(slide));
			//slide.addEvent('click', this.cycleForward.bind(this));
			this.effects[this.slides.indexOf(slide)] = new Fx.Style(slide, 'opacity');
		}, 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);
		//this.cycleForward.periodical(1000, this);
		//setTimeout(this.cycleForward.bind(this), 6000);
	},
	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];
		alert(currentSlide);
		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;
		}
	}
});


VideoSwitch.implement(new Options, new Events);


