$(function(){
//$(window).load(function(){
var $photo = $('#photo'),
$jsGallery = $('#js-gallery'),
$picName = $('#pic_name');
$picMain = $('#pic_main'),
$picOther = $('#pic_other'),
nowNum = 0,
maxNum = $jsGallery.find('li').length - 1;
//サムネイルクリック
$jsGallery.find('a').on('click', function(){
$photo.addClass('dis');
nowNum = $(this).parent().index();
modalSet(nowNum);
//var n = $(this).children().index();
var n = $(this).children().length;
if(n > 0) {
$picOther.show();
} else {
$picOther.hide();
}
return false;
});
$photo.find('.next').on('click', function(){
if(nowNum < maxNum) {
nowNum++;
} else {
nowNum = 0;
}
modalSet(nowNum);
return false;
});
$photo.find('.prev').on('click', function(){
if(nowNum > 0) {
nowNum--;
} else {
nowNum = maxNum;
}
modalSet(nowNum);
return false;
});
$photo.find('.close-bg, .close').on('click', function(){
$photo.removeClass('dis');
return false;
});
var modalSet = function(num) {
var targetTag = $jsGallery.find('li'),
imgSrc = targetTag.eq(num).find('a').attr('href'),
imgAlt = targetTag.eq(num).find('a').attr('title'),
imgTags = targetTag.eq(num).children().html();
//console.log(imgSrc + '\n' + imgAlt + '\n' + imgTags);
$picName.text(imgAlt);
$picMain.find('img').attr('src', imgSrc);
$picOther.html(imgTags);
$picOther.find('img').wrap("");
setTimeout(function(){
$picOther.find('a').on('click', function(){
var imgSrc = $(this).children().attr('src');
$picMain.find('img').attr('src', imgSrc)
return false;
});
}, 50);
}
$(window).resize(function() {
var timer = false;
if (timer !== false) { clearTimeout(timer); }
timer = setTimeout(function() {
$photo.removeClass('dis');
}, 100);
});
});