var MGFX=MGFX||{};
MGFX.Rotater=new Class({
	Implements:[Options,Events],
	options:{
		slideInterval:4000,
		transitionDuration:1000,
		startIndex:0,
		autoplay:true
	},
	initialize:function(tabcontent, taboptions){
		this.setOptions( taboptions );
		this.slides	= tabcontent.getChildren( 'div' );
		this.createFx();
		this.showSlide( this.options.startIndex );
		if( this.slides.length < 2 ){
			this.options.autoplay=false
		}
		if( this.options.autoplay ){
			this.autoplay()
		}
		return this;
	},
	toElement:function(){
		return this.container;
	},
	createFx:function(){
		if(!this.slideFx){
			this.slideFx=new Fx.Elements(this.slides,{duration:this.options.transitionDuration})
		}
		this.slides.each(function(A){A.setStyle("opacity",0)});
	},
	showSlide:function(B){
		var A={};
		if ( B != this.currentSlide ) {
			this.slides.each(function(C,D){
				if(D==B&&D!=this.currentSlide){
					A[D.toString()]={opacity:1}
				}else{
					A[D.toString()]={opacity:0}
				}
			},this);
			this.fireEvent('onShowSlide',B);
			this.currentSlide=B;
			this.slideFx.start(A);
		}
		return this;
	},
	autoplay:function(){
		this.slideshowInt=this.rotate.periodical(this.options.slideInterval,this);
		this.fireEvent('onAutoPlay');
		return this;
	},
	stop:function(){
		$clear(this.slideshowInt);
		this.fireEvent('onStop');
		return this;
	},
	rotate:function(){
		current	= this.currentSlide;
		next	= (current+1>=this.slides.length) ? 0 : current+1;
		this.showSlide(next);
		this.fireEvent( 'onRotate', next );
		return this;
	}
});

var MGFX=MGFX||{};
MGFX.Tabs=new Class({
	Extends:MGFX.Rotater,
	options:{
		slideInterval:6000,
		transitionDuration:300,
		autoplay:false
	},
	initialize:function(tabtoggler, tabcontent, taboptions){
		this.tabs	= tabtoggler.getElements( 'li' );
		this.tabsA	= tabtoggler.getElements( 'a' );
		this.createTabs();
		this.parent( tabcontent, taboptions );
		return this
	},
	createTabs:function(){
		this.tabsA.each(function( item, index ) {
			item.addEvent( 'click', function(e) {
				e.stop();
				this.showSlide( index );
				this.stop()
			}.bind(this))
		}.bind(this))
	},
	activateTab:function( index ){
		this.tabs.removeClass( 'active' );
		this.tabsA.removeClass( 'active' );
		this.tabs[index].addClass( 'active' );
		this.tabsA[index].addClass( 'active' )
	},
	showSlide:function( index ){
		this.activateTab( index );
		this.parent( index );
		return this
	}
});
