// JavaScript Document to run the sliding gallery on the homepage

function gallerySwitch() {
	var $active = $('#homepage_gallery .active');
	if ( $active.length == 0 ) $active = $('#homepage_gallery .gallery_slide:first');
	var $next =  $active.next('.gallery_slide').length ? $active.next('.gallery_slide')	: $('#homepage_gallery .gallery_slide:first');

	$active.fadeOut('slow').removeClass('active');
	$next.fadeIn('slow').addClass('active');
}
function startGallery() {
	galleryInit = setInterval( "gallerySwitch()", 5000 );	
}
function stopGallery() {
	clearInterval(galleryInit);	
}



$(function() {
	$("div#testimonial_control").jFlow({
		slides: "#testimonial_slides",
		width: "300px",
		height: "167px"
	});
});
function slideSwitch() {
	$('.jFlowNext').click();
}
function startSlide() {
	slideInit = setInterval( "slideSwitch()", 10000 );	
}
function stopSlide() {
	clearInterval(slideInit);	
}



$(document).ready( function () {
	$('#professional_endorsements').hoverIntent( stopSlide, startSlide);
	startSlide();
	
	$('#homepage_gallery').hoverIntent( stopGallery, startGallery);
	startGallery();
});


