$(document).ready(function (){
  //ToolTop
  menuHover($("#menu li>a"), $("#menu li p"), function (_this){
    _this.siblings().addClass("OnCurt");
  }, function (_this){
    _this.siblings().removeClass("OnCurt");
  }, 200);
  //Navbar
  var timer;
  $("#Navbar").hover(function (){
    clearTimeout(timer);
    timer = setTimeout(function (){
      $("#ToolNav").addClass("ToolNavbar-hover");
    }, 300);
  }, function (){
    clearTimeout(timer);
    $("#ToolNav").removeClass("ToolNavbar-hover");
  });
  $(".WrapHid").each(function (){
    checkFocus({
      obj_input: $(this), msgBox: $(this).siblings(".CentHid"), Tip: "CentHid"
    });
    clearInput({
      obj_input: $(this), msgBox: $(this).siblings("._CentHid"), Tip: "_CentHid"
    });
  });
  $(".ToolChoese").each(function (){
    _select({
      select: $(this).find(".SearChoese"),
      options: $(this).find("ul.SearChoese-show"),
      option: $(this).find("ul.SearChoese-show li a"),
      t: "slide", //效果（可选参数）
      parents: $(".ToolChoese")//多个select时，传入父级（可选参数）
    });
  });
  Init();
});
function menuHover(menuObj, menuItem, itemOverbackall, itemOutbackall, timer){
  if (!timer) timer = 200;
  var hoverTimer, outTimer;
  menuObj.hover(function (){
    var _this = $(this);
    clearTimeout(hoverTimer);
    hoverTimer = setTimeout(function (){
      menuItem.hide();
      _this.nextAll().show();
    }, timer);
  }, function (){
    var _this = $(this);
    clearTimeout(outTimer);
    outTimer = setTimeout(function (){
      _this.nextAll().hide();
    }, timer);
  });
  menuItem.hover(function (){
    var _this = $(this);
    clearTimeout(hoverTimer);
    hoverTimer = setTimeout(function (){
      _this.show();
    }, timer);
    if (itemOverbackall) itemOverbackall(_this);
  }, function (){
    var _this = $(this);
    clearTimeout(outTimer);
    outTimer = setTimeout(function (){
      _this.hide();
    }, timer);
    if (itemOutbackall) itemOutbackall(_this);
  });
}
function getid(id){
  return (typeof id == "string") ? document.getElementById(id) : id
}
//获取url参数值
function Init(){
  var currentInput = null;
  var showtype = "url";
  var trime;
  var inputSave = {
    OnKeyup: function (e){
      var obj = e.target ? e.target : e.srcElement;
      if (window.location.href.indexOf("ddlSearchMode=2") === -1) {
        if (/\s+/.test(obj.value)) $(obj).val($(obj).val().replace(/\s+/g, ""));
      }
      setTimeout(function (){
        inputSave.addInput("" + obj.id + "", this)
      }, 200);
    }, BoxShowUrls: function (e){
      if (currentInput) {
        if ($(currentInput).siblings(".CentHid").hasClass("col-red")) $(currentInput).siblings(".CentHid").removeClass("col-red")
      }
      inputSave.BoxShowTime(e, "url");
    }, BoxHide: function (e){
      clearTimeout(trime);
      trime = setTimeout(function (){
        if (getid("ToolBox")) {
          getid("ToolBox").style.display = "none";
          var tags = document.getElementsByTagName("input");
          for (var i = 0; i<tags.length; i++) {
            if (tags[i].getAttribute("f") === "1") {
              tags[i].setAttribute("f", 0)
            }
          }
        }
      }, 200);
    }, OnPaste: function (e){
      var obj = e.target ? e.target : e.srcElement;
      setTimeout(function (){
        inputSave.MoveHttp("" + obj.id + "")
      }, 200);
    }, BoxShowWords: function (e){
      inputSave.BoxShowTime(e, "words");
    }, BoxShowCname: function (e){
      inputSave.BoxShowTime(e, "cname");
    }, BoxShowIcpcode: function (e){
      inputSave.BoxShowTime(e, "icpcode");
    }, BoxShowTime: function (e, b){
      if (getid("ToolBox")) getid("ToolBox").style.display = "none";
      clearTimeout(trime);
      trime = setTimeout(function (){
        showtype = b;
      }, 200);
    }, addInput: function (id, _this){
      var obj = getid(id);
      if (!obj) return;
      if (obj.value.indexOf("。")>0) {
        obj.value = obj.value.replace("。", ".");
      }
      this.value = obj.value;
    }, MoveHttp: function (id){
      var val = getid(id).value;
      //网站测速区分https
      if (location.pathname.toLowerCase().indexOf("speedtest")>0 || location.pathname.toLowerCase().indexOf("speedworld")>0 || location.pathname.toLowerCase().indexOf("speedcom")>0) val = val.replace(/http:\/\//i, ""); else val = val.replace(/http(s)?:\/\//i, "");
      var temp = val.split("/");
      if (temp.length<=2) {
        if (val[val.length - 1] === "/") {
          val = val.substring(0, val.length - 1);
        }
      }
      getid(id).value = val;
    }
  }
  $("input[url='true']").bind({
    keyup: inputSave.OnKeyup, mousedown: inputSave.BoxShowUrls, mouseout: inputSave.BoxHide, paste: inputSave.OnPaste
  });
}