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

function slideSwitch() {
	var $active = $('.gallery_head.active');
	if ( $active.length == 0 ) $active = $('.gallery_head:first');
	var $next = $active.next('.gallery_head').length ? $active.next('.gallery_head') : $('.gallery_head:first');
	$next.click();
}
function stopSlide() {
	clearInterval(slideInit);	
}
function startSlide() {
	slideInit = setInterval( "slideSwitch()", 5000 );	
}

$(function() {
	$("div#controllers").jFlow({
		slides: "#latest_posts_slides",
		width: "317px",
		height: "167px"
	});
});
function testSwitch() {
	$('.jFlowNext').click();
}
function startTest() {
	testInit = setInterval( "testSwitch()", 5000 );	
}
function stopTest() {
	clearInterval(testInit);	
}


$(document).ready( function () {
	
	$('#latest_posts').hoverIntent( stopTest, startTest);
	startTest();
	
	$('.gallery_head').click(function() {
		num = 0;
		var info_head = $(this);
		var num = $('.gallery_head').index(this);
		var box = $('.gallery_block:eq('+num+')');
		$('.gallery_head').removeClass('active');
		$(this).addClass('active');
		/*$('.gallery_block').each( function () {
			if($(this).hasClass('down')){
				$(this).fadeOut(1000).removeClass('down').addClass('up');
			}				
		});*/
		$('.gallery_block.down').fadeOut(1000).removeClass('down').addClass('up');
		$(box).fadeIn(1000).removeClass('up').addClass('down');	

	});
	$('#homepage_gallery').hoverIntent( stopSlide, startSlide);
	startSlide();
	
});



