$(document).ready(function() {
	$("#nav > ul > li:not(.selected)").each(function() {
		$(this).mouseover(function() {
			var img = $(this).find("img");
			var src = img.attr("src");
			if (src.indexOf('_over') == -1) {
				var base = src.substring(0, src.lastIndexOf('.'));
				var ext = src.substring(src.lastIndexOf('.'));
				img.attr("src", base + "_over" + ext);
			}
		});
		$(this).mouseout(function() {
			var img = $(this).find("img");
			var src = img.attr("src");
			if (src.indexOf('_over') != -1) {
				var base = src.substring(0, src.lastIndexOf('_over'));
				var ext = src.substring(src.lastIndexOf('.'));
				img.attr("src", base + ext);
			}
		});		
	});
	
	// Homepage testimonials
	setInterval(rotateTestimonial, 7000);
});

function rotateTestimonial() {
	var testimonial = $("#homepage-buckets #testimonials div.testimonial.visible");
	var i = $("#homepage-buckets #testimonials > div.testimonial").index(testimonial);
	var numTestimonials = $("#homepage-buckets #testimonials > div.testimonial").length;
	var nextIndex = ((i + 1 == numTestimonials) ? 0 : i + 1); 
	testimonial.fadeOut(400, function() {
		$(this).removeClass("visible");
		$("#homepage-buckets #testimonials > div.testimonial:eq(" + nextIndex + ")").fadeIn().addClass("visible");
	});
}