FLYG.ready(function(){

	FLYG.slideshow=function(prevBttn,playBttn,nextBttn,interval,stages){
			
		interval = 8;
	
		this.prevBttn=prevBttn;
		this.playBttn=playBttn;
		this.nextBttn=nextBttn;
		this.stages=stages;
		this.interval=interval || 5;
		this.activeStage=0;
		this.timer=false;
		
		var self=this;
		
		this.prevBttn.click(function(e){
			this.blur();
			FLYG.Event.handleBubble(e,false);
			self.pause().prev();
			});
		
		this.nextBttn.click(function(e){
			this.blur();
			FLYG.Event.handleBubble(e,false);
			self.pause().next();
			});
			
		this.playBttn.click(function(e){
			this.blur();
			FLYG.Event.handleBubble(e,false);
			if (self.timer) self.pause();
			else self.play();
			});
		};
		
	FLYG.slideshow.prototype={
		update:function(n){
			this.stages.removeClass('active');
			FLYG.$(this.stages[n]).addClass('active');
			this.activeStage=n;
			},
		next:function(){
			var n=this.activeStage;
			if (n==this.stages.length-1) n=-1;
			n++;
			this.update(n);
			},
		prev:function(){
			var n=this.activeStage;
			if (!n) n=this.stages.length;
			n--;
			this.update(n);
			},
		play:function(){
			var self=this;
			var link=this.playBttn.$byTag('a').removeClass('paused')[0];
			link.href='#pause';
			link.title='Pause';
			this.timer=setInterval(function(){
				self.next();
				},this.interval*1000);
			},
		pause:function(){
			clearInterval(this.timer);
			this.timer=false;
			var link=this.playBttn.$byTag('a').addClass('paused')[0];
			link.href='#play';
			link.title='Play';
			return this;
			}
		};
		
	if (FLYG.$('slideshow').length){
		
		(new FLYG.slideshow(
			FLYG.$('slideshow_prev'),
			FLYG.$('slideshow_play'),
			FLYG.$('slideshow_next'),
			10,
			FLYG.$('slideshow').$byClass('slideshow_data',{tagtype:'div'})
			)).play();
			
		}

	});