/* Js for , Version=1790093362 */
 if(typeof(v) != "object") v = {};v.theme = {"template":"default","theme":"wide","device":"desktop"};;v.lang = {"confirmDelete":"Do you want to delete it?","deleteing":"Deleting","doing":"Doing","loading":"Loading","updating":"Updating","timeout":"Timeout. Please try it again.","errorThrown":"Error : ","continueShopping":"Continue shopping","required":"Required","back":"Back","continue":"Continue","bindWechatTip":"Posting sets the limit for binding WeChat. Please bind WeChat user first.","importTip":"Old layout data will be replaced","fullImportTip":"Old article, product, layout data will be replaced and import test data"};;
$(function()
{
    var $link = $('#navbar').find('.js-try-for-free');
    if(!$link.length) return;

    var raw = $.cookie('siteContext');
    if(!raw) return;

    var siteContext = {};
    try
    {
        siteContext = JSON.parse(raw) || {};
    }
    catch(e)
    {
        return;
    }

    var siteNumber = parseInt(siteContext.siteNumber, 10);
    if(isNaN(siteNumber)) siteNumber = 0;

    var defaultTryUrl = $link.data('defaultTryUrl');
    var chooseSiteUrl = $link.data('chooseSiteUrl');
    var loginSiteTpl  = $link.data('loginSiteTpl');
    var siteID        = siteContext.siteID || '';
    var userSite      = siteContext.userSite || '';

    if(defaultTryUrl) $link.attr('href', defaultTryUrl);

    if(siteNumber > 1)
    {
        $link.attr('href', chooseSiteUrl);
        return;
    }

    if(siteNumber === 1 && userSite && siteID && loginSiteTpl)
    {
        $link.attr('href', loginSiteTpl.replace('__SITE_ID__', siteID));
    }
});
;v.path = [4];;v.objectType = "article";;v.categoryID = 4;;v.objectID = 106;;
;v.pageLayout = "global";;$(document).ready(function()
{
  /* Set current active topNav. */
  if(v.path && v.path.length)
  {
      $.each(v.path, function(index, category)
      {
          $('.nav-blog-' + category).addClass('active');
      })
  }
  else
  {
      $('.tree li:first-child').addClass('active');
  }

  if(typeof(v.categoryID) != 'undefined') $('#category' + v.categoryID).parent().addClass('active');
  $('#navbar li.active').parents('li').addClass('active');

  $('body').tooltip(
  {
      html: true,
      selector: "[data-toggle=tooltip]",
      container: "body"
  });

  $('.blog-header .icon-search').click(function()
  {
      $(this).parent('form').submit();
  });

  setTimeout(function(){$('.nav-system-blog').parents('.dropdown').addClass('active'); $('.nav-system-blog').addClass('active')}, 10);
});
$(document).ready(function()
{
    function basename(str)
    {
        var pos = str.lastIndexOf('/');
        return str.substring(pos + 1,str.length);
    }

    $('.article-content img').click(function(){
        var itemSrc  = $(this).attr('src');
        var itemName = basename(itemSrc).split('&')[0];
        if(typeof(itemName) == 'string')
        {
            $('.files-list .' + itemName).click();
        }
    });
});
$(function()
{
    $('.related-blogs .tag').click(function(e)
    {
        e.stopPropagation();
        e.preventDefault();
        location.href = $(this).parent('.tag-wrapper').data('url');
    });

    $('.article-cover .expand-cover').click(function()
    {
        $(this).siblings('img').toggleClass('expanded');
        if($(this).siblings('img').hasClass('expanded'))
        {
            document.querySelector('.article-cover .icon-collapse').classList.remove('hidden');
            document.querySelector('.article-cover .icon-expand').classList.add('hidden');
        }
        else
        {
            document.querySelector('.article-cover .icon-collapse').classList.add('hidden');
            document.querySelector('.article-cover .icon-expand').classList.remove('hidden');
        }
    });
});
var lang = $.cookie('browseLang');
if (!lang) {
  lang = /^zh/i.test(navigator.language || '') ? 'zh-cn' : 'en';

  $.cookie('browseLang', lang, {
      expires: 365,
      path: '/',
      secure: true,
      sameSite: 'lax'
  });

  var url = new URL(location.href);
  var isCnPath =
      url.pathname === '/cn' ||
      url.pathname.indexOf('/cn/') === 0;

  if (lang === 'en' && isCnPath) {
      // /cn、/cn/XXX -> /、/XXX
      url.pathname = url.pathname.substring(3) || '/';
      location.replace(url.href);
  } else if (lang === 'zh-cn' && !isCnPath) {
      // /、/XXX -> /cn/、/cn/XXX
      url.pathname = '/cn' + url.pathname;
      location.replace(url.href);
  }
}
;
$(document).ready(function()
{
    $('a[data-download=1]').each(function()
    {
        link = window.btoa(window.encodeURIComponent($(this).attr('href')));
        fileName = window.btoa(window.encodeURIComponent($(this).text()));
        $(this).attr('data-toggle', 'modal').attr('href', createLink('misc', 'download', 'link=' + link + '&fileName=' + fileName));
    });
})
;
function loadCartInfo(twinkle)
{
    $('#siteNav').load(createLink('misc', 'printTopBar'),
        function()
        {
            if(twinkle)
            {
                bootbox.dialog(
                {
                    message: v.addToCartSuccess,
                    buttons:
                    {
                        back:
                        {
                            label:     v.lang.continueShopping,
                            className: 'btn-primary',
                            callback:  function(){location.reload();}
                        },
                        cart:
                        {
                            label:     v.gotoCart,
                            className: 'btn-primary',
                            callback:  function(){location.href = createLink('cart', 'browse');}
                        }
                    }
                });
            }
        }
    );
}
;
var hash = window.location.hash.substring(1);
var browserLanguage = navigator.language || navigator.userLanguage;
var resolution      = screen.availWidth + ' X ' + screen.availHeight;
$.get(createLink('log', 'record', "hash=" + hash), {browserLanguage:browserLanguage, resolution:resolution});
