/* main_sub19d.js  2019.10.12 */

    photo_com = []; photo_file = []; photo_numb = [] ;
    photo_data = []; pa_photo = [] ; pht1_data = []; com1_data = []; 
    thmb_max = []; tm_pos = []; 
 
    tms1_data = []; thm1_img = []; thm1_alt= [];  thm1_ttl = []; 
    th_width = [];  th_height = []; 
    tms1_data[0] = "";  pht1_data[0] = ""; com1_data[0] = "";

    tm_style = [];

    album_title ="";
    photo_no = 1;  ph_efct = 1;
    tm_source = 14;  tm_css3 = 1 ;

    tm_size_fix = 1  // ☆ 0 にすると小サムネイルは、その画像の実サイズで表示される
    max1_ph = 0;   smh = 0; dan=0;

    prRead = new Image()
    scwd = screen.width;  scht = screen.height;


/* サムネイル間コメント */

function com_top(tr_style){ tbs += "<TR><TD colspan="+col_max+" style='"+tr_style+"'>" }
function com_end(){ tbs += "</TD></TR>"}


/* データ分離 */
function cnvData(){

var pgno = 1 ; var phsp; var pg = 0;

    if(photos_holder.lastIndexOf("/")== -1){
        photos_holder = photos_holder+"/"
    }

    for(var i = 0; i < photo_data.length-1; i++){
        pa_photo[i] = photo_data[i]
    }

    for(var pn = 0; pn < pa_photo.length-1; pn = pn+3){
        pg++; 
        tms1_data[pg]  = pa_photo[pn]
        pht1_data[pg]  = photos_holder + pa_photo[pn+1]
        com1_data[pg]  = pa_photo[pn+2]
    }

    max1_ph = pg; thmb_max[1] = pg;
    sepThmb(1)
 
    pa_photo = []
    for(var i=0; i<=100 ; i++){tm_pos[i] = i}

    dsm = 1; 
    for(i = 0; i < photo_data.length-1; i++){
        pa_photo[i] = photo_data[i] 
    }
    for(pn = 0; pn < pa_photo.length-1; pn = pn+3){
        photo_file[dsm]  = photos_holder + pa_photo[pn+1]
        photo_com[dsm]  = pa_photo[pn+2]
        dsm++; 
    }
    photo_file[dsm]  = photo_file[dsm-1]
    dat_sum = dsm-1;

    for(i = 1 ; i < dsm ; i++){
        photo_numb[i] = i +"/"+ (dsm-1)
    }
    photo_numb[i] ="***" 
}


/* サムネイル表示データの分離 */
function sepThmb(){

var phsp; var pn; 
    phd = photos_holder
    pg = 0;
    for(pn = 0; pn < pa_photo.length-1; pn = pn+3){
        pg++;
        tms1_data[pg]  = pa_photo[pn]
        if(tms1_data[pg].indexOf("*") >= 0){
            thm1_img[pg] = pht1_data[pg] 
        }else{
            dpos = tms1_data[pg].indexOf(".") 
            if(dpos > 0){
                phsp = tms1_data[pg].split("|")
                thm1_img[pg] = phd + phsp[0] 
            }else{
                phsp = pht1_data[pg].split(".")
                thm1_img[pg] = phsp[0]+"s."+phsp[1] 
            }
        }
    }
}

/* === サムネイル表示部 === */

    col_max = 0 ;  photo_jun = 0;
    tate = 1    ; yoko = 1 ;
    tm_width = 0; tm_height = 0; 
    tbs = ""; tateyoko = "11";

function tableTop(){

    photo_jun = 1; 
    tbs ="<TABLE cellpadding=0 cellspacing=0 border=0 class='tm_table1'>"
    tbs += "<TR><TD>"
    tbs +="<TABLE cellpadding=0 cellspacing=0 border=0>"
}


/* サムネイルの一行出力 */
function tr(trst){

    tbs += "<TR>";
    for(var tri=0 ; tri <trst.length ; tri++){
         trstr = trst.charAt(tri)
         if(trstr == "1"){ tate =1; yoko=1; tateyoko=11; tm_out()}
         if(trstr == "2"){ tate =2; yoko=2; tateyoko=22; tm_out()}
         if(trstr == "3"){ tate =3; yoko=3; tateyoko=33; tm_out()}
         if(trstr == "4"){ tate =1; yoko=2; tateyoko=21; tm_out()}
         if(trstr == "5"){ tate =2; yoko=3; tateyoko=32; tm_out()}
    }
    tbs += "</TR>";
    col_max = trst.length;
}


tm_css3 = 0

/* サムネイル一個の出力 */

function tm_out(){

    if(photo_jun > thmb_max[1]){tbs += "</TR>"; return }
    ksp = tm_pos[photo_jun];

    tbs += "<TD nowrap align='center' valign='top' ";
    if(tateyoko > 11){ tbs += " colspan="+yoko+" rowspan="+tate+" "}
 
    if(tateyoko == 11){
        th_width = tm_width
        th_height = tm_height
    }

    if(tateyoko == 22){
        th_width = tm_width*2 +  tm_style[1]*4 + tm_style[2]
        th_height = tm_height*2 + tm_style[1]*4 + tm_style[2]
    }

    if(tateyoko == 33){
        th_width = tm_width*3 +  tm_style[1]*8 + tm_style[2]*2
        th_height = tm_height*3 + tm_style[1]*8 + tm_style[2]*2
    }

    if(tateyoko == 21){
        th_width = tm_width*2 +  tm_style[1]*4 + tm_style[2]
        th_height = tm_height
    }

   if(tateyoko == 32){
        th_width = tm_width*3 +  tm_style[1]*8 + tm_style[2]*2
        th_height = tm_height*2 + tm_style[1]*4 + tm_style[2]
    }

    tbs +=" >";

    tbs += " <table cellpadding=0 cellspacing=0 "

    if(tm_imgs < 5){ 
        tbs += " class='tm_tbl grds'>"
    }else{
        if(tm_imgs == 5){tbs += " class='tm_tbl grds tm_photo2'>"}
        if(tm_imgs == 6){tbs += " class='tm_tbl grds tm_photo3'>"}
        if(tm_imgs == 7){tbs += " class='tm_tbl grds tm_photo4'>"}
        if(tm_imgs == 8){tbs += " class='tm_tbl grds tm_photo5'>"}
        if(tm_imgs == 9){tbs += " class='tm_tbl grds tm_photo6'>"}
    }
    tbs += "<tr><td>"
 
    tbs += "<a href='javascript:void(0)' onfocus='this.blur()'>"
    tbs +="<img src='"+ thm1_img[ksp] + "'  border=0  class='tm_img"+tm_imgs+"'"
    tbs += " onClick = subWinOpen("+ ksp +")" 

 //   if(tw_width >0){
 //            tbs += " width="+tw_width+" height="+tw_height+" "
 //   }else{
        if(tateyoko > 11){ 
             tbs += " width="+th_width+" height="+th_height+" "
        }else{
             tbs += " width="+tm_width+" height="+tm_height+" "
        }
 //   }
    tbs +=" </a>"

    tbs +="</td></tr></table>"

    tbs +="</TD>"
    photo_jun++;
}


/* サムネイル群の終了 */
function tableEnd(){
 
    tbs += "</TABLE></TD></TR></TABLE>" 
    document.open(); document.write(tbs); document.close()
}


/* 写真画面を上に */
function subWinOpen(kapp){

    photo_no = kapp
if(photo_no>1){
    Photos.src = photo_file[0]
    Photos.src = photo_file[photo_no]
}else{
    Photos.src = photo_file[1]
}
    objCom.innerHTML = photo_com[photo_no]
    numbDsp.innerHTML = photo_numb[photo_no]
    scrollTo(0,0);
    objPhotofrm.style.zIndex = 2 ;
}


function initBtn(){

    prev_str = "← Prev" ,  next_str = "Next →" ,  close_str = "Close ↑↑";
    btnst ="<a href='javascript:void(0)' onfocus='this.blur()' "
    next_chr = btnst+" onClick = 'clickBtns(2) ; return false;' title='次の一枚'> " + next_str + "</a>"
    prev_chr = btnst+" onClick = 'clickBtns(3) ; return false;' title='前の一枚'> " + prev_str + "</a>"
    home_chr = btnst+" onClick = 'winClose() ; return false;' title='リンク元に戻る' > " + close_str + "</a>"

    objNext = getID("td_next") ; objNext.innerHTML = next_chr
    objPrev = getID("td_prev") ; objPrev.innerHTML = prev_chr
    objHome = getID("close"); 
    objHome.innerHTML = home_chr

    numbDsp.innerHTML =  photo_numb[photo_no]
}


function initSub(){
     prRead.src = photo_file[photo_no] 
     prRead.src = photo_file[photo_no+1] 
}


photo_file[0] ="src9c/top_img.png"

function dspPhoto(){

    PhotoTd1 = getID("photo_td1")
    objCom = getID("comDiv")

    if(smho==1){ 
        objCom.style.fontSize="28px"; 
    }else{
         objCom.style.fontSize="15px";
    }

    if(smho==1){
        PhotoTd1.innerHTML = "<img src = '"+ photo_file[1]+"' ID='photo_1' onTouchStart=clickBtns(1) >"
    }else{
        PhotoTd1.innerHTML = "<img src = '"+ photo_file[1]+"' ID='photo_1' onClick=clickBtns(1) >"
    }
    Photos = getID("photo_1")
    objCom.innerHTML = photo_com[photo_no]
}


function clickBtns(btno){

    if(photo_no <= dat_sum){ 
        if(btno == 1){NextPhoto() }
        if(btno == 2){NextPhoto() }
    }
    if(photo_no > 1){ 
        if(btno == 3){PrevPhoto()}
    }
}

function NextPhoto(){

    photo_no++
    if(photo_no <= dat_sum){ 
        Photos.src = photo_file[photo_no]
        if(ph_efct == 1){ mz = 0.7 ; mBlend()}
        objCom.innerHTML = photo_com[photo_no]
        objTitle.innerHTML = "*　"+document.title+"　*"
        PreRead()
        numbDsp.innerHTML = photo_numb[photo_no]
    }

    if(photo_no == dat_sum){ 
        Photos.src = photo_file[photo_no]
        if(ph_efct == 1){ mz = 0.7 ; mBlend()}
        numbDsp.innerHTML = photo_numb[photo_no]
        objCom.innerHTML = photo_com[photo_no]
    }

    if(photo_no > dat_sum){ 
        objNext.innerHTML = "　";
        objPrev.innerHTML = "　";
        numbDsp.innerHTML = "　";
        objTitle.innerHTML = "　"
  
        objCom.innerHTML = "***　これで終わりです。約３秒後に一覧画面に戻ります。 ***"
        nz = 0.9; last_fade2();
        timerID= setTimeout("winClose()",3000)
    }
}

function mBlend(){

     Photos.style.opacity = mz
     mz += 0.005
     if(mz < 1.0){ setTimeout("mBlend()",1)}
}




/* Ｋｅｙ操作 */
    window.document.onkeydown = checkKey

function checkKey(e){

   if(document.all){ evk = event.keyCode }else{ evk = e.keyCode }
   if(evk == 37){ clickBtns(3) ; return false}
   if(evk == 39){ clickBtns(1) ; return false}
   if(evk == 40){ winClose() }
}


/* スマホ判別 */
if(navigator.userAgent.match(/(iPhone|Android)/i)){ smho=1 }else{ smho=0 }

/* スマホ対応 予備 */
function initSmh(){ }


function startSub(){

    dspButton()
    initBtn()
    dspPhoto()

    objTitle = getID("title1");
    objTitle.innerHTML = "写真をクリックすると順に表示されます。"

    objThmfrm = getID("thm_frm");
    objPhotofrm = getID("photo_frm");
    objPhotofrm.style.zIndex = 0 ;
}


function PreRead(){
    prRead.src = photo_file[photo_no + 1]
}




function last_fade2(){

     Photos.style.opacity = nz
     nz -= 0.01
     if(nz > 0.5){ setTimeout("last_fade2()",10) }
}


function PrevPhoto(){

    if(photo_no > 1){photo_no-- ;} else {photo_no = 1}
    Photos.src = photo_file[photo_no]
    Photos.style.opacity = 1
    objCom.innerHTML = photo_com[photo_no]
    numbDsp.innerHTML = photo_numb[photo_no]
    objNext.innerHTML = next_chr
}


function winClose(){

    objNext.innerHTML = next_chr
    objPrev.innerHTML = prev_chr
    objHome.innerHTML = home_chr
    Photos.style.opacity = 1
    objPhotofrm.style.zIndex = 0 ;
    objTitle.innerHTML = ""

}


function dspButton(){

    numbDsp = getID("numb")
    numbDsp.style.paddingRight = "10px"
    numbDsp.innerHTML = photo_numb[photo_no]
}


function getID(arg){return document.getElementById(arg)}


