// jquery photo rotator

var current;
var next;
var myTimer;

function rotateDivs(){
	clearTimeout(myTimer);

	current = $('#photoSubject img.current');
	next = $(current).next().length > 0 ? $(current).next() : $('#photoSubject img:first');
	
	$(current).trigger('fadeBack');
	$(next).trigger('fadeFront');

	myTimer = setTimeout('rotateDivs()',4000);
}

$(document).ready( function(){
	myTimer = setTimeout('rotateDivs()',4000);
	
 	$('#photoSubject img').bind( 'fadeBack', function(){
		
		var id = $(this).attr('id').replace('pho','');
		$('#inf'+id).removeClass('current').addClass('next');
		
		$(this).fadeOut('slow', function(){
			$(this).removeClass('current').addClass('next');
		});
		
 	}).bind( 'fadeFront', function(){
 	
 	  var id = $(this).attr('id').replace('pho','');
		$('#inf'+id).removeClass('next').addClass('current');
		
		$('#photoMore img').attr('src', 'images/bullet.jpg');
		$('#bul'+id).attr('src', 'images/bulletActive.jpg');
		
		$(this).fadeIn('slow', function(){
			$(this).removeClass('next').addClass('current');
		}); 	
		
 	});
});

