(function(){var containers = [{"id":"grv-personalization-16","url":"http://rma-api.gravity.com/v1/api/intelligence/w2?sg=361837bc83c4c2cba7b350dff56a564f&pl=16&ug=&b=59&ad=&sp=332","width":"300px","height":"250px","siteGuid":"361837bc83c4c2cba7b350dff56a564f","placement":16,"userGuid":""}];
/*
  Provides GravityUtils.includeJs() to dynamically source JavaScripts.
*/

/*
  @param {String}   url
  @param {Function} onSuccess Called on script load success.
  @param {Function} onError   Called on script load error.
*/

if (!window.GravityUtils) {
  window.GravityUtils = {};
}

if (!window.GravityUtils.includeJs) {
  window.GravityUtils.includeJs = function(url, onSuccess, onError) {
    var loadHandled, loadHandler, s, someScript;
    if (onSuccess == null) {
      onSuccess = (function() {});
    }
    if (onError == null) {
      onError = (function() {});
    }
    s = document.createElement('script');
    s.async = true;
    loadHandled = false;
    loadHandler = function() {
      loadHandled = true;
      s.onreadystatechange = s.onload = null;
      return onSuccess();
    };
    s.onreadystatechange = function() {
      if (!loadHandled && (!this.readyState || this.readyState === 'complete' || this.readyState === 'loaded')) {
        return loadHandler();
      }
    };
    s.onload = function() {
      if (!loadHandled) {
        return loadHandler();
      }
    };
    if (s.addEventListener) {
      s.addEventListener('error', onError, false);
    } else if (s.attachEvent) {
      s.attachEvent('onerror', onError);
    }
    s.src = url;
    someScript = document.getElementsByTagName('script')[0];
    return someScript.parentNode.insertBefore(s, someScript);
  };
}

/*
  Provides GravityUtils.insertStyleBlock() to insert style blocks into the page. Especially useful in situations where
  external stylesheets aren't feasible, or when styles need to be introduced for async loaded elements that aren't
  present at the time of style determination.
*/

/*
  @param {String} css The inner CSS content of the style block.
*/

if (!window.GravityUtils) {
  window.GravityUtils = {};
}

if (!window.GravityUtils.insertStyleBlock) {
  window.GravityUtils.insertStyleBlock = function(css) {
    var head, style;
    head = document.head || document.getElementsByTagName('head')[0];
    style = document.createElement('style');
    style.type = 'text/css';
    if (style.styleSheet) {
      style.styleSheet.cssText = css;
    } else {
      style.appendChild(document.createTextNode(css));
    }
    return head.appendChild(style);
  };
}

var documentElem, _ref;

documentElem = window.document.documentElement;

/*
  @param {Object} elem                Native DOM element.
  @param {Number} inViewThreshold     Square pixel area of element that must be in viewport in order to consider it in view.
                                      Default is 100x100 square.
  @param {Number} absMinViewThreshold If the entire widget area is less than inViewThreshold (i.e. a very small widget),
                                      this absolute min view threshold will be used instead considering that the widget
                                      would otherwise never be counted as "in view."

  @return {Boolean}
*/


if ((_ref = window.grvElemInView) == null) {
  window.grvElemInView = function(elem, inViewThreshold, absMinViewThreshold) {
    var elemArea, elemHeight, elemRect, elemWidth, heightInView, inView, widthInView, windowHeight, windowWidth;
    if (inViewThreshold == null) {
      inViewThreshold = 10000;
    }
    if (absMinViewThreshold == null) {
      absMinViewThreshold = 4000;
    }
    inView = false;
    elemRect = elem.getBoundingClientRect();
    windowHeight = documentElem.clientHeight;
    elemWidth = elemRect.right - elemRect.left;
    elemHeight = elemRect.bottom - elemRect.top;
    elemArea = elemWidth * elemHeight;
    if ((absMinViewThreshold <= elemArea && elemArea <= inViewThreshold)) {
      inViewThreshold = absMinViewThreshold;
    }
    if ((elemRect.top >= 0 && elemRect.top < windowHeight) || (elemRect.bottom >= 0 && elemRect.bottom < windowHeight) || (elemRect.top < 0 && elemRect.bottom >= windowHeight)) {
      windowWidth = documentElem.clientWidth;
      if ((elemRect.left >= 0 && elemRect.left < windowWidth) || (elemRect.right >= 0 && elemRect.right < windowWidth) || (elemRect.left < 0 && elemRect.right >= windowWidth)) {
        widthInView = Math.min(elemRect.right, windowWidth) - Math.max(elemRect.left, 0);
        heightInView = Math.min(elemRect.bottom, windowHeight) - Math.max(elemRect.top, 0);
        if (widthInView * heightInView > inViewThreshold) {
          inView = true;
        }
      }
    }
    return inView;
  };
}

/*
  Shows the attribution modal, lazily initting it if necessary.

  Can be called either from same window (JSONP widgets) or via postMessage from widget to widget loader (iframe widgets).

  @requires insertStyleBlock.coffee
*/

window.grvShowAttributionModal = function($) {
  var $box, $closeBtn, $document, $overlay, $window, bindOverlayEvents, closeDialog, closeOnEscape, maintainOverlaySize, openDialog, setOverlaySize, unbindOverlayEvents, _ref,
    _this = this;
  $window = $(window);
  $document = $(document);
  if ((_ref = this.isVisible) == null) {
    this.isVisible = false;
  }
  if (!this.$overlay) {
    GravityUtils.insertStyleBlock("#grv_attr_overlay {\n  background: rgb(0,0,0);\n  background: rgba(0,0,0,0.6);\n  position: absolute;\n  top: 0px;\n  left: 0px;\n  z-index: 1000;\n  font-family: 'Source Sans Pro', 'helvetica neue', helvetica, sans-serif, arial;\n  display: none;\n}\n#grv_attr_box {\n  background: #fff url(http://i.api.grvcdn.com/personalization/gravity_com_logo.932f1275dd5d743c1ae799763120a12c.png) no-repeat center 30px;\n  border-radius: 4px;\n  -moz-border-radius: 4px;\n  -webkit-border-radius: 4px;\n  padding: 85px 30px 30px;\n  width: 330px;\n  text-align: center;\n  position: absolute;\n  display: none;\n}\n#grv_attr_box p.grv_p {\n  font-size: 15px;\n  line-height: 18px;\n  margin-bottom: 10px;\n  font-weight: 300;\n  color: #505050;\n}\na.grv_btn_blue {\n  background: #09f;\n  border-radius: 4px;\n  -moz-border-radius: 4px;\n  -webkit-border-radius: 4px;\n  color: #fff !important;\n  font-size: 16px;\n  font-weight: 200;\n  padding: 6px 12px;\n  outline: none;\n  text-decoration: none !important;\n}\na.grv_btn_blue:hover {\n  background: #f90;\n}\n#grv_attrib_close_btn {\n  background: #505050;\n  color: #fff;\n  width: 30px;\n  height: 30px;\n  line-height: 30px;\n  vertical-align: middle;\n  text-align: center;\n  font-size: 15px;\n  font-weight: 100;\n  position: absolute;\n  top: -15px;\n  right: -15px;\n  display: block;\n  border-radius: 30px;\n  -moz-border-radius: 30px;\n  -webkit-border-radius: 30px;\n  cursor: pointer;\n}\n#grv_attrib_close_btn:hover {\n  background: #09f;\n}");
    this.$overlay = $("<div id=\"grv_attr_overlay\">\n  <div id=\"grv_attr_box\">\n    <p class=\"grv_p\">These stories are recommended for you by Gravity.</p>\n    <p class=\"grv_p\">The recommendations may include stories from other partners, some of whom pay to include their content here.</p>\n    <a href=\"http://www.gravity.com/consumers\" target=\"_blank\" class=\"grv_btn_blue\">Learn More</a>\n    <div id=\"grv_attrib_close_btn\">X</div>\n  </div>\n</div>").hide().appendTo('body');
    this.$box = $('#grv_attr_box');
    this.$closeBtn = $('#grv_attrib_close_btn');
  }
  $overlay = this.$overlay;
  $box = this.$box;
  $closeBtn = this.$closeBtn;
  setOverlaySize = function() {
    return $overlay.height($document.height()).width($document.width());
  };
  maintainOverlaySize = function() {
    var _this = this;
    if (this.resizeTimeoutHandle) {
      clearTimeout(this.resizeTimeoutHandle);
    }
    return this.resizeTimeoutHandle = setTimeout((function() {
      _this.resizeTimeoutHandle = null;
      return setOverlaySize();
    }), 50);
  };
  bindOverlayEvents = function() {
    $window.resize(maintainOverlaySize);
    $document.keyup(closeOnEscape);
    $overlay.add($closeBtn).click(closeDialog);
    return $box.click(function(e) {
      return e.stopPropagation();
    });
  };
  unbindOverlayEvents = function() {
    $window.unbind('resize', maintainOverlaySize);
    $document.unbind('keyup', closeOnEscape);
    $overlay.add($closeBtn).unbind('click', closeDialog);
    return $box.unbind('click');
  };
  closeDialog = function() {
    _this.isVisible = false;
    unbindOverlayEvents();
    return $box.stop().fadeOut('fast', function() {
      return $overlay.stop().fadeOut('slow');
    });
  };
  closeOnEscape = function(e) {
    if (e.which === 27) {
      return closeDialog();
    }
  };
  openDialog = function() {
    _this.isVisible = true;
    setOverlaySize();
    $box.add($overlay).css('opacity', 0).show();
    $box.css('top', $window.scrollTop() + $window.height() / 2 - $box.outerHeight() / 2);
    $box.css('left', $window.scrollLeft() + $window.width() / 2 - $box.outerWidth() / 2);
    bindOverlayEvents();
    return $overlay.animate({
      opacity: 1
    }, 'slow', function() {
      return $box.animate({
        opacity: 1
      }, 'fast', function() {
        if (window.focus) {
          window.focus();
        }
        if (document.activeElement && document.activeElement.blur) {
          return document.activeElement.blur();
        }
      });
    });
  };
  if (this.isVisible) {
    return closeDialog();
  } else {
    return openDialog();
  }
};

var jqueryAssetUrl, loadWidgets, secure, _ref,
  __hasProp = {}.hasOwnProperty;

if ((_ref = window.grvPageViewId) == null) {
  window.grvPageViewId = {
    widgetLoaderWindowUrl: window.location.href,
    timeMillis: new Date().getTime().toString(),
    rand: Math.random().toString().replace('.', '').replace(/^0+/, '')
  };
}

loadWidgets = function($) {
  var $window, bindEvent, c, frameUrl, inputSourceUrl, isEmptyObject, lastHeight, msgDataToIframe, msgDataToIframeOnScroll, postMessageSupported, receiveMessage, showWidget, sourceUrl, _base, _base1, _fn, _i, _len, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
  bindEvent = function(eventName, handler) {
    if (window.addEventListener) {
      return window.addEventListener(eventName, handler, false);
    } else if (window.attachEvent) {
      return window.attachEvent("on" + eventName, handler);
    }
  };
  $window = $(window);
  postMessageSupported = !!window.postMessage;
  msgDataToIframe = {};
  msgDataToIframeOnScroll = {};
  showWidget = function(container) {
    var cb, containerCss, containerId, _i, _len, _ref1, _ref2;
    if ((_ref1 = window.grvWidgetSuccessCallbacks) != null ? _ref1.length : void 0) {
      containerId = container.attr('id');
      _ref2 = window.grvWidgetSuccessCallbacks;
      for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
        cb = _ref2[_i];
        cb(containerId);
      }
    }
    containerCss = {
      position: 'static',
      left: 'auto',
      top: 'auto'
    };
    if (container.hasClass('grvRestore100PercentWidth')) {
      containerCss.width = '100%';
    }
    return container.css(containerCss);
  };
  if ((_ref1 = window.grvDestroyWidget) == null) {
    window.grvDestroyWidget = function(containerId) {
      var elem, iframeAndContainer, iframeCollection, iframeOnScroll, iframeOnScrollCollection, key, msgDataKey, _i, _j, _len, _len1, _ref2, _ref3, _ref4;
      if (typeof console !== "undefined" && console !== null) {
        if (typeof console.log === "function") {
          console.log("Gravity: Destroying widget " + containerId);
        }
      }
      elem = document.getElementById(containerId);
      if (elem != null ? (_ref2 = elem.parentNode) != null ? _ref2.removeChild : void 0 : void 0) {
        msgDataKey = null;
        _ref3 = window.grvDestroyWidget.grvIframeCollections;
        for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
          iframeCollection = _ref3[_i];
          for (key in iframeCollection) {
            if (!__hasProp.call(iframeCollection, key)) continue;
            iframeAndContainer = iframeCollection[key];
            if (!(iframeAndContainer.filter('div')[0] === elem)) {
              continue;
            }
            msgDataKey = key;
            break;
          }
        }
        if (msgDataKey) {
          delete iframeCollection[msgDataKey];
          _ref4 = window.grvDestroyWidget.grvIframeOnScrollCollections;
          for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
            iframeOnScrollCollection = _ref4[_j];
            for (key in iframeOnScrollCollection) {
              if (!__hasProp.call(iframeOnScrollCollection, key)) continue;
              iframeOnScroll = iframeOnScrollCollection[key];
              if (!iframeOnScrollCollection[msgDataKey]) {
                continue;
              }
              delete iframeOnScrollCollection[msgDataKey];
              break;
            }
          }
          return elem.parentNode.removeChild(elem);
        }
      }
    };
  }
  if ((_ref2 = (_base = window.grvDestroyWidget).grvIframeCollections) == null) {
    _base.grvIframeCollections = [];
  }
  if ((_ref3 = (_base1 = window.grvDestroyWidget).grvIframeOnScrollCollections) == null) {
    _base1.grvIframeOnScrollCollections = [];
  }
  window.grvDestroyWidget.grvIframeCollections.push(msgDataToIframe);
  window.grvDestroyWidget.grvIframeOnScrollCollections.push(msgDataToIframeOnScroll);
  isEmptyObject = function(obj) {
    var k;
    for (k in obj) {
      return false;
    }
    return true;
  };
  lastHeight = null;
  receiveMessage = function(event) {
    var $iframe, cb, container, containerId, decimalPart, iframeAndContainer, iframeElem, iframeSrc, intPart, is_maybe_our_message, matches, messageDomainMatches, msg, msgData, msg_data, msg_placement, msg_siteguid, msg_userid, newHeight, unit, _base2, _i, _len, _ref4, _ref5, _ref6, _results;
    if (isEmptyObject(msgDataToIframe)) {
      if (window.removeEventListener) {
        window.removeEventListener('message', receiveMessage, false);
      } else if (window.detachEvent) {
        window.detachEvent('onmessage', receiveMessage);
      }
      return;
    }
    if (event.data && event.origin) {
      msg_data = typeof (_base2 = event.data).split === "function" ? _base2.split("|") : void 0;
      is_maybe_our_message = ((msg_data != null ? msg_data.length : void 0) || 0) >= 4;
      if (!is_maybe_our_message) {
        return;
      }
      msg_siteguid = msg_data[0], msg_placement = msg_data[1], msg_userid = msg_data[2], msg = msg_data[3];
      msgData = "" + msg_siteguid + "|" + msg_placement + "|" + msg_userid;
      iframeAndContainer = msgDataToIframe[msgData];
      iframeSrc = iframeAndContainer != null ? iframeAndContainer.find('[src]').attr('src') : void 0;
      messageDomainMatches = (iframeSrc != null ? iframeSrc.indexOf(event.origin) : void 0) === 0;
      if (messageDomainMatches) {
        $iframe = iframeAndContainer.filter('iframe');
        iframeElem = $iframe[0];
        if (!msgDataToIframeOnScroll[msgData]) {
          msgDataToIframeOnScroll[msgData] = function() {
            if (grvElemInView(iframeElem)) {
              $window.unbind('scroll', msgDataToIframeOnScroll[msgData]);
              return iframeElem.contentWindow.postMessage('widgetInView', '*');
            }
          };
        }
        if (msg === 'grv_show') {
          showWidget(iframeAndContainer.not('iframe'));
          iframeElem.contentWindow.postMessage('widgetShown', '*');
          $window.bind('scroll', msgDataToIframeOnScroll[msgData]);
          return msgDataToIframeOnScroll[msgData]();
        } else if (msg === 'showAttrib') {
          return window.grvShowAttributionModal($);
        } else if (((_ref4 = (matches = /^setHeight:(\d+)(\.\d+)?(px|%)?/.exec(msg))) != null ? _ref4[1] : void 0) != null) {
          intPart = matches[1];
          decimalPart = matches[2] || '';
          unit = matches[3] || 'px';
          newHeight = intPart + decimalPart + unit;
          if (newHeight !== lastHeight) {
            iframeAndContainer.height(newHeight);
            iframeElem.contentWindow.postMessage('heightUpdated', '*');
            if ($iframe.width() >= 2) {
              $iframe.css('opacity', 1);
              return msgDataToIframeOnScroll[msgData]();
            }
          }
        } else if (msg === 'grvWidgetError' && ((_ref5 = window.grvWidgetErrorCallbacks) != null ? _ref5.length : void 0)) {
          container = iframeAndContainer.not('iframe');
          containerId = container.attr('id');
          _ref6 = window.grvWidgetErrorCallbacks;
          _results = [];
          for (_i = 0, _len = _ref6.length; _i < _len; _i++) {
            cb = _ref6[_i];
            _results.push(cb(containerId));
          }
          return _results;
        }
      }
    }
  };
  inputSourceUrl = (_ref4 = window.gravityInsightsParams) != null ? (_ref5 = _ref4.sourceUrl) != null ? (_ref6 = _ref5.match(/^http.*/)) != null ? _ref6[0] : void 0 : void 0 : void 0;
  sourceUrl = inputSourceUrl || window.location.href;
  frameUrl = window.location.href;
  _fn = function(c) {
    var aolOmniPassThrough, aolOmniPassThroughJson, clickCaptureCallbacks, container, glid, htmlEncodedUrl, iframe, iframeAndContainer, is100PercentWidth, msgData, msgDelim, msgPrefix, msgPrefixLen, realContainerWidth, toJsonLite, url, wlClientTime, _ref7, _ref8, _ref9;
    aolOmniPassThroughJson = null;
    if ('0' === '1') {
      toJsonLite = function(obj) {
        var key, val;
        return '{' + ((function() {
          var _results;
          _results = [];
          for (key in obj) {
            if (!__hasProp.call(obj, key)) continue;
            val = obj[key];
            _results.push('"' + key.replace(/"/g, '\\"') + '":"' + val.toString().replace(/"/g, '\\"') + '"');
          }
          return _results;
        })()).join(',') + '}';
      };
      if (window.s_265) {
        aolOmniPassThrough = {};
        if (window.s_265.prop1 != null) {
          aolOmniPassThrough.prop1 = window.s_265.prop1;
        }
        if (window.s_265.prop2 != null) {
          aolOmniPassThrough.prop2 = window.s_265.prop2;
        }
        if (window.s_265.prop14 != null) {
          aolOmniPassThrough.prop14 = window.s_265.prop14;
        }
        if (window.s_265.prop10 != null) {
          aolOmniPassThrough.prop10 = window.s_265.prop10;
        }
        if (window.s_265.pageURL != null) {
          aolOmniPassThrough.pageURL = window.s_265.pageURL;
        }
        if (window.s_265.prop56 != null) {
          aolOmniPassThrough.prop56 = window.s_265.prop56;
        }
        if (window.s_265.channel != null) {
          aolOmniPassThrough.prop23 = window.s_265.channel;
        }
        if (window.s_265.eVar14 != null) {
          aolOmniPassThrough.eVar14 = window.s_265.eVar14;
        }
        glid = (_ref7 = window.s_265) != null ? typeof _ref7.c_r === "function" ? _ref7.c_r('UNAUTHID') : void 0 : void 0;
        if (glid != null) {
          aolOmniPassThrough.glid = glid;
        }
        aolOmniPassThroughJson = toJsonLite(aolOmniPassThrough);
      }
    }
    wlClientTime = '';
    clickCaptureCallbacks = ((_ref8 = window.grvArticleClickCaptureCbs) != null ? (_ref9 = _ref8[c.siteGuid || '']) != null ? _ref9[c.placement.toString() || ''] : void 0 : void 0) || [];
    url = ("" + c.url + "&sourceUrl=" + (encodeURIComponent(sourceUrl)) + "&frameUrl=" + (encodeURIComponent(frameUrl))) + ("&clientTime=" + (new Date().getTime()) + "&ci=" + (encodeURIComponent(c.id)) + "&") + $.param({
      'pageViewId[widgetLoaderWindowUrl]': window.grvPageViewId.widgetLoaderWindowUrl,
      'pageViewId[timeMillis]': window.grvPageViewId.timeMillis,
      'pageViewId[rand]': window.grvPageViewId.rand
    }) + (aolOmniPassThrough ? "&aopt=" + (encodeURIComponent(aolOmniPassThroughJson)) : '') + (wlClientTime ? "&wct=" + (encodeURIComponent(wlClientTime)) : '') + ((clickCaptureCallbacks != null ? clickCaptureCallbacks.length : void 0) && postMessageSupported ? '&cc' : '');
    htmlEncodedUrl = $('<p />').text(url).html();
    iframe = $("<iframe frameBorder='0' scrolling='no' src='" + htmlEncodedUrl + "' />").css('overflow', 'hidden');
    container = $("#" + c.id);
    iframeAndContainer = iframe.add(container);
    iframe.css({
      width: c.width,
      height: c.height
    });
    is100PercentWidth = /^100(\.0+)?%$/.test(c.width);
    if (is100PercentWidth && ((realContainerWidth = container.parent().width()) != null) && realContainerWidth > 1) {
      container.css('width', "" + realContainerWidth + "px").addClass('grvRestore100PercentWidth');
    } else {
      container.css('width', c.width);
    }
    container.css({
      height: c.height,
      overflow: 'hidden',
      position: 'absolute',
      top: '-10000px',
      left: '-10000px'
    });
    if (!postMessageSupported) {
      iframe.load(function() {
        return showWidget(container, iframe);
      });
    }
    iframe.appendTo(container);
    if (postMessageSupported) {
      msgData = "" + c.siteGuid + "|" + c.placement + "|" + c.userGuid;
      msgDataToIframe[msgData] = iframeAndContainer;
      if (clickCaptureCallbacks != null ? clickCaptureCallbacks.length : void 0) {
        msgPrefix = 'grvClk';
        msgPrefixLen = msgPrefix.length;
        msgDelim = '|';
        return bindEvent('message', function(e) {
          var cb, exposedArticle, msg, msgIsFromUs, origin, parts, _j, _len1, _results;
          msg = e != null ? e.data : void 0;
          origin = e != null ? e.origin : void 0;
          msgIsFromUs = origin && c.url.indexOf(origin) === 0;
          if (msgIsFromUs && msg.substr(0, msgPrefixLen) === msgPrefix) {
            parts = msg.substr(msgPrefixLen).split(msgDelim, 2);
            if (parts.length === 2) {
              exposedArticle = {
                title: parts[0],
                url: parts[1]
              };
              _results = [];
              for (_j = 0, _len1 = clickCaptureCallbacks.length; _j < _len1; _j++) {
                cb = clickCaptureCallbacks[_j];
                _results.push(cb(c.id, exposedArticle));
              }
              return _results;
            }
          }
        });
      }
    }
  };
  for (_i = 0, _len = containers.length; _i < _len; _i++) {
    c = containers[_i];
    _fn(c);
  }
  return bindEvent('message', receiveMessage);
};

/*
  @requires includeJs.coffee
*/


if (window.jQuery && !false) {
  window.$grv = jQuery;
  loadWidgets($grv);
} else {
  secure = document.location.protocol === 'https:';
  jqueryAssetUrl = secure ? 'https://s.api.grvcdn.com/personalization/grv-jquery-1.8.2.min.115d7718903b2f8f1196ec95c1c853c6.js' : 'http://i.api.grvcdn.com/personalization/grv-jquery-1.8.2.min.115d7718903b2f8f1196ec95c1c853c6.js';
  window.grvJqueryLoadedCallbacks = window.grvJqueryLoadedCallbacks || [];
  window.grvJqueryLoadedCallbacks.push(loadWidgets);
  window.GravityUtils.includeJs(jqueryAssetUrl);
}
})();