$(function() {
		   
	pageScroll();
	photoMouseOver();
	commentLink();
	slideshow();
	
});


/*
 * pageScroll：ページスクロール
 */
function pageScroll(){
	
	$('a[href*=#]').click(function() {
								
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			
			//「#●●」をターゲットに
			var target = $(this.hash);
			
			target = target.length && target;
			if (target.length) {
				var sclpos = 30;
				var scldurat = 1200;
				var targetOffset = target.offset().top;
				
				
				$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
				return false;
			}
		}
	});
}


/*
 * photoMouseOver：写真がオンマウスされたらボーダーのカラーチェンジ
 */
 
function photoMouseOver(){
	var target = $('a[rel*="lightbox"] > img');
	
	$(target).each(function(){
		$(this).mouseover(function(){
			$(this).css("border", "5px solid #d9f7ff");								  
		});
	
		$(this).mouseout(function(){
			$(this).css("border", "5px solid #e2e2e2");								  
		});
	});
}


/*
 * photoMouseOver：写真がオンマウスされたらボーダーのカラーチェンジ
 */
 
function commentLink(){
	$(".guest > a").attr("target", "_blank");
}


//==========================================================================
//  Custom Function - slideshow
//==========================================================================
function slideshow() {
	if(!$('#slideBox')) return false;

	var slideTime = 4500; // 画像切替インターバル
	var fadeTime = 2000; // フェード時間

	var imgWrapper = $('#slideBox p a');
	var anchorBox = $('#frame a');
	var buttons = $('#slideBoxButtons li a');
	var idx = 1;

	
	
	// only show the first image, hide the rest
	
	if(imgWrapper.length < 2) return false;
	
	imgWrapper.find('img').hide().filter(':first').show();	
	var timer = setInterval(slideImage, slideTime);

	
	function slideImage(){
				imgWrapper.fadeOut(fadeTime).find('img').fadeOut(fadeTime);
				var currentWrapper = '';
				
				// 最後の１枚
				if(idx == buttons.length -1) {
					//currentWrapperにimgWrapper.slide1を代入
					currentWrapper = imgWrapper.filter(".slide1");
					currentWrapper.fadeIn(fadeTime).find('img').fadeIn(fadeTime);
				} else {
					currentWrapper = imgWrapper.filter(".slide" + (idx+1));
					currentWrapper.fadeIn(fadeTime).find('img').fadeIn(fadeTime);
				}

				anchorBox.attr('href', currentWrapper.attr('href'));
				
				if(idx == 5) { idx = 0; } else {idx = idx + 1;}
				
				return false;
		
	}
}


