// :nth-child
$(function () {
	$("#features article ul li:nth-child(3n+3)").addClass("last");
	$("#features article ul li:nth-child(4n+4)").addClass("first");
	$("ul#team_list li:nth-child(4n+4)").addClass("last");
	$("ul#team_list li:nth-child(4n+5)").addClass("first");
	$("#common_questions ul li:nth-child(3n+3)").addClass("last");
	$("#common_questions li:nth-child(3n+4)").addClass("first");
	$("#common_questions li:nth-child(8n+8)").addClass("mid");
	$("#our_customers_list ul li:nth-child(3n+3)").addClass("last");
	$("#our_customers_quotes article:nth-child(3n+3)").addClass("last");
	$("body#landing #features article ul li:nth-child(4n+5)").addClass("first");
});

// Promo/Referral Code Show/Hide
$('a#promo_and_referral_codes_trigger').click(function(e){
  e.preventDefault();
  $('#promo_and_referral_codes').slideToggle('fast');
})

//Retrieve a query string parameter
function getParameterByName(name) {
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if (results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function capturePromoAndReferralCodes() {
  var referralCode = getParameterByName("referral_code");
  if (referralCode != null && referralCode != "") {
    $.cookie("referral_code", referralCode, { expires: 7, path: "/" });
  }
  
  var promotional_code = getParameterByName("promotional_code");
  if (promotional_code != null && promotional_code != "") {
    $.cookie("promotional_code", promotional_code, { expires: 7, path: "/" });
  }

  var member_id = getParameterByName("member_id");
  if (member_id != null && member_id != "") {
    $.cookie("member_id", member_id, { expires: 7, path: "/" });
  }	
}
// Capture promo and referral codes on load
capturePromoAndReferralCodes();
