/**
 * site.lib.js
 */

if (Object.isUndefined(Cosmetics)) { var Cosmetics = {} }
Cosmetics.adjustStillingsTicker = function(options) {
  /**
   * Function to adjust the stillingsticker.
   * Call once the stillingsTicker markup is written.
   */
  options = $H({
    popupOffset: [-10, -10],
    maxImageHeight: 50
  }).update(options).toObject();

  /* Adjust pop-up ticker-ad popup element-container */
  var offset = $('rubrikk_stilling_holder').positionedOffset();
  $('adPopupBoxMain').setStyle({
    left: (offset[0] + options.popupOffset[0] - $('adPopupBoxMain').getWidth())+'px',
    top: offset[1] + options.popupOffset[1] + 'px'
  });


  /* Adjust width of ticker-ads within iframe */
  (function() {
    if (!$('rubrik_stilling_iframe').contentWindow.tickerAdjustments) {
      // Try this anonymous function again soon
      setTimeout(arguments.callee, 200);
    } else {
      try {
        var width = $('rubrik_stilling_iframe').getWidth();
        $('rubrik_stilling_iframe').contentWindow.tickerAdjustments({
          adWidth: width,
          maxImageHeight: options.maxImageHeight
        });
      } catch(e) {
        console.error(e);
      }
    }
  })();
}
