var Testimonials = {
	init : function() {
		Testimonials.setActivators();
		Testimonials.rotate();
	},
	
	setActivators : function() {
        Testimonials.fx = [];
        Testimonials.activators = $$('#testimonialsControls li a');
        Testimonials.frames = $$('#testimonials li');		
        Testimonials.frames.each(function(frame, i) {
	        Testimonials.fx[i] = new Fx.Style(frame, 'opacity', {wait: false, duration: 500}); 	        
            Testimonials.activators[i].addEvent('click', function() {
				Testimonials.rotating = false;
				Testimonials.showFrame(i);
	        });
        });
	},
	
	rotate : function() {												
		if( Testimonials.rotating == true)
		{
			Testimonials.showFrame(Testimonials.currentFrame);
			Testimonials.currentFrame++;
			if(Testimonials.currentFrame >= Testimonials.frames.length)
			{
				Testimonials.currentFrame = 0;
			}
			setTimeout(Testimonials.rotate, 12500);
		}
	},
	
	showFrame : function(frame) {
		var isActive = Testimonials.activators[frame].hasClass('active')												
		if( isActive == false)
		{
			Testimonials.frames.each(function(paneToDisplay, i) {
				Testimonials.frames[i].setStyle('display', 'none');
				Testimonials.activators[i].removeClass('active');
			});
			Testimonials.activators[frame].addClass('active');
			Testimonials.frames[frame].setOpacity(0);
			Testimonials.frames[frame].setStyle('display', 'block');
			Testimonials.fx[frame].start(0,1);
		}		
	},
	
	rotating : true,
	currentFrame : 0
};

window.addEvent('domready', Testimonials.init);
