// JavaScript Document
//佈景外框高度
//目前編號slidein1
//CSS調整
/*$(document).ready(function(){
	$(".caption div").css("font-size", "50%");   
}
*/
//開啟收合左區塊
$(document).ready(function() {
    //按鈕開關
    $("body").on("click", "#leftmenubtn", function() {
        if ($(this).attr("name") == 'open') { //開啟	
            $("#leftfloatbox").css({
                "animation-name": "leftopen",
                "left": "0px"
            });              	
            $("html,body").animate({
                scrollTop: 0
            }, 900);
        } else { //關閉
            $("#leftfloatbox").css({
                "animation-name": "leftclose",
                "left": "-350px"
            });
        }
        $("#leftfloatbox").css("min-height", "" + $(document).height() + "px");
    })
    //區塊外的點擊關閉	 
    $(this).mouseup(function(e) {
        if ($("#leftfloatbox").css("left") == '0px') {
            var container = $("#leftfloatbox"); // 這邊放你想要排除的區塊
            if (!container.is(e.target) && container.has(e.target).length === 0) {
                $("#leftfloatbox").css({
                    "animation-name": "leftclose",
                    "left": "-350px"
                });
            }
        }
    });
});
//顯示字元限制
$(document).ready(function() {
    $("#sidediv .blocktitle").each(function(index) {
        $idname = $(this).attr("name");
        var str = $("#sidediv .blocktitleto" + $idname).text();
        $("#sidediv .blocktitleto" + $idname).text(str.substr(0, (languagevar == 'en' ? "20" : "8")));
    });
    if($("#bottomrlbox").length == '1'){
    $("#bottomrlbox .blocktitle").each(function(index) {
        $idname = $(this).attr("name");
        var str = $("#bottomrlbox .blocktitleto" + $idname).text();
        $("#bottomrlbox .blocktitleto" + $idname).text(str.substr(0, (languagevar == 'en' ? "20" : "8")));
    });
    }
    if($("#bottomrlbox2").length == '1'){
    $("#bottomrlbox2 .blocktitle").each(function(index) {
        $idname = $(this).attr("name");
        var str = $("#bottomrlbox2 .blocktitleto" + $idname).text();
        $("#bottomrlbox2 .blocktitleto" + $idname).text(str.substr(0, (languagevar == 'en' ? "20" : "8")));
    });
    }
     $("#centertpldiv .blocktitle").each(function(index) {
        $idname = $(this).attr("name");
        var str = $("#centertpldiv .blocktitleto" + $idname).text();
        $("#centertpldiv .blocktitleto" + $idname).text(str.substr(0, (languagevar == 'en' ? "45" : "32")));
    }); 
    $(".contentframe .blocktitle").each(function(index) {
        $idname = $(this).attr("name");
        var str = $(".contentframe .blocktitleto" + $idname).text();
        $(".contentframe .blocktitleto" + $idname).text(str.substr(0, (languagevar == 'en' ? "48" : ($centerdivwcss == 'ldivtrue' ? "34" : "38"))));
    });      
});
//迴圈操作區塊樣式關閉開啟
$(document).ready(function() {
    $(".blockseach").each(function(index) {
        $ajaxsetuptop = $(this).attr("name");
        if ($ajaxsetuptop != undefined) {
            var $ajaxsetuptop_arr = $ajaxsetuptop.split(','); //切割陣列
        }
        var $btn = "#blocksoperating" + $ajaxsetuptop_arr[0] + "";
        $($btn).click(function() {
            $ajaxsetup = $(this).attr("name");
            if ($ajaxsetup != undefined) {
                var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
            }
            $.ajax({
                url: xoopsjsurl + '/modules/neillibrary/ajax.php',
                type: 'POST',
                data: {
                    id: 166,
                    var1: $ajaxsetup_arr[0], //bid
                    var2: $ajaxsetup_arr[1], //狀態
                    var3: $ajaxsetup_arr[2] //title              	            	         	     			       		
                },
                success: function(response) {
                    history.go(0); //更新頁面
                },
                error: function() {
                    console.log('ajax error!');
                }
            })
        });
    });
});
if ($configListenable == '0') {
    //佈景版本判斷
    $(document).ready(function() {
        var $xoopsmodule = "neothemesadmin";
        $.ajax({
            url: xoopsjsurl + '/modules/neillibrary/ajax.php',
            type: 'POST',
            data: {
                id: 126,
                dbid: $themesversion,
                var1: $descriptionurl,
                var2: $downloadurl,
                xoopsmodule: $xoopsmodule
            },
            success: function(response) {
                $('#updatenotice').html(response);
            },
            error: function() {
                console.log('ajax error!');
            }
        })
        //關閉通知
        $("body").on("click", "#kclosebtn", function(e) {
            $("#updatenotice").toggle("slow");
            $.ajax({
                url: xoopsjsurl + '/modules/neillibrary/ajax.php',
                type: 'POST',
                data: {
                    id: 127,
                    dbid: 1
                },
                success: function(response) {},
                error: function() {
                    console.log('ajax error!');
                }
            })
        })
    });
}
//去除nowrap
if ($xoopsdirname == 'tad_uploader') { //只有在tad_uploader模組執行
    $(document).ready(function() {
        $('#sort tr').each(function(index) {
            var $sorttext = $(this).html(); //取得tr中的HTML內容   
            var $sorttextreplace = $sorttext.replace(/nowrap/g, ''); //去除nowrap標籤
            $(this).replaceWith($(this).html($sorttextreplace)); //輸出內容
        });
    });
}

//LOGO動畫
function logoAnimationfunction() {
  async function myFunction() {
    await new Promise(resolve => setTimeout(resolve, 0));
    $(".animation #logoimgbox").css({
      "animation-name": "logoimgbox",
      "animation-duration": "0.8s",
      "opacity": "1",
      "transform": "scale(1,1)"
    });
    await new Promise(resolve => setTimeout(resolve, 200));
    $(".animation #logoimgbox1").css({
      "animation-name": "logoimgbox1",
      "animation-duration": "1.3s",
      "opacity": "1",
      "left": "172px"
    });
    await new Promise(resolve => setTimeout(resolve, 300));
    $(".animation #logoimgbox2").css({
      "animation-name": "logoimgbox2",
      "animation-duration": "0.7s",
      "opacity": "1",
      "top": "5px"
    });
    await new Promise(resolve => setTimeout(resolve, 400));
    $(".animation #logoimgbox3").css({
      "animation-name": "logoimgbox3",
      "animation-duration": "0.7s",
      "opacity": "1",
      "left": "195px"
    });
  }
  myFunction();
  //重置動畫
  setTimeout(function() {
    $(".animation #logoimgbox,.animation #logoimgbox1,.animation #logoimgbox2,.animation #logoimgbox3").css({
      "animation-name": ""
    });
  }, 6000);
}
setInterval(function() {
  logoAnimationfunction();
}, 20000);

$(document).ready(function() {
    $("body").on("click", ".webbtnmenu", function() {
        $("#fixmenu").css("z-index", "30");
        $("#jointhelinkbtn").css("z-index", "20");
    })
});
//標語區塊
$(document).ready(function() {
    $("#logobottom").mouseover(function() {
        $("#logotext").css({
            "animation-name": "slidein",
            "opacity": "0.9",
            "display": "block"
        });
     $("#logobottom a").attr('title', '');    //隱藏title  	        	
    });
    $("#logobottom").mouseout(function() {
        $("#logotext").css("display", "none");
    });
});
//開關區塊
//目前按鈕使用ID：slowdivbotton3
//目前區塊使用ID：slowdiv3
$(document).ready(function() {
    $(".eachclass").each(function(index) {
        $("#slowdivbotton" + index + "").css("cursor", "pointer");
        $("#slowdivbotton" + index + "").click(function() {
            $(".slowdiv" + index + "").toggle("slow");
            return false;
        });
    });
});
//區塊高度相等	
function sameheightfunction(divid) {
    if ($(divid).attr("name") == 'true') {
        var $range = $column - 1;
        var $difference = 10; //補差
        var $sections = $(divid+' .blockdiv');
        $sections.filter(':nth-child(' + $column + 'n-' + $range + ')').each(function(index) {
            var $index = index * 1500; //setTimeout時間each迴圈取index乘1500數值
            var $this = $(this),
                $els = $this.nextAll(':lt(' + $range + ')').addBack();
            var sectionheight = new Array();
            $els.each(function() {
                var value = $(this).height();
                sectionheight.push(value);
            });
            var newsectionheight = Math.max.apply(Math, sectionheight);
            if ($animationcss == 'animationtrue' && !$contentstrue) { //啟用視差
                setTimeout(function() {
                    $els.css({
                        "animation-duration": "2.0s",
                        "animation-name": "bottomr",
                        "margin-left": "0px",
                        "opacity": "1",
                        "min-height": newsectionheight + $difference
                    });
                }, $index);
            } else { //未啟用視差
                $els.css("min-height", newsectionheight + $difference);
            }
        })
    }
    $(divid).attr('name', 'false');
}
//右浮動選單
if ($rmenufloat == true) {
    $(window).scroll(function() {
        //取的頂端位置
        if (($(this).scrollTop()) > '150') {
            $("#fixmenu").css({
                "display": "block",
                "animation-name": "fixmenuslidein",
                "opacity": "1"
            });              	           	
        } else {
            $("#fixmenu").css({
                "display": "none",
                "animation-name": "",
                "opacity": "0"
            });
        }
    });
}
//內容頁面由標題開始讀取
$(window).load(function() {
    if ($contentstrue) {
        if ($opver != 'form' && $opver != 'releaseform' && ($opver != 'default' || $xoopsdirname != 'neilperiodical')) {
            $(window).mousewheel(function(e) {
                if (e.deltaY == 1) {
                    $("#header").css({
                        "visibility": "visible",
                        "height": "600px"
                    });
                    $("#menutbl").css({
                        "visibility": "visible",
                        "height": "55px"
                    });
                    $("#topbox").hide();
                }
            });
        }
        $('#topbox').click(function() {
            $("#header").css({
                "visibility": "visible",
                "height": "600px"
            });
            $("#menutbl").css({
                "visibility": "visible",
                "height": "55px"
            });
            $("#topbox").hide();
        });
    }
});

//滑動按鈕特效
/*$(window).scroll(function() {
  if ($tplenutype == '0') return false;
  var $scrollTopa = $(this).scrollTop();
  var position = $('#toplayerdiv').offset();
  var trigger=($("#toplayerdiv").attr("zoom") == '' || $("#toplayerdiv").attr("zoom") == '1') ? '230' : ('230' * $("#toplayerdiv").attr("zoom"));  
  if ($scrollTopa > trigger) {
    if ($zoomswitch) {
      //啟用放大縮小
      var $menulocation = ($("#toplayerdiv").attr("zoom") == '' || $("#toplayerdiv").attr("zoom") == '1') ? 0 : $scrollTopa / $("#toplayerdiv").attr("zoom");
      var $menutop = ($("#toplayerdiv").attr("zoom") == '' || $("#toplayerdiv").attr("zoom") == '1') ? 0 : -5;
    } else {
      //不啟用放大縮小
      var $menulocation = 0;
      var $menutop = 0;
      var x = position.left;
      $("#menutbl").css("left", x + "px");
    }
    //啟用滑動效果關閉上方區塊
    $(".slowdiv2").hide();
    $(".slowdiv1").hide();
    $("#menutbl").css({
      "animation-name": "slidein1",
      "position": "fixed",
      "margin-top": $menutop + "px",
      "top": $menulocation + "px"
    });
    $("#jGrowl").css("display", "none");
  } else {
    var $topvar = ($browser == 'IE11') ? "0px" : "initial";
    $("#menutbl").css({
      "animation-name": "",
      "position": "absolute",
      "margin-top": "161px",
      "left": "0px",
      "top": $topvar
    });
  }
});
*/

//滑動按鈕特效
/*$(window).scroll(function() {
  if ($tplenutype == '0') return false;
  var $scrollTopa = $(this).scrollTop();
  var position = $('#toplayerdiv').offset();
  var zoomval =$("#toplayerdiv").attr("zoom");
  var trigger=(zoomval === '1') ? '230' : ('230' * parseFloat(zoomval));  
  if ($scrollTopa > trigger) {
    if ($zoomswitch) {
      //啟用放大縮小
      var $menulocation = (zoomval === '1') ? 0 : $scrollTopa / parseFloat(zoomval);
      //var $menutop = (zoomval === '1') ? 0 : -5;
      var $menutop = 0;
    } else {
      //不啟用放大縮小
      var $menulocation = 0;
      var $menutop = 0;
      var x = position.left;
      $("#menutbl").css("left", x + "px");
    }
    //啟用滑動效果關閉上方區塊
    $(".slowdiv2").hide();
    $(".slowdiv1").hide();
    $("#menutbl").css({
      "animation-name": "slidein1",
      "position": "fixed",
      "margin-top": $menutop + "px",
      "top": $menulocation + "px"
    });
    $("#jGrowl").css("display", "none");
  } else {
    var $topvar = ($browser == 'IE11') ? "0px" : "initial";
    $("#menutbl").css({
      "animation-name": "",
      "position": "absolute",
      "margin-top": "161px",
      "left": "0px",
      "top": $topvar
    });
  }
});
*/

//滑動按鈕特效
$(window).scroll(function() {
  if ($tplenutype == '0') return false;
  var $scrollTopa = $(this).scrollTop();
  var position = $('#toplayerdiv').offset();
  var zoomval =$("#toplayerdiv").attr("zoom"); 
  var trigger=(zoomval == '' || zoomval == '1') ? '230' : ('230' * zoomval);  
  if ($scrollTopa > trigger) {
    if ($zoomswitch) {
      //啟用放大縮小
      var $menulocation = (zoomval == '' || zoomval == '1') ? 0 : $scrollTopa / zoomval;
      var $menutop = (zoomval == '' || zoomval == '1') ? 0 : -5;
    } else {
      //不啟用放大縮小
      var $menulocation = 0;
      var $menutop = 0;
      var x = position.left;
      $("#menutbl").css("left", x + "px");
    }
    //啟用滑動效果關閉上方區塊
    $(".slowdiv2").hide();
    $(".slowdiv1").hide();
    $("#menutbl").css({
      "animation-name": "slidein1",
      "position": "fixed",
      "margin-top": $menutop + "px",
      "top": $menulocation + "px"
    });
    $("#jGrowl").css("display", "none");
  } else {
    var $topvar = ($browser == 'IE11') ? "0px" : "initial";
    $("#menutbl").css({
      "animation-name": "",
      "position": "absolute",
      "margin-top": "161px",
      "left": "0px",
      "top": $topvar
    });
  }
});
$(document).ready(function() {
    $('.di01').html("<a name='neodw' aria-label=" + $di01 + ">" + $di01 + "</a>");
   if ($iframe == '') {
        $('.di02').html("<a target='_blank' href='https://creativecommons.org/licenses/by-sa/3.0/tw/legalcode' title=" + $di02 + ">" + $di02 + "</a>");
        if ($(".di01").length == 0) {
            $("#toplayerdiv").remove();
        } else if ($(".di02").length == 0) {
            $("#toplayerdiv").remove();
        }
    }
});
$(document).ready(function() {
    $('a[name="neodw"],#close').css("cursor", "pointer");
    $('a[name="neodw"]').click(function() {
        $('html,body').animate({
            scrollTop: $('#neodwboxanchored').offset().top
        }, 600);
        $("#neodwboxcentents").css({
            "animation-name": "slidein",
            "opacity": "0.9"
        });
        $("#neodwbox").show();
    });
    $('#close').click(function() {
        $("#neodwbox").hide();
    });
    $('a[name="neodw"]').mouseover(function() {
        $("#neodwtext").css({
            "animation-name": "slidein",
            "opacity": "0.9",
            "display": "block"
        });
    });
    $('a[name="neodw"]').mouseout(function() {
        $("#neodwtext").css("display", "none");
    });
    $("#goTop,#goTop2").click(function() {
        $("html,body").animate({
            scrollTop: 0
        }, 900);
    });
});