var root_dir = '';
if (document.location.hostname.indexOf('localhost') != -1) {
  root_dir = '/sites/khomsanph.net';
}

$(document).ready(function() {
  $(".app_c2a").css("background-color", "#FFFFFF");

  $(".app_c2a[title^='VisualWget']").mouseenter(function() {
    $(".app_c2a").css("background-color", "#FFFFFF");
    $(this).css("background-color", "#eaf1cd");
  });
  $(".app_c2a[title^='VisualWget']").mouseleave(function() {
    $(this).css("background-color", "#FFFFFF");
  });

  $(".app_c2a[title^='MyLex']").mouseenter(function() {
    $(".app_c2a").css("background-color", "#FFFFFF");
    $(this).css("background-color", "#dce3f3");
  });
  $(".app_c2a[title^='MyLex']").mouseleave(function() {
    $(this).css("background-color", "#FFFFFF");
  });

  $(".app_c2a[title^='FireFaSt']").mouseenter(function() {
    $(".app_c2a").css("background-color", "#FFFFFF");
    $(this).css("background-color", "#f8e3d3");
  });
  $(".app_c2a[title^='FireFaSt']").mouseleave(function() {
    $(this).css("background-color", "#FFFFFF");
  });

  $(".app_c2a[title^='PikConv']").mouseenter(function() {
    $(".app_c2a").css("background-color", "#FFFFFF");
    $(this).css("background-color", "#cadde1");
  });
  $(".app_c2a[title^='PikConv']").mouseleave(function() {
    $(this).css("background-color", "#FFFFFF");
  });

  $(".app_c2a[title^='OtoShut']").mouseenter(function() {
    $(".app_c2a").css("background-color", "#FFFFFF");
    $(this).css("background-color", "#eccaca");
  });
  $(".app_c2a[title^='OtoShut']").mouseleave(function() {
    $(this).css("background-color", "#FFFFFF");
  });

  jQuery('a[href^=##]').click(function(event) {
    event.preventDefault();
    var a_name = jQuery(this).attr('href').substr(2);
    if (a_name == '') {
      var a_onclick = jQuery(this).attr('onclick');
      if (a_onclick == undefined) {
        scrollTo('body');
      }
    } else {
      scrollTo('a[name=' + a_name + ']');
    }
  });
});

function scrollTo(selector) {
  var targetOffset = jQuery(selector).offset().top;
  $('html,body').animate({
    scrollTop: targetOffset
  });
}

function sendMail() {
  var s = "cEKnbhBgom7m3UsXoajFn8a.dSPt8hoN@eGgzAmRnawTiXVlt4.UEcoaozym";
  var emailAddress = "";
  for (var i = 0; i + 2 * (i + 1) < s.length; i++) {
    emailAddress += s.substr(i + 2 * (i + 1), 1);
  }
  window.location.assign("mailto:" + emailAddress);
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
