var findProfileTour = null;
var nextIcon = '';
var prevIcon = '';
$(document).ready(function () {
//$('.mrp-mobile-screen').remove(); //remove mobile popup for now on MRP Site
var curBodyID = $("body").attr("ID");
//only show speedsport video player on profiles and news at this time
if (curBodyID != "profileBody_driver" && curBodyID != "profileBody_track" && curBodyID != "profileBody_assoc" && curBodyID != "profileBody_sch" && curBodyID != "newsBody") {
$("#div-gpt-ad-1509196665425-0").remove();
}
if (curBodyID == "homeBody") {
$("#homeSubScriptionWrap").insertBefore($("#homeHero"));
initPhotoFader("#homeHero .bg", 10000, 2200, "random");
//fix the search bar for tablet
//if ($(window).height() < 790) {
// initFullPages();
// $("#homeHero").css("background-position", "center -950px");
//}
//$(".mrp_fullPage .mrp_pageSub").innerHeight($(window).height() * .5);
//$("#sourceBar_topSearchWrap .txtWatermark").attr("placeholder", "Search for a Track, Series, or Driver");
//$("#homeHero .mrp_pageSub").append($("#sourceBar_topSearchWrap"));
//$("#sourceBar_topSearchWrap").prepend("
Lineups, Results, Points, and much more!
");
initSearchComplete();
initFeatured();
headlineItems = $("#headlineWrap .headlineContent").size();
$("#headlineWrap .headlineContent:eq(" + currHeadlineItem + ")").show();
$("#headlineNav li:eq(0)").addClass("active");
start_Int();
}
$(window).scroll(lazyload);
lazyload();
initMainNav();
initSliders();
//initFullPages();
//initHomeFades();
loadSnippets();
initExpands();
loadFoundStats();
initSignUpTour();
initSpecialNewsTypesModals();
formatAPIJson();
if (curBodyID == "needsBody" || curBodyID == "employmentBody")
initSuperPageCollapse();
if(curBodyID == "contactBody")
initContactPageExtras();
//if (curBodyID == "homeBody") {
// $(".mrp_pageCallout2").parent().insertAfter($(".elementWrap:eq(1)"));
//}
//if (curBodyID == "proTracksNewPricing")
// initPricingTable();
checkFA();
});
function checkFA() {
var mrpFaCookie = "mrpFaCheck";
function GetMrpFaCookie() {
var keyValue = document.cookie.match('(^|;) ?' + mrpFaCookie + '=([^;]*)(;|$)');
return keyValue ? keyValue[2] : null;
}
if (GetMrpFaCookie()) {
//check for old FA icons
$("*").each(function () {
if ($(this).hasClass("fa") && !$(this).hasClass("fas"))
alert($(this).attr("class"));
});
}
else if (querySt("checkMrpFa")) {
alert("setting cookie");
var date = new Date();
date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
var expires = '; expires=' + date.toUTCString();
document.cookie = mrpFaCookie + '=dismiss' + expires + "; path=/";
}
}
function getRndmFromSet(set) {
var rndm = Math.floor(Math.random() * set.length);
return set[rndm];
}
function initSearchComplete() {
var elWidth = Math.floor($("#sourceBar_topSearchWrap .mrp_input1").width() * .9);
$(".mrp_input1 input[type='text']").autocomplete("/ui/autocomplete.aspx?ref=d-t-a", {
scrollHeight: 400,
width: elWidth,
addTop: 0,
addLeft: 0,
delay: 5,
max: 30,
selectFirst: false,
formatResult: function (item) {
return item[0].replace(/(<.+?>)/gi, '');
}
}).result(function (event, item) {
location.href = item.attr("href");
});
}
function initMainNav() {
$(".navHover").hover(
function() {
$(this).find("ul").stop(true, true).show();
},
function() {
$(this).find("ul").stop(true, true).hide();
}
);
}
function initFeatured() {
var featureScroll = null;
if (!$(".featureFeedSub").is(":empty")) {
$(".featureFeedWrap").prepend($(".featureThumbsWrap"));
featureScroll = $(".featureFeed").scrollable({ vertical: false, clickable: false, loop: true, size: 1, keyboard: false, speed: 700, items: ".featureFeedSub", circular: true }).navigator(".featureThumbsWrap").autoscroll({ autoplay: false, interval: 4500, api: true });
$(".featureThumb:first").addClass("active");
if (featureScroll != null) {
featureScroll.play();
}
}
}
function initSliders() {
$('.bxSliderBg, .mrp_pageTestimonial .bxSlider').bxSlider({
auto: true,
autoHover: true,
pager: false,
nextText: nextIcon,
prevText: prevIcon
});
$('.bxSliderWithCaptions').bxSlider({
captions: true,
nextText: nextIcon,
prevText: prevIcon
});
$('.footFeatureWrap .pushItemSub').bxSlider({
nextText: nextIcon,
prevText: prevIcon,
infiniteLoop: true,
speed: 3000,
slideSelector: ".pushItemContent",
slideWidth: 388,
minSlides: 4,
maxSlides: 5
});
$('#mrpappBody .appScreenWrap').bxSlider({
auto: false,
nextText: nextIcon,
prevText: prevIcon,
infiniteLoop: false,
slideSelector: ".appScreen",
speed: 3000,
pager: false,
slideWidth: 200,
minSlides: 3,
maxSlides: 5
});
$('.bxFade').bxSlider({
mode: 'fade',
auto: false,
nextText: nextIcon,
prevText: prevIcon,
infiniteLoop: false,
slideSelector: ".item",
speed: 800,
pager: false,
slideWidth: 600
});
$('.bxSlider').bxSlider({
nextText: nextIcon,
prevText: prevIcon
});
}
var headlineItems;
var currHeadlineItem = 0;
var intVal = "";
function tickHeadline() {
$("#headlineWrap .headlineContent:eq(" + currHeadlineItem + ")").fadeOut("slow");
$("#headlineNav li:eq(" + currHeadlineItem + ")").removeClass("active");
currHeadlineItem = ++currHeadlineItem % headlineItems;
$("#headlineNav li:eq(" + currHeadlineItem + ")").addClass("active");
$("#headlineWrap .headlineContent:eq(" + currHeadlineItem + ")").fadeIn("slow");
}
function setHeadline(newItem) {
stop_Int();
$("#headlineWrap .headlineContent:eq(" + currHeadlineItem + ")").hide();
$("#headlineNav li:eq(" + currHeadlineItem + ")").removeClass("active");
currHeadlineItem = newItem;
$("#headlineNav li:eq(" + newItem + ")").addClass("active");
$("#headlineWrap .headlineContent:eq(" + currHeadlineItem + ")").show();
start_Int();
}
function stop_Int() {
if (intVal != "") {
clearInterval(intVal);
intVal = "";
}
}
function start_Int() {
if (intVal == "") {
intVal = setInterval("tickHeadline()", 10000);
}
else {
stop_Int();
}
}
function initFullPages() {
if ($(".mrp_fullPage").length > 0) {
if ($(window).height() > 600) {
var offSet1 = $("#siteHeader").outerHeight();
if ((".mrp_pageNav").length > 0) {
offSet1 = offSet1 + $(".mrp_pageNav").height();
}
$(".mrp_fullPage .mrp_pageSub").innerHeight($(window).height() - offSet1);
}
}
}
function initHomeFades() {
if ($("#homeHero").length > 0) {
$("#driverBanner").delay(400).fadeIn(2500);
$("#trackBanner").delay(800).fadeIn(2500);
$("#seriesBanner").delay(1200).fadeIn(2500);
}
}
function scrollDown(el) {
var amount = $(el).parent().height();
if ($(window).scrollTop() > 0)
amount += $(window).scrollTop();
else
amount += $("#siteHeader").height();
$(window).scrollTo({ top: amount + "px", left: 0 }, 800);
return false;
}
function loadSnippets() {
if ($(".loadSnippet").length > 0) {
$(".loadSnippet").each(function() {
var path = $(this).attr("rel");
$(this).load(path, function() {
initToolTips();
initExpands();
});
});
}
}
function initExpands() {
if ($(".mrp_expandTitle").length > 0) {
$(".mrp_expandTitle").each(function() {
$(this).on('click', this, function(e) {
e.preventDefault();
$(this).next().toggle();
});
});
}
}
function mrpDoBack() {
window.history.back();
}
function iAdmin(curHref) {
doTempPanelFix(curHref);
}
function iUser(curHref) {
doTempPanelFix(curHref);
}
function doTempPanelFix(curHref) {
if (curHref.toLowerCase().indexOf("submit.aspx") > -1) {
$.colorbox({ href: curHref, iframe: true, width: "800px", height: "700px" })
}
else if (curHref.toLowerCase().indexOf("signin.aspx") > -1) {
//window.location = "/myaccount/signin.aspx?ret=" + encodeURIComponent((location.pathname + location.search).substr(1));
$.colorbox({ href: curHref + "#siteMainSub", iframe: true, width: "800px", height: "600px", onClosed: function() { location.reload(true); } })
}
}
function loadFoundStats() {
if ($("#mrp_networkStats").length > 0) {
var rel = $("#mrp_networkStats").attr("rel");
var rt = rel.split('_')[0];
var r = rel.split('_')[1];
$("#mrp_networkStats").load("/ui/profileFind.aspx?actn=stats&r=" + r + "&rt=" + rt);
}
}
function initSignUpTour() {
if ($("#findProfileWrap").length > 0 && $(window).width() > 1120) {
// Instance the tour
findProfileTour = new Tour({
name: "tour",
steps: [
{
element: "#findProfileWrap",
title: "Find your profile!",
content: "Start by typing the name of your driver, track, or series in this box. If your profile pops up, click it to select.",
placement: "left"
},
{
element: "#profilePhoneWrap",
title: "Enter your phone",
content: "Enter your phone number so we can verify your profile.",
placement: "left"
}],
storage: false,
template: ""
});
// Initialize the tour
findProfileTour.init();
// Start the tour
findProfileTour.start();
}
}
function initSpecialNewsTypesModals() {
if ($("body").attr("ID") == "mrpappBody") {
$("#mrpappBody .modalBox").colorbox({
maxWidth: "80%",
maxHeight: "90%"
});
}
//$(".mrp_inlineImageWrap img").each(function() {
// var curImgID = $(this).attr("src").split("-")[1];
// $(this).wrap("");
//});
//$(".mrp_inlineImageWrap a").colorbox({ rel: 'inlineImageGroup1' });
}
function formatAPIJson(){
if ($("pre.jsonOutput").length > 0) {
$("pre.jsonOutput").each(function() {
var jsonStr = $(this).text();
var jsonObj = JSON.parse(jsonStr);
var jsonPretty = JSON.stringify(jsonObj, null, 2);
$(this).text(jsonPretty);
// var path = $(this).attr("rel");
// $(this).load(path, function() {
// initToolTips();
// initExpands();
// });
});
}
}
function initContactPageExtras(){
$(".contentSubHead:eq(0)").append("");
$(".fieldWrapCol260").append($(".buttonWrap"));
}
function initSuperPageCollapse(){
if ($(".elementHeading").length > 0) {
$(".elementHeading .headSpec a").click(function(event) {
event.stopPropagation();
});
$(".elementHeading").each(function() {
var i = $(".elementHeading").index($(this));
$(this).addClass("elementHeadingHoverable");
$(this).nextUntil(".elementHeading").wrapAll("");
$(this).click(function() {
$(".elementSubWrap" + i).slideToggle();
});
});
}
}
function initPricingTable() {
$(".mrp_plansTable").delegate('td', 'mouseover mouseleave', function (e) {
if (e.type == 'mouseover') {
$(this).parent().addClass("hover");
$("colgroup").eq($(this).index()).addClass("hover");
}
else {
$(this).parent().removeClass("hover");
$("colgroup").eq($(this).index()).removeClass("hover");
}
});
}
function lazyload() {
$.ajaxSetup({
// Disable caching of AJAX responses
cache: false
});
var wt = $(window).scrollTop(); //* top of the window
var wb = wt + $(window).height(); //* bottom of the window
$(".mrp-lazyLoad:empty").each(function () { //mark the element as pending and show a loader
$(this).addClass("mrp-pending");
$(this).append('
');
});
$(".mrp-lazyLoad.mrp-pending").each(function () { //only search pending elements
var ot = $(this).offset().top; //* top of object (i.e. advertising div)
var ob = ot + $(this).height(); //* bottom of object
if ((wt <= ob && wb >= ot) || (ot - 100 <= wb)) {
requestLazy($(this));
}
});
}
function requestLazy(el) {
var lazyURL = $(el).attr("data-mrp-lazy");
var lazyCallback = $(el).attr("data-mrp-lazy-callback");
$(el).removeClass("mrp-pending"); //don't try load again
$(el).load(lazyURL, function () {
if (lazyCallback != null) {
eval(lazyCallback);
}
$(this).find($(".mrp-preload")).html("--No data found--"); //if the loader is still showing, nothing was returned
});
}
function scrollSideMerch() {
if ($(".sideMerchWrap .pushItemSub").html().indexOf("No data found") > -1)
$(".sideMerchWrap").remove();
var itemCount = $('.sideMerchWrap .pushItemSub .pushItemPicWrap').length;
$('.sideMerchWrap .pushItemSub').bxSlider({
auto: itemCount > 1 ? true : false,
pager: false,
randomStart: true,
nextText: nextIcon,
prevText: prevIcon,
infiniteLoop: true,
speed: 1000,
slideSelector: ".pushItemContent",
slideWidth: 300,
minSlides: 1,
maxSlides: 1
});
}
function scrollFootMerch() {
if ($("#footMarketWrap .pushItemSub").html().indexOf("No data found") > -1)
$("#footMarketWrap").remove();
$('#footMarketWrap .pushItemSub').bxSlider({
nextText: nextIcon,
prevText: prevIcon,
infiniteLoop: true,
speed: 2000,
slideSelector: ".pushItemContent",
slideWidth: 300,
minSlides: 3,
maxSlides: 8
});
}