(function () {

var cdn = 'https://d2git0jmd3o4gs.cloudfront.net';
var htv = $('<iframe src="'+ cdn +'/api_cache/data/script/htv" width="224" height="283" style="margin-bottom:15px;"></iframe>');
var htv2 = $('<iframe src="'+ cdn +'/api_cache/data/script/htv2" width="224" height="283" style="margin-bottom:15px;"></iframe>');

var i;
  var fn = function() {
    console.log('call fn');
    if($('.sidebar').length > 0) {
      $('.sidebar').prepend(htv);
      clearInterval(i);
    }
  };
var j;
  var fn2 = function() {
    if($('.aside').length > 0) {
      $('.aside').prepend(htv2);
      clearInterval(j);
    }
  };

  if(document.location.pathname === '/cat' ) {
    console.log('we are in cat');
    i = setInterval(fn,200); j = setInterval(fn2,200);

  }

var displayVideo = false;
setInterval(function() {
  if(document.location.pathname !== '/cat' ) {
    displayVideo = true;
  } else if(displayVideo === true && document.location.pathname === '/cat' ) {
    displayVideo = false;  i = setInterval(fn,200); j = setInterval(fn2,200);
 }
}, 200);

$.get('/api/user/vuid', function(data) {
  if(data.vuid && ga) {
    ga('set', 'userId', data.vuid);
  }
});

})();

(function (window, document) {
  var loader = function () {
    var script = document.createElement("script"), tag = document.getElementsByTagName("script")[0];
    script.src = "/api/data/script/CookieConsent";
    tag.parentNode.insertBefore(script, tag);
  };
  window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
})(window, document);