$.extend(config, {home: {testimonials: {index: 0, items: null, interval: null}}});

$(document).ready(function() {
	/* testimonials */
	$.get('testimonials.php', {start: '0', results: '4'}, function(data) {
		if (!data.found) {
			$('#testimonial').hide().empty();
			html = '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;"><p style="margin-top: 8px;"><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span><strong>Alert:</strong> There was an error loading the testimonials.</p></div>';
			$('#testimonial').html(html).fadeIn(400);
		} else {
			config.home.testimonials.items = data.results;
			show_testimonials();
			if (data.results.length > 1) config.home.testimonials.interval = setInterval('show_testimonials()', 10000);
		}
	}, 'json');
});

function show_testimonials() {
	if (config.home.testimonials.index >= config.home.testimonials.items.length) config.home.testimonials.index = 0;
	$('#testimonial').fadeOut(300).empty();
	html = '<p><em>'+config.home.testimonials.items[config.home.testimonials.index].message+'</em></p><br/>';
	if (config.home.testimonials.items[config.home.testimonials.index].portfolio_url) {
		html += '<div class="fl"><a href="'+config.home.testimonials.items[config.home.testimonials.index].portfolio_url+'">View Project</a></div>';
	}
	html += '<div class="text-right">'+config.home.testimonials.items[config.home.testimonials.index].name+'</div>';
	$('#testimonial').html(html).fadeIn(400);
	config.home.testimonials.index++;
}