function time_ago_in_words(a) {
  return distance_of_time_in_words(new Date().getTime(), Date.parse(a))
}
function distance_of_time_in_words(b, a) {
  seconds_ago = ((b - a) / 1000);
  minutes_ago = Math.floor(seconds_ago / 60);
  if (minutes_ago == 0) {
    return "less than a minute"
  }
  if (minutes_ago == 1) {
    return "a minute"
  }
  if (minutes_ago < 45) {
    return minutes_ago + " minutes"
  }
  if (minutes_ago < 90) {
    return " about 1 hour"
  }
  hours_ago = Math.round(minutes_ago / 60);
  if (minutes_ago < 1440) {
    return "about " + hours_ago + " hours"
  }
  if (minutes_ago < 2880) {
    return "1 day"
  }
  days_ago = Math.round(minutes_ago / 1440);
  if (minutes_ago < 43200) {
    return days_ago + " days"
  }
  if (minutes_ago < 86400) {
    return "about 1 month"
  }
  months_ago = Math.round(minutes_ago / 43200);
  if (minutes_ago < 525960) {
    return months_ago + " months"
  }
  if (minutes_ago < 1051920) {
    return "about 1 year"
  }
  years_ago = Math.round(minutes_ago / 525960);
  return "over " + years_ago + " years"
}
twttr.anywhere(function (a) {
  a.User.find("hostroute").timeline().first(4).each(function (d) {
    if (d.text !== undefined) {
      var c = '<div class="tweet">';
      var b = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
      c += d.text.replace(b, '<a href="$1">$1</a>');
      c += '<div class="tweet_hours">';
      c += '<a href="http://www.twitter.com/';
      c += "hostroute/status/" + d.id + '">';
      c += "<time>" + time_ago_in_words(d.createdAt) + " ago</time></a></div>";
      c += "</div>";
      $("#tweet-container").append(c);
      a.hovercards()
    }
  });
  a("#follow-button").followButton("hostroute");
  a.hovercards()
});
function activatePlaceholders() {
  var d = navigator.userAgent.toLowerCase();
  if (d.indexOf("safari") > 0) {
    return false
  }
  var e = document.getElementsByTagName("input");
  for (var f = 0; f < e.length; f++) {
    if (e[f].getAttribute("type") == "text") {
      if (e[f].getAttribute("placeholder") && e[f].getAttribute("placeholder").length > 0) {
        e[f].value = e[f].getAttribute("placeholder");
        e[f].onclick = function () {
          if (this.value == this.getAttribute("placeholder")) {
            this.value = ""
          }
          return false
        };
        e[f].onblur = function () {
          if (this.value.length < 1) {
            this.value = this.getAttribute("placeholder")
          }
        }
      }
    }
  }
}
$(function () {
  $("#hosting-comparison tbody tr td.toggle").toggle(function () {
    $(this).text("View Less Features");
    $("#hosting-comparison tbody tr.more-features").show()
  }, function () {
    $(this).text("View More Features");
    $("#hosting-comparison tbody tr.more-features").hide()
  });
  $(".tabs").tabs();
  activatePlaceholders();
  var b = $.cookie("locale");
  $(".currency").hide();
  if (/(AT|BE|BG|CY|CZ|DK|EE|FI|FR|DE|GR|HU|IE|IT|LV|LT|LU|MT|NL|PL|PT|RO|SK|SI|ES|SE)/.test(b)) {
    $(".currency-EU").show();
  } else if (/(US|CA|MX)/.test(b)) {
    $(".currency-US").show();
  } else {
    $(".currency-GB").show();
  }
  if ($(".mini-domain-lookup")[0]) {
    $.ajax({
      async: true,
      url: "http://core.hostroute.com/setup_domain_tool.json?callback=?",
      type: "GET",
      dataType: "jsonp",
      success: function (f) {
        var e = f.available_to_register,
            a = "";
        $.each(e, function (c, d) {
          a += "<option val='" + d + "'>";
          a += d;
          a += "</option>"
        });
        $(".mini-domain-lookup").find("select").html(a)
      }
    })
  }
  $("ul#nav > li.dd").each(function () {
    var a = $(this).width(),
        h = $(this).height(),
        e = $(this).position(),
        g = $(this).find("ul");
    $(g).css({
      top: h + e.top + 12 + "px",
      left: e.left + 11 + "px"
    })
  });
  $("#hosting-comparison tbody tr td:first-child a.term").click(function () {
    return false
  });
  $("#hosting-comparison th:nth-child(even), #hosting-comparison tr:nth-child(even), #hosting-comparison td:nth-child(even), #other-hosting-features table tr:nth-child(even), .reseller-features tr:nth-child(even)").addClass("even");
  $("#hosting-comparison th:nth-child(odd), #hosting-comparison tr:nth-child(odd), #hosting-comparison td:nth-child(odd), #other-hosting-features table tr:nth-child(odd), .reseller-features tr:nth-child(odd)").addClass("odd");
  $("#hosting-comparison th:last-child, #hosting-comparison tr:last-child, #hosting-comparison td:last-child, #other-hosting-features table td:last-child, .reseller-features td:last-child").addClass("last");
  $("#phone-number span").qtip({
    content: $(this).attr("title"),
    position: {
      corner: {
        target: "bottomMiddle",
        tooltip: "topMiddle"
      }
    },
    style: {
      name: "light",
      tip: "topMiddle",
      fontSize: "12px",
      border: {
        width: 1,
        radius: 10
      },
      width: {
        max: 500
      },
      padding: 10
    }
  });
  $("#footer-phone-number").qtip({
    content: $(this).attr("title"),
    position: {
      corner: {
        target: "topMiddle",
        tooltip: "bottomMiddle"
      }
    },
    style: {
      name: "light",
      tip: "bottomMiddle",
      fontSize: "12px",
      border: {
        width: 1,
        radius: 10
      },
      width: {
        max: 500
      },
      padding: 10
    }
  });
  $("#hosting-comparison tbody tr td:first-child a.term").each(function () {
    $(this).qtip({
      content: $(this).next("div.definition"),
      position: {
        corner: {
          target: "rightMiddle",
          tooltip: "leftMiddle"
        }
      },
      style: {
        name: "blue",
        tip: "leftMiddle",
        fontSize: "12px",
        background: "#dae5ee",
        color: "#686868",
        border: {
          width: 1,
          radius: 10,
          color: "#364484"
        },
        width: {
          max: 500
        },
        padding: 10
      }
    })
  });
  $("#domain-transfer-container input").live("keyup keydown", function () {
    var a = $(this).parent().find("button");
    if ($(this).val().length == 0) {
      $(a).attr("disabled", "disabled")
    } else {
      $(a).attr("disabled", "")
    }
  });
  $("#domain-transfer-container form").live("submit", function () {
    $.ajax({
      type: "GET",
      url: "https://core.hostroute.com/transfer_eligibility.json?callback=?",
      data: {
        domain: $("#domain-transfer-container input").val()
      },
      dataType: "jsonp",
      success: function (e) {
        var g = (e.status == 200) ? true : false,
            d = $("#domain-transfer-notice");
        if (g) {
          if (e.transferrable) {
            var h = $.cookie("unauthed_domain_basket") || "[]",
                f, a;
            a = JSON.parse(h);
            a.push({
              n: e.sld,
              t: e.tld,
              p: 1,
              a: "transfer"
            });
            f = JSON.stringify(a);
            if (f.length > 4000) {
              throw ("Cannot add domain to cookie; too long (over 4,000 characters)")
            }
            $.cookie("unauthed_domain_basket", f, {
              domain: ".hostroute.com",
              path: "/"
            });
            $(d).addClass("success").text("Success! That domain has been added to your bucket. Enter another if you'd like, or click Checkout Now.");
            $("#domain-transfer-container input").val("");
            $("#domain-transfer-checkout-now").show()
          } else {
            $(d).addClass("failure").text("This domain is not eligible for transfer, and couldn't be added to your bucket. Please read the transfer eligibility guidelines to the right.")
          }
        } else {
          $(d).addClass("failure").text("An unknown error occurred while checking transfer eligibility. Please contact us for assistance.")
        }
        $("#domain-transfer-container button").attr("disabled", "").text("Transfer")
      }
    });
    $("#domain-transfer-notice").removeClass("success failure").text("");
    $("#domain-transfer-container button").attr("disabled", "disabled").text("Please wait...");
    return false;
  });
  $("#domain-transfer-guides").tabs({
    collapsible: true,
    selected: -1
  });
});
