if (top.location != self.location) {
  top.location = self.location.href
}

(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)

function replaceButtonImage(elem, search, replace) {
  src = $(elem).attr("src").replace(/_hover/g, "").replace(/_down/g, "");
  src = src.replace(search, replace);
  $(elem).attr("src", src);
}

function hashChecks() {
  if (location.hash == '') return;
  
  if ($(location.hash).length) {
    if ($("div.faq").length) {
      $("div.faq dl").has(location.hash).children('dt').show();
      $(location.hash).siblings(location.hash + ' + dd').animate({"opacity": "show", "height": "show"}, "fast");
    } else if ($("div.media").length) {
      $(location.hash).children("div.prContents").animate({"opacity": "show", "height": "show"}, "fast");
    } else if ($("div.features").length) {
      $(location.hash).children("p").animate({"opacity": "show", "height": "show"}, "fast");
    }
    $.scrollTo(location.hash, 1000);
  }
}

$(function() {
  $("div#frontMain").pngFix({"fix": ["main_slogan.png", "main_click_here_arrow.png"]});
  
  $("div.plans tr.prepay div").hide();
  $("div.businessPlans tbody:gt(0) tr:not(.subhead)").hide();
  $("div.features div.toggle p").hide();
  $("div.faq fieldset dt").hide();
  $("div.faq dd").hide();
  $("div.media div.pressRelease div.prContents").hide();
  
  $(window).hashchange(function() { hashChecks(location.hash)  });
  hashChecks(location.hash);
  
  $(".button img, img.button, input.button, #giantSignupButton img, div#planButtons img").each(function(i) {
    $.preLoadImages($(this).attr('src'));
  });
  
  $(".button img, img.button, input.button, #giantSignupButton img, div#planButtons img").hover(function() {
    replaceButtonImage(this, ".png", "_hover.png");
  }, function() {
    replaceButtonImage(this, "_hover.png", ".png");
  }).mousedown(function() {
    replaceButtonImage(this, ".png", "_down.png");
  }).mouseup(function() {
    replaceButtonImage(this, "_down.png", ".png");
  });

  $("div.plans tr.prepay span.trigger").toggleClass("pointer").addClass("clickable").attr("title", "Click to read more.");
  $("div.businessPlans tbody:gt(0) tr.subhead h4").toggleClass("pointer").addClass("clickable").attr("title", "Click for a price list.");
  $("div.features div.toggle h3").toggleClass("pointer").addClass("clickable").attr("title", "Click to expand.");
  $("div.faq dt").toggleClass("pointer").addClass("clickable").attr("title", "Click to find out the answer.");
  $("div.faq fieldset span.toggle").toggleClass("pointer").addClass("clickable").attr("title", "Click to expand.");
  $("div.prTitle").toggleClass("pointer").addClass("clickable").attr("title", "Click to read this press release.");
  
  $("div.plans tr.prepay span.trigger").click(function() {
    $("+ div", this).animate({"opacity": "toggle", "height": "toggle"}, "fast");
  });
  
  $("div.businessPlans tbody:gt(0) tr.subhead h4").click(function() {
    $(this).parent().parent().siblings().toggle();
  });
  
  $("div.features div.toggle h3").click(function() {
    $("~ p", this).animate({"opacity": "toggle", "height": "toggle"}, "fast");
  });

  $("div.faq fieldset span.toggle").click(function() {
    $("~ dl", this).children("dd").animate({"opacity": "hide", "height": "hide"}, "fast");
    $("~ dl", this).children("dt").animate({"opacity": "toggle", "height": "toggle"}, "fast");
  });
  
  $("div.faq dt").click(function() {
    $("+ dd", this).animate({"opacity": "toggle", "height": "toggle"}, "fast");
  });
  
  $("div.prTitle").click(function() {
    $("~ div.prContents", this).animate({"opacity": "toggle", "height": "toggle"}, "fast");
  });
  
  
  /* Form Hints */
  
  $("#loginBar input#username").focusin(function() {
    if ($(this).val() == "username") $(this).val("");
  }).focusout(function() {
    if ($(this).val() == "") $(this).val("username");
  });
  
  $("#loginBar input#password").focusin(function() {
    if ($(this).val() == "password") $(this).val("");
  }).focusout(function() {
    if ($(this).val() == "") $(this).val("password");
  });
  
  $("input#fields_fname").focusin(function() {
    if ($(this).val() == "First Name") $(this).val("");
  }).focusout(function() {
    if ($(this).val() == "") $(this).val("First Name");
  });
  
  $("input#fields_lname").focusin(function() {
    if ($(this).val() == "Last Name") $(this).val("");
  }).focusout(function() {
    if ($(this).val() == "") $(this).val("Last Name");
  });
  
  $("input#fields_email").focusin(function() {
    if ($(this).val() == "Email Address") $(this).val("");
  }).focusout(function() {
    if ($(this).val() == "") $(this).val("Email Address");
  });
  
  
  /* Provide Support Init */

  icpForm12994 = document.getElementById('icpsignup12994');

  if (document.location.protocol === "https:")
    icpForm12994.action = "https://app.icontact.com/icp/signup.php";
});

function verifyRequired12994() {
  if (icpForm12994["fields_email"].value == "" || icpForm12994["fields_email"].value == "Email Address") {
    icpForm12994["fields_email"].focus();
    alert("The Email field is required.");
    return false;
  }
  return true;
}