//head_photo自動スライド
var position=0;
var zIndex = 2;

function getNextPhoto(nextNum, pa){
	var photoIdArray = pa;
	//次の写真のデータを持ってくる
	$.post(
		'get_next_photo.php',
		{
			next_num: photoIdArray[nextNum]
		},
		function(e){
			var nextPhotoData = [];

			//次の写真データ受け取り
				nextPhotoData = eval(e);

			setTimeout(function(){
				//次の写真を作成
				//nextPhotoData[0]=>id, [1]=>timestamp, [2]=>comment, [3]=>ext, [4]=>new
				$('<div id="'+nextPhotoData[0]+'" />').addClass('photo_outer').css('zIndex', zIndex).hide()
				.append('<img src="images/photo_memo/'+nextPhotoData[0]+'.' +nextPhotoData[3] + '" />')
				.append('<p class="photodate">' + nextPhotoData[1] + ' <span>' + nextPhotoData[4] + '</span></p>')
				.append('<p>' + nextPhotoData[2] + '</p>')
				.appendTo('div#position_'+position);
				//現在の写真をフェードアウトさせて
				$('div#position_'+position+' div:first').fadeOut(800,function(){
					$(this).remove();
				});
				//次の写真をフェードイン
				$('div#'+nextPhotoData[0]).fadeIn(800);
				
				
				nextNum++;
				position++;
				if(position>=3){
					position = 0;
				}else{
					position = position;
				}
				if(photoIdArray.length-1<nextNum){
					nextNum = '0';
					getNextPhoto(nextNum, photoIdArray);
				}else{
					getNextPhoto(nextNum, photoIdArray);
				}
				zIndex++;
				
				
			}, 5000)
		}
	);
}
