//function set_height("
var MGFX=MGFX||{};
MGFX.Rotater=new Class(
	{
		Implements:[Options,Events],
		options:{
			slideInterval:4000,
			transitionDuration:1000,
			startIndex:0,
			autoplay:true
		},
		initialize:function(B,A){
			this.setOptions(A);
			this.slides=$$(B);
			this.createFx();
			this.showSlide(this.options.startIndex);
			//console.log('height is '+this.slides.getHeight());
			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);
			//console.log('height is '+A.getHeight());
			})},
		showSlide:function(B){
			var A={};
			this.slides.each(function(C,D){
				if(D==B&&D!=this.currentSlide){A[D.toString()]={opacity:1};
				//console.log('IMPORTANT. We need to set up new height for .relative in this CASE. Height is: '+C.getHeight());
				$$('.relative').setStyle('height',C.getHeight());
				}
				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(B,C,A){
			this.tabs=$$(B+" li");
			this.tabsA=$$(B+" a");
			this.createTabs();
			this.parent(C,A);
			return this
		},
		createTabs:function(){
			this.tabsA.each(function(B,A){
				B.addEvent("click",function(C){
					//variable = B.getStyle();
					if (B.hasClass('current')) {
						//console.log("fucken bingo");
					}
					else
					{
					//console.log('i like A:'+A+'and B:'+B+'and C:'+C+'and this'+this); //+'and variable:'+variable
					C.stop();
					this.showSlide(A);
					this.stop()}}.bind(this))}.bind(this))
		},
		activateTab:function(A){
			this.tabs.removeClass("current");
			this.tabsA.removeClass("current");
			this.tabs[A].addClass("current");
			this.tabsA[A].addClass("current")
		},
		showSlide:function(A){
			this.activateTab(A);
			this.parent(A);
			return this
		}
});

/*
window.addEvent('domready',function() {
	var tabs = new MGFX.Tabs('.tabs','.content',{
		autoplay: true,
		transitionDuration:500,
		slideInterval:6000
	});
});
*/

window.addEvent('domready',function(e){
	if($$('.tabs').length > 0) MGFX.tabs = new MGFX.Tabs(
		'.tabs',
		'.feature',
		{
		transitionDuration:0
		});
//	if($('rotater-demo')) MGFX.rotater = new MGFX.Rotater('.slide');
});






















/* good old script, deleted by bibi request :(
 
 
 var showFunction = function() {
        //resets all the styles before it morphs the current one
	$$('.hidden').setStyles({
		'display': 'none',
		'opacity': 0

	}); 
        //here we start the morph and set the styles to morph to
	this.start({
		'display': 'block',
		'opacity': 1
	});
}

//var showFunction = function() {
//	$$('.hidden').setStyle('display', 'none'); 
//	this.setStyle('display', 'block');
//}
window.addEvent('domready', function() {
	var elOne = $('contentone');
	var elTwo = $('contenttwo');
	var elTab1 = $('one');
	var elTab1 = $('two');
	elOne = new Fx.Morph(elOne, {
		duration: 150,
		transition: Fx.Transitions.Sine.easeOut,
		link: 'cancel'
	});
	elTwo = new Fx.Morph(elTwo, {
		duration: 150,
		transition: Fx.Transitions.Sine.easeOut,
		link: 'cancel'
	});
 	$('one').addEvent('click', function() {
		showFunction.bind(elOne)();
		this.addClass('current');
		$('two').removeClass('current');
	});
	$('two').addEvent('click', function() {
		showFunction.bind(elTwo)();
		this.addClass('current');
		$('one').removeClass('current');
	});
	this.showFunction.bind(elOne)();
});*/
