window.addEvent('domready', function() {

	var wrapper = $('testimonial-cycle').setStyle('position','relative');
	
	if (!wrapper) {
		return;
	}
	
	var testimonials = wrapper.getElements('div.testimonial');
	var current = 0;
	var total = testimonials.length;
	
	if (total < 2) {
		return;
	}
	
	var dir = (testimonials[0].hasClass('left') ? 'left' : 'right');
	var spacer = new Element('div', {
			'styles': 'border: 1px solid #fff',
			'class': 'testimonial ' + dir
		}).injectInside(wrapper);
	var maxHeight = 0;
	
	testimonials.each(function(el,i) {
		if (el.getStyle('height').toInt() > maxHeight) {
			maxHeight = el.getStyle('height').toInt();
		}
		
		el.setStyles({
			'background-color': '#fff',
			'position': 'absolute',
			'top': 0,
			opacity: (current == i ? 1 : 0)
		});
		el.setStyle(dir,0);
	});
	
	spacer.setStyle('height',maxHeight);
	
	setInterval(function() {
		var fadeOut = new Fx.Style(testimonials[current], 'opacity', {duration:500}).start(1,0);
		
		current++;
		
		if (current >= total) {
			current = 0;
		}
		
		var fadeIn = new Fx.Style(testimonials[current], 'opacity', {duration:500}).start(0,1);
	},9500);
});

