// JavaScript Document

//佈景外框高度
//目前編號slidein1
//table自適應
$(document).ready(function() {
  //$(".formatbox  table").addClass( "basictable" );
  //table->增加.basictable
  $('.basictable').basictable({
    breakpoint: 640,
    orceResponsive: true,
  });
});
//顯示字元限制
$(document).ready(function() {
  $(".blockdiv .blocktitle").each(function(index) {
    $idname = $(this).attr("name");
    var str = $(".blockdiv .blocktitleto" + $idname).text();
    $(".blockdiv .blocktitleto" + $idname).text(str.substr(0,(languagevar == 'en' ? "20" : "8")));
  });
  
  $(".contentframe .blocktitle").each(function(index) {
    $idname = $(this).attr("name");
    var str = $(".contentframe .blocktitleto" + $idname).text();
    $(".contentframe .blocktitleto" + $idname).text(str.substr(0, (languagevar == 'en' ? "80" : "34")));
  });
  
});


//迴圈操作區塊樣式關閉開啟
$(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!');
        }
      })
    })
  });
}

//右浮動選單
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"
      });
    }
  });
}
//去除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)); //輸出內容
    });
  });
}
/*======按鈕開關=============*/
$(document).ready(function() {
  $('#menubtn').css("cursor", "pointer");
  $('#menubtn2').css("cursor", "pointer");
  $("body").on("click", "#menubtn", function() {
    $("#menutbl").slideToggle("fast");
    $("#headerformbox").hide();
  })
  $("body").on("click", "#menubtn2", function() {
    $("#headerformbox").slideToggle("fast");
    $("#menutbl").hide();
  })
  $("body").on("click", "#menubtnclose", function() {
    $("#headerformbox").slideToggle("fast");
    $("html,body").animate({
      scrollTop: 0
    }, 900);
  })
});
//開關區塊
//目前按鈕使用ID：slowdivbotton5
//目前區塊使用ID：slowdiv5
$(document).ready(function() {
  $(".eachclass").each(function(index) {
    $("#slowdivbotton" + index + "").css("cursor", "pointer");
    $("#slowdivbotton" + index + "").click(function() {
      $(".slowdiv" + index + "").toggle("slow");
      $('html,body').animate({
        scrollTop: $('body').offset().top
      }, 900);
      return false;
    });
  });
});

//內容頁面移動到ID位置
$(window).load(function() {
  if ($contentstrue) {
    $('html,body').animate({
      scrollTop: $('#xo-content,#sponsorshiplist').offset().top
    }, 0);
    return false;
  }
});
$(document).ready(function() {
  $('.di01').html("<a name='neodw' title=" + $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").css("display", "none");
    } else if ($(".di02").length == 0) {
      $("#toplayerdiv").css("display", "none");
    }
  }
});
$(document).ready(function() {
  $('a[name="neodw"],#close').css("cursor", "pointer");
  $('a[name="neodw"],#close').click(function() {
    $('html,body').animate({
      scrollTop: $('#neodwboxanchored').offset().top
    }, 900);
    $("#neodwbox").toggle("slow");
  });
  $("#goTop,#goTop2").click(function() {
    $("html,body").animate({
      scrollTop: 0
    }, 900);
  });
});