(function(){var config={"campaignId":"3486","aspectRatio":"16:9","videoPoster":"",'showWhen':"adReceived",'skipAdTimer':5,"waterfallID":"35","adTagURL":"","controls":true,"sound":"off","volume":50,"cap":false,"capType":"clicks","capLimit":0,"capTimeout":0,trackingPx:[],trackingFirstQuart:[],trackingMidpoint:[],trackingThirdQuart:[],trackingComplete:[],"assets":{"cssURL":"http://4cad707bbe7099c8f3c8-1d22a0d4135badeea192d868b304eb1e.r26.cf5.rackcdn.com/ad_units_shared_files/kikvid_interstitial/all.css","jwplayerURL":"http:\/\/4cad707bbe7099c8f3c8-1d22a0d4135badeea192d868b304eb1e.r26.cf5.rackcdn.com\/ad_units_shared_files\/kikvid_interstitial\/jwplayer.js","jwplayerKey":"","jwplayerVideoURL":"http:\/\/4cad707bbe7099c8f3c8-1d22a0d4135badeea192d868b304eb1e.r26.cf5.rackcdn.com\/ad_units_shared_files\/kikvid_interstitial\/jwplayer_1sec_video.mp4"}};var iframeBody='<div id="kv-ad-unit" class="kv-video kv-in-unit" style="position: absolute;top:0;bottom:0;left:0;right:0;margin:auto;min-width:240px;max-width:600px;height:0px;overflow:hidden">'+'<div id="ctrlBar" class="ctrl-bar" style="width:100%;margin:0 auto;">'+'<div>'+'<div style="float:left;"><span id="advertising_txt" style="display: none;">Advertisement</span><span>&nbsp;</span> <span id="remainingTime" style="display: none;"></span></div>'+'<button style="float:right;cursor:pointer;display:none" id="closeBtn"></button>'+'<div style="clear:both"></div>'+'</div>'+'</div>'+'<div id="playerBox" style="position:relative">'+'<div>'+'<div id="content_video"></div>'+'</div>'+'<div style="display:none">'+'<button id="soundBtn" class="sound-status-'+config.sound+'" style="float: left;display:none; bottom:20px"></button>'+'<button id="playBtn" style="display: none;"></button>'+'</div>'+'</div>'+'</div>';var in_iframe=window.top!==window.self,topDoc=window.top.document,playerWidth,playerHeight,anchor,kikIframe,kikIframeDoc;var isLoadedEventFiredOnce=false;var ipAddress='';function replaceMacros(str){if(str.length>0){str=str.replace(/\[CACHEBUSTER\]|\[timestamp\]/gi,new Date().getTime());str=str.replace(/\[RANDOM_NUMBER\]|\[RANDOMNUMBER\]/gi,Math.round(Math.random()*1000000));str=str.replace(/__random-number__/gi,Math.round(Math.random()*1000000));str=str.replace(/__player-width__|\[WIDTH\]/gi,Math.round(playerWidth));str=str.replace(/__player-height__|\[HEIGHT\]/gi,Math.round(playerHeight));str=str.replace(/__page-url__|\[PAGE_URL\]/gi,encodeURIComponent(window.top.location.href));str=str.replace(/\[DOMAIN\]/gi,encodeURIComponent(document.domain));str=str.replace(/__referrer__/gi,encodeURIComponent(topDoc.referrer));str=str.replace(/\[USERAGENT\]/gi,encodeURIComponent(navigator.userAgent));if(str.indexOf('[IOSVERSION]')>=0&&getIOSVersion()!==false)
str=str.replace(/\[IOSVERSION\]/gi,encodeURIComponent(getIOSVersion()));if(str.indexOf('[IPADDRESS]')>=0&&ipAddress!=='')
str=str.replace(/\[IPADDRESS\]/gi,encodeURIComponent(ipAddress));}
return str;}
function getIOSVersion(){return parseFloat((''+(/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent)||[0,''])[1]).replace('undefined','3_2').replace('_','.').replace('_',''))||false;}
function isIpAddressMacroInAdTags(adTags){for(var i=0;i<adTags.length;i++){if(adTags[i].indexOf('[IPADDRESS]')>=0)return true;}
return false;}
function getIPAddress(callback){kikIframe.contentWindow.clientInfoCallback=function(data){if(typeof data==='object'){ipAddress=data.ip;}
if(typeof callback==='function')callback();};loadScript(kikIframeDoc,'http://ads.zikvid.com/client_info.php?callback=clientInfoCallback');}
function reportPlayedAdTag(url){if(!(config.waterfallID>0)||config.campaignId==='preview')return;var timestamp=new Date().getTime();var query=['t='+'adtag','campaign_id='+encodeURIComponent(config.campaignId),'url='+encodeURIComponent('http://ads.zikvid.com'),'waterfall_id='+encodeURIComponent(config.waterfallID),'adtag='+encodeURIComponent(url),'rand='+encodeURIComponent(timestamp)];(new Image()).src='http://ads.zikvid.com/index.php?'+query.join('&');}
function hitTrackingPx(arr){for(var i=0;i<arr.length;i++){(new Image()).src=replaceMacros(arr[i]);}}
function hitKikvidPx(e){if(config.campaignId==='preview')return;if(e==='i'){hitTrackingPx(config.trackingPx);}
else if(e==='first_quart'){hitTrackingPx(config.trackingFirstQuart);}
else if(e==='mid_point'){hitTrackingPx(config.trackingMidpoint);}
else if(e==='third_quart'){hitTrackingPx(config.trackingThirdQuart);}
else if(e==='complete'){hitTrackingPx(config.trackingComplete);}
var timestamp=new Date().getTime();var cUrl='';if(typeof kikIframe!=='undefined')
cUrl=kikIframe.contentWindow.top.location.href;else
cUrl='http://ads.zikvid.com';var query=['t='+encodeURIComponent(e),'campaign_id='+encodeURIComponent(config.campaignId),'url='+encodeURIComponent(cUrl),'rand='+encodeURIComponent(timestamp)];(new Image()).src='http://ads.zikvid.com/index.php?'+query.join('&');}
function sendEvent(e){if(e==='LOADED'){hitKikvidPx('i');}
else if(e==='CLICK'){hitKikvidPx('c');}
else if(e==='STARTED'){hitKikvidPx('play');}
else if(e==='FIRST_QUARTILE'){hitKikvidPx('first_quart');}
else if(e==='MIDPOINT'){hitKikvidPx('mid_point');}
else if(e==='THIRD_QUARTILE'){hitKikvidPx('third_quart');}
else if(e==='COMPLETE'){hitKikvidPx('complete');}}
function getTimestamp(){return Math.round((new Date().getTime())/1000);}
var cap={isCountDone:false,keyPrefix:'kikvid_ads_'+config.campaignId+'_',getKey:function(key){return localStorage.getItem(cap.keyPrefix+key);},setKey:function(key,val){try{localStorage.setItem(cap.keyPrefix+key,val);}catch(e){}},delKey:function(key){localStorage.removeItem(cap.keyPrefix+key);},getUntil:function(){var val=cap.getKey('cap_until');return val===null?val:parseInt(val,10);},getCounter:function(){var val=cap.getKey('cap_counter');return val===null?0:parseInt(val,10);},isReached:function(){if(cap.getUntil()===null)return false;if(cap.getUntil()<getTimestamp()){cap.reset();return false;}
else
return true;},reset:function(){cap.delKey('cap_counter');cap.delKey('cap_until');},set:function(){cap.setKey('cap_until',getTimestamp()+config.capTimeout);},count:function(){if(cap.isCountDone)return;cap.isCountDone=true;cap.setKey('cap_counter',cap.getCounter()+1);if(cap.getCounter()>=config.capLimit){cap.set();}}};init=function(){hitKikvidPx('ad_call');var div=document.createElement("div");div.innerHTML="<!--[if lt IE 9]><i></i><![endif]-->";var isIeLessThan9=(div.getElementsByTagName("i").length==1);if(isIeLessThan9){console.log('Browser not supported.');return;}
if(config.cap&&cap.isReached()){console.log('Cap reached.');return;}
if(topDoc.documentElement.offsetWidth<970){console.log(topDoc.documentElement.offsetWidth);console.log('small screen');return;}
if(config.videoPoster!='')
startImageLoad(config.videoPoster);createIframe();placeIframe();kikIframeDoc=(kikIframe.contentDocument)?kikIframe.contentDocument:kikIframe.contentWindow.document;var adTagsReady=false;var iframeContentLoaded=false;var kikvidWaterfall;function determineAdTagsAndSetAd(){var adTags=config.waterfallID>0?kikvidWaterfall:[config.adTagURL];if(adTags.length===0){hideUnit();console.log('No adtags.');return;}
if(isIpAddressMacroInAdTags(adTags)){getIPAddress(function(){if(config.showWhen==='immediately'){setTimeout(function(){setAd(kikIframe.contentWindow,kikIframeDoc,adTags);},500)}
else{setAd(kikIframe.contentWindow,kikIframeDoc,adTags);}});}
else{if(config.showWhen==='immediately'){setTimeout(function(){setAd(kikIframe.contentWindow,kikIframeDoc,adTags);},500)}
else{setAd(kikIframe.contentWindow,kikIframeDoc,adTags);}}}
setIframeContent(function(){recalculateSizes();if(config.showWhen==='immediately')showUnit();if(adTagsReady)determineAdTagsAndSetAd();iframeContentLoaded=true;});recalculateSizes();if(typeof config.waterfallID!=='undefined'&&config.waterfallID>0){loadScript(kikIframeDoc,'http://4cad707bbe7099c8f3c8-1d22a0d4135badeea192d868b304eb1e.r26.cf5.rackcdn.com/waterfalls/'+config.waterfallID+'/waterfall.js?r='+new Date().getTime(),function(){kikvidWaterfall=kikIframe.contentWindow.kikvidWaterfall;if(typeof kikvidWaterfall!=='undefined'&&Array.isArray(kikvidWaterfall)){adTagsReady=true;if(iframeContentLoaded)determineAdTagsAndSetAd();}});}
else{adTagsReady=true;}};function startImageLoad(src){var image=new Image();image.src=src;}
function recalculateSizes(){var anchor=kikIframeDoc.getElementById('playerBox');var anchorWidth=anchor.clientWidth;var anchorHeight=anchor.clientHeight;playerWidth=anchorWidth;playerHeight=(anchorWidth/(config.aspectRatio=='16:9'?16/9:4/3));if(playerWidth<240){playerWidth=240;playerHeight=135;}
kikIframeDoc.getElementById('playerBox').style.height=playerHeight+'px';var ctrlBarHeight=kikIframeDoc.getElementById('ctrlBar').clientHeight;kikIframeDoc.getElementById('kv-ad-unit').style.height=(playerHeight+ctrlBarHeight)+'px';}
function createIframe(){kikIframe=topDoc.createElement('iframe');kikIframe.style.position='fixed';kikIframe.style.zIndex='99999';kikIframe.style.left='0';kikIframe.style.top='-10000px';kikIframe.style.width='100%';kikIframe.style.height='100%';kikIframe.style.background='rgba(0,0,0,0)';kikIframe.src='about:blank';kikIframe.name='kikvid brands ad';kikIframe.seamless='seamless';kikIframe.scrolling='no';kikIframe.marginwidth=0;kikIframe.marginheight=0;kikIframe.frameBorder=0;kikIframe.setAttribute('allowFullScreen','');};function placeIframe(){topDoc.body.appendChild(kikIframe);};setIframeContent=function(success){kikIframeDoc.open();kikIframeDoc.write("<!DOCTYPE html><html><head></head><body></body></html>");kikIframeDoc.close();kikIframeDoc.body.innerHTML=iframeBody;kikIframeDoc.getElementById('closeBtn').onclick=hideUnit;loadStyle(kikIframeDoc,config.assets.cssURL);var scriptsRemaing=1;function jsReady(){scriptsRemaing--;if(scriptsRemaing>0)return;success();}
loadScript(kikIframeDoc,config.assets.jwplayerURL,function(){kikIframe.contentWindow.jwplayer.key=config.assets.jwplayerKey;jsReady();})};loadStyle=function(doc,url){var cssLink=doc.createElement("link");cssLink.setAttribute('rel','stylesheet');cssLink.setAttribute('media','screen');cssLink.setAttribute('type','text/css');cssLink.setAttribute('href',url);doc.getElementsByTagName('head')[0].appendChild(cssLink);}
loadScript=function(doc,url,callback){var script=doc.createElement("script");script.type="text/javascript";script.async=true;if(script.readyState){script.onreadystatechange=function(){if(script.readyState==="loaded"||script.readyState==="complete"){script.onreadystatechange=null;if(callback)callback();}};}else{script.onload=function(){if(callback)callback();};}
script.src=url;doc.getElementsByTagName("head")[0].appendChild(script);};function showUnit(){kikIframe.style.background='rgba(0,0,0,0.8)';kikIframe.style.top='0';var div=kikIframeDoc.getElementById('kv-ad-unit');var heightToAnimate=div.style.height;div.style.height=0;setTimeout(function(){var transition='all 0.5s ease-out';div.style.webkitTransition=transition;div.style.mozTransition=transition;div.style.msTransition=transition;div.style.oTransition=transition;div.style.transition=transition;div.style.visibility="visible";div.style.height=heightToAnimate;},0);}
function hideUnit(){kikIframeDoc.getElementById('kv-ad-unit').style.height=0;kikIframe.parentNode.removeChild(kikIframe);}
function setAd(window,document,adTags){var firstQuartileSent=false;var midPointSent=false;var thirdQuartileSent=false;var isOnCompleteFired=false;var isFirstPlay=true;var isAdStarted=false;var isAdPausedByUser=false;var isAdCompleted=false;var isAdPlaying=false;var soundBtn=document.getElementById('soundBtn');soundBtn.addEventListener('click',function(){player.setMute();var isMuted=player.getMute();if(isMuted)
soundBtn.className='sound-status-off';else
soundBtn.className='sound-status-on';});var playBtn=document.getElementById('playBtn');playBtn.addEventListener('click',function(){player.play();isAdPlaying=true;});var adTagsOrig=adTags.concat();for(var i=0;i<adTags.length;i++){adTags[i]=replaceMacros(adTags[i]);}
var player=window.jwplayer("content_video").setup({image:config.videoPoster,file:config.assets.jwplayerVideoURL,cookies:false,controls:config.controls,advertising:{client:'vast',schedule:{adbreak1:{offset:'pre',tag:adTags}}},width:"100%",aspectratio:config.aspectRatio,primary:"flash",autostart:true});window.top.addEventListener('resize',function(){recalculateSizes();});player.on('adImpression',function(e){document.getElementById("advertising_txt").style.display="block";if(isFirstPlay){if(config.cap&&config.capType==='impressions'){cap.count();}
reportPlayedAdTag(adTagsOrig[adTags.indexOf(e.tag)]);soundBtn.style.display='block';if(config.showWhen==='adReceived')showUnit();isFirstPlay=false;}
sendEvent('LOADED');isAdStarted=false;player.setVolume(parseInt(config.volume,10));player.setMute(config.sound==='on'?false:true);});player.on('adPlay',function(e){setTimeout(function(){kikIframeDoc.getElementById('closeBtn').style.display='block';},config.skipAdTimer*1000);isAdPausedByUser=false;isAdPlaying=true;playBtn.style.display='none';if(isAdStarted)sendEvent('RESUMED');else{isAdStarted=true;sendEvent('STARTED');}});player.on('adPause',function(e){sendEvent('PAUSED');playBtn.style.display='block';});player.on('adClick',function(e){if(config.cap&&config.capType==='clicks'){cap.count();}
isAdPlaying=false;isAdPausedByUser=true;sendEvent('CLICK');});player.on('adComplete',function(e){sendEvent('COMPLETE');if(isOnCompleteFired){playBtn.style.display='none';}
isAdPlaying=false;hideUnit();});var adTagCounter=0;player.on('adError',function(e){adTagCounter++;if(config.cap&&config.capType==='impressions'){cap.count();}
isAdPlaying=false;if(adTagCounter===adTags.length){sendEvent('ERROR');player.remove();hideUnit();}});player.on('complete',function(e){playBtn.style.display='none';isOnCompleteFired=true;isAdCompleted=true;hideUnit();});player.on('adTime',function(e){var sec_num=Math.round(e.duration-e.position);var hours=Math.floor(sec_num / 3600);var minutes=Math.floor((sec_num-(hours*3600))/ 60);var seconds=sec_num-(hours*3600)-(minutes*60);if(hours<10){hours="0"+hours;}
if(minutes<10){minutes="0"+minutes;}
if(seconds<10){seconds="0"+seconds;}
var time=(hours==='00'?'':hours+':')+minutes+':'+seconds;document.getElementById('remainingTime').innerHTML='<span class="middot">&middot;</span> '+time;trackQuartiles(e);});function trackQuartiles(an){var remaining=Math.round(an.duration-an.position);var position=Math.round(an.position);var quartile=Math.round(an.duration/4);var first=quartile;var second=(quartile*2);var third=(quartile*3);if(position>=(first-1)&&firstQuartileSent===false){sendEvent("FIRST_QUARTILE");firstQuartileSent=true;}else if(position>=(second-1)&&midPointSent===false){sendEvent("MIDPOINT");midPointSent=true;}else if(position>=(third-1)&&thirdQuartileSent===false){sendEvent("THIRD_QUARTILE");thirdQuartileSent=true;}}}
init();})();