var i, textboxes, hideColour, showColour, periodical;
var transitionDuration = 1000;
var periodDuration = 18000;
var next = function(first) {
	// current textbox
	var tb_c = $(textboxes[i]);
	if (!first)
	{
		i++;
	}
	if (i >= textboxes.length) i = 0;
	// next textbox
	var tb_n = $(textboxes[i]);
	
	
	var tb_c_height = tb_c.getSize().y;
	var tb_n_height = tb_n.getSize().y;
	newText = tb_n.innerHTML;
	
	new Fx.Morph($('testimonial-container'), {duration: transitionDuration}).start({
		// set height so there isn't a jump when text is replaced
		'height' : tb_c_height,
		'opacity' : 0
	}).chain(function(){
		$('testimonial-container').innerHTML = newText;
		this.start({
			'opacity' : 1,
			'height' : tb_n_height
		});
	});
};
var stop = function() {
	$clear(periodical);
};
window.addEvent('load', function() {
	if ($('testimonial-hider')) {
		$('testimonial-hider').setStyle('display', '');
		textboxes = $('testimonial-hider').getChildren();
		hideColour = $('testimonial-container').getStyle('background-color');
		showColour = $('testimonial-container').getStyle('color');
		
		i = Math.floor(Math.random() * textboxes.length);
		
		next(true);
		periodical = next.periodical(periodDuration);
	}
});

