(function () {
	var currentCaption = 0,
		outFx = function () {
			var nextImgNumber = $("div#photos img").index($(this)); // 'this' refers to the incoming photo
				
			$("#captions p").eq(currentCaption).hide();
			if (nextImgNumber >= 0) currentCaption = nextImgNumber;
		},
		inFx = function () {
			$("#captions p").eq(currentCaption).show();
		};
	
	$(function () {
		var start = Math.floor($('#photos img').length*Math.random());
		
		$('#photos').cycle({ 
		    fx: 'scrollHorz',
		    speed: 300,
		    timeout: 7000,
			startingSlide: start,
			next: '#next',
			prev: '#prev',
			before: outFx,
			after: inFx
		});
		$("#captions p").hide();
		$("#captions p").eq(start).show();
		currentCaption = start;
	});
})();