(function($) { $(function() { var featuresContainer$ = $("#rotator-features"); var features$ = featuresContainer$.children(".feature"); var dots$ = $(); var scroll$ = $(); CN = CN || {}; CN.style = CN.style || {}; CN.style.homepage = CN.style.homepage || {}; CN.style.homepage.rotatorTTL = 0; // how long between homepage visits to wait before repeating the rotator animation: [0, Infinity] CN.style.homepage.numRotatorLoops = 1; // how many times to loop the rotator animation: [0, Infinity] CN.style.homepage.rotatorDelay = 1e3; // how long to wait before beginning the rotator animation: [0, 9007199254740992] CN.style.homepage.rotatorPause = 4e3; // how long to wait between rotator features while animating: [0, 9007199254740992] bootstrap(); function bootstrap() { if (features$.length <= 1) return; /* var featurePromises = []; features$.each(function() { var featureDeferred = $.Deferred(); featurePromises.push(featureDeferred.promise()); var assets$ = $(this).find("[src]"); var assetPromises = []; assets$.each(function() { var assetDeferred = $.Deferred(); assetPromises.push(imageDeferred.promise()); var srcElement$ = $(this); var targetElement$ = srcElement$; if (srcElement$.is("param")) { var targetElement$ = srcElement$.parent("object"); if (targetElement$.length === 0) return; } else if (srcElement$.is("embed")) { var targetElement$ = srcElement$.parent("object"); if (targetElement$.length === 0) return; } var src = srcElement$.attr("src"); srcElement$.attr("src", ""); targetElement$.on("load", function() { assetDeferred.resolve(src); }).on("error", function() { assetDeferred.reject(src); }); srcElement$.attr("src", src); }); $.when.apply(this, assetPromises).then(function() { featureDeferred.resolve(images$); }); }); $.when.apply(this, featurePromises).then(function() { build(); if (isRotatorExpired()) animate(); }); */ $(window).load(function() { build(); if (isRotatorExpired()) animate(); }); } function build() { buildRotator(); buildNav(); function buildRotator() { features$.wrapAll("
"); scroll$ = features$.parent(".scroll"); var scrollWidth = 0; features$.each(function(index) { var feature$ = $(this); feature$.attr("data-ordinal", index); scrollWidth += $(this).width(); }); scroll$.css({ "width": scrollWidth + "px", "left": "0px", "height": features$.first().height() + "px" }); } function buildNav() { var navContainer$ = $(""); var nav$ = $("
    "); nav$.appendTo(navContainer$); navContainer$.appendTo(featuresContainer$); features$.each(function(index) { var feature$ = $(this); var dot$ = $("
  1. ").on("click", function() { $(this).trigger("activate"); }).on("activate", function() { rotateTo(feature$); }); dots$ = dots$.add(dot$); }); dots$.appendTo(nav$).first().addClass("active"); } } function animate() { featuresContainer$.one("click", function() { // first click interrupts the animation featuresContainer$.clearQueue(); }).delay(CN.style.homepage.rotatorDelay).queue(function(next) { var loops = 0; checkLoop(); function checkLoop() { if (loops < CN.style.homepage.numRotatorLoops) { queueLoop(); featuresContainer$.queue(function(next) { ++loops; checkLoop(); next(); }); } } function queueLoop() { features$.each(function() { featuresContainer$.queue(function(next) { rotateNext(); next(); }).delay(CN.style.homepage.rotatorPause); }); } next(); }); } function rotateNext() { var active$ = dots$.filter(".active"); var next$ = active$.next(); if (next$.length !== 0) { next$.trigger("activate"); } else { next$ = dots$.first(); var firstFeature$ = features$.first(); var secondFeature$ = firstFeature$.next(); scroll$.queue(function(next) { features$.last().after(firstFeature$.detach()); scroll$.css("left", "+=" + firstFeature$.width() + "px"); next(); }); next$.trigger("activate"); scroll$.queue(function(next) { secondFeature$.before(firstFeature$.detach()); scroll$.css({ "left": "0px" }); next(); }); } } function rotateTo(feature$) { var dot$ = dots$.eq(Number(feature$.attr("data-ordinal"))); if (dot$.hasClass("active")) return; else dot$.addClass("active").siblings().removeClass("active"); var leftOffset = 0; feature$.prevAll().each(function() { leftOffset += $(this).width(); }); scroll$.animate({ "left": -leftOffset + "px", "height": feature$.height() + "px" }, "slow"); } function saveRotatorVisit() { var rotatorVisit = String(new Date().getTime()); if (Modernizr.localstorage) { localStorage.setItem("rotator-visit", rotatorVisit); } else if (Boolean(document.cookie)) { CN.cookie.set("rotator-visit", rotatorVisit, { "expires": new Date(new Date().getTime() + (~~(CN.style.homepage.rotatorTTL / 1000))) }); } } function isRotatorExpired() { var rotatorVisit = null; if (Modernizr && Modernizr.localstorage) { rotatorVisit = localStorage.getItem("rotator-visit"); } else { rotatorVisit = CN.cookie.get("rotator-visit"); } if (!Boolean(rotatorVisit)) { return true; } else { return (new Date() - rotatorVisit > CN.style.homepage.rotatorTTL); } } }); }(jQuery));