	/**
	* Rotater v3.1 - You may not remove or change this notice.
	* Copyright Marek Ryk 2008-2010. All rights reserved.
	* This library is free software. 
	* You can use it for anything you like, as long as you include the copyright notice. 
	* Please send e-mail to me (marek.ryk#gmail.com #->@) with information about your website!
	*/
	var rotater = Class.create();
	rotater.prototype = {
		initialize: function(framesClass,params)
		{
			this.framesClass = framesClass;
			this.frames = [];
			this.frameID = 0;
			this.stepShow = 0;
			this.oneStep = 0;
			this.stepValue = 0;
			this.opacityValuesShow = [];
			this.opacityValuesHide = [];
			this.intervalShow = 0;
			this.intervalHide = 0;
			this.processShow = false;
			this.processHide = false;
			this.durationStepShow = 20;
			this.durationStepHide = 20;
			this.stepsShow = 25;
			this.stepsHide = 20;
			this.pauseShow = 500;
			this.pauseHide = 2500;
			this.setOpacityArrays();
			if ( typeof(params) != 'undefined'  ) this.setParams(params);
			this.stepHide = this.stepsHide;
		},
		
		init: function()
		{
			this.frames = $$('.'+this.framesClass);
			this.lastIDframes = this.frames.size()-1; 
		},
		
		setParams: function(params)
		{
			if ( typeof(params.durationStepShow) != 'undefined' ) this.durationStepShow = params.durationStepShow;
			if ( typeof(params.durationStepHide) != 'undefined' ) this.durationStepHide = params.durationStepHide;
			if ( typeof(params.stepsShow) != 'undefined' ) this.stepsShow = params.stepsShow;
			if ( typeof(params.stepsHide) != 'undefined' ) this.stepsHide = params.stepsHide;
			if ( typeof(params.pauseShow) != 'undefined' ) this.pauseShow = params.pauseShow;
			if ( typeof(params.pauseHide) != 'undefined' ) this.pauseHide = params.pauseHide;
		},
		
		
		setOpacityArrays: function()
		{
			this.stepValue = this.oneStep = 100 / this.stepsShow;
			for(i=0;i<this.stepsShow;i++){
				this.opacityValuesShow[i] = (this.stepValue/100).toFixed(2) ;
				this.stepValue += this.oneStep;
			}
			this.stepValue = this.oneStep = 100 / this.stepsHide;
			for(i=0;i<this.stepsHide;i++){
				this.opacityValuesHide[i] = (this.stepValue/100).toFixed(2);
				this.stepValue += this.oneStep;
			}
		},
		
		setOpacityShowLayout: function()
		{
			if(this.stepShow < this.stepsShow) {
				if(this.stepShow == 0) this.frames[this.frameID].style.display = 'block';
				this.frames[this.frameID].setOpacity(this.opacityValuesShow[this.stepShow]);
				this.stepShow++;
			}else{
				clearInterval(this.intervalShow);
				this.stepShow = 0;
				this.processShow = false;
				setTimeout(
					this.hideSlide.bindAsEventListener(this),
					this.pauseHide
				);
			}
		},
		
		setOpacityHideLayout: function()
		{
			if(this.stepHide > 0) {
				this.stepHide--;
				this.frames[this.frameID].setOpacity(this.opacityValuesHide[this.stepHide]);
			}else{
				clearInterval(this.intervalHide);
				this.frames[this.frameID].style.display = 'none';
				this.stepHide = this.stepsHide;
				this.processHide = false;
				this.nextIteration();
				setTimeout(
					this.showSlide.bindAsEventListener(this),
					this.pauseShow
				);
			}
		},
		
		showSlide: function()
		{
			if(!this.processHide){
				this.processShow = true;
				this.intervalShow = setInterval(
					this.setOpacityShowLayout.bindAsEventListener(this),
					this.durationStepShow
				);
			}
		},
		
		hideSlide: function()
		{
			if(!this.processShow){
				this.processHide = true;
				this.intervalHide = setInterval(
					this.setOpacityHideLayout.bindAsEventListener(this),
					this.durationStepHide
				);
			}
		},
		
		nextIteration: function()
		{
			if(this.frameID < this.lastIDframes) 
				this.frameID++;
			else
				this.frameID = 0;
		},
		
		startLoop: function()
		{
			this.init();
			if (this.frames.size() > 0) {
				this.processHide = false;
				this.processShow = false;
				this.showSlide();
			}
		},
		
		stopLoop: function()
		{
			this.processHide = true;
			this.processShow = true;
			clearInterval(this.intervalShow);
			clearInterval(this.intervalHide);
		}
		
	};