var delayB4StartGame = 500;var showPlayButton = false; var _debug = true; var activeRotator = true; if(typeof(gameIsPortrait) == 'undefined') activeRotator = false; //var ga = function(){}; //MANAGER var adsManager; var adsLoader; var adsRequest; var adsRenderingSettings; var adDisplayContainer; var CDBetweenInterTimer; var currentAd; var isDisplayingAd = false; if(typeof(CDBetweenInter) == 'undefined') var CDBetweenInter = 120 * 1000; // s * 1000 var apply_CDBetweenInter_to_first_MR = true; var videoContent = document.getElementById('c2canvasdiv'); var reallyOnMobile = false; var onMobile = false; var pubIsLoaded = false; var actualTypeOfPub = ""; var adsObjectIsReady = false; // var nopreroll; // var nomidroll; if(typeof(getCookie) == 'undefined'){ var getCookie = function (cname, defaultVal) { defaultVal = defaultVal || ""; var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i jQuery(window).height()){ displayRotator('portrait'); return false; } if(!gameIsPortrait && jQuery(window).width() < jQuery(window).height()){ displayRotator('landscape'); return false; } return true; } function displayRotator(orientation){ var gameElement = document.getElementById("c2canvasdiv"); var rotatorElement = document.getElementById("rotator"); // if(gameElement.style.display != "block" || rotatorElement.style.display != "none" || (window["cr_getC2Runtime"]().isSuspended !== false && window["cr_getC2Runtime"]().pi !== false )) return false; if(gameElement.style.display != "block" || rotatorElement.style.display != "none") return false; if(typeof(cr_setSuspended) == "function") cr_setSuspended(true); gameElement.style.display = "none"; rotatorElement.innerHTML = ""; rotatorElement.innerHTML = ''; rotatorElement.style.display = "block"; rotatorElement.style.backgroundColor = "black"; rotatorElement.style.width = "100%"; rotatorElement.style.height = "100%"; window.centerRotatorTimer = setInterval(function(){ centerRotator(); }, 100); return true; } function centerRotator(){ var rotatorElement = document.getElementById("rotator"); rotatorElement.style.paddingLeft = jQuery(window).width() / 2 - jQuery("#rotatorLogo").width() / 2 +"px"; rotatorElement.style.paddingTop = jQuery(window).height() / 2 - jQuery("#rotatorLogo").height() / 2 +"px"; rotatorElement.style.paddingBottom = jQuery(window).height() / 2 - jQuery("#rotatorLogo").height() / 2 +"px"; } function hideRotator(){ var gameElement = document.getElementById("c2canvasdiv"); var rotatorElement = document.getElementById("rotator"); if(rotatorElement.style.display != "block") return false; rotatorElement.innerHTML = ""; rotatorElement.style.display = "none"; gameElement.style.display = "block"; // if(window["cr_getC2Runtime"]().isSuspended === true) if(typeof(cr_setSuspended) == "function") cr_setSuspended(false); if(typeof(cr_setSuspended) == "function") cr_setSuspended(false); clearInterval(window.centerRotatorTimer); return true; } //ROTATOR END function launchGame(){ if(typeof(fireEvent) != 'undefined') fireEvent('onGameStart'); if(!canFireAnInter && apply_CDBetweenInter_to_first_MR) CDBetweenInterTimer = setTimeout(function(){ canFireAnInter = true; }, CDBetweenInter); jQuery(window).resize(function() { if(typeof(cr_sizeCanvas) == "function") cr_sizeCanvas(jQuery(window).width(), jQuery(window).height()); if(checkOrientation()) hideRotator(); }); // Create new runtime using the c2canvas cr_createRuntime('c2canvas'); setTimeout(function(){ checkOrientation(); }, 500); // Pause and resume on page becoming visible/invisible function onVisibilityChanged() { if (document.hidden || document.mozHidden || document.webkitHidden || document.msHidden){ if(typeof(cr_setSuspended) == "function") cr_setSuspended(true); }else{ if(typeof(cr_setSuspended) == "function") cr_setSuspended(false); } }; document.body.style.backgroundColor="black"; document.addEventListener('visibilitychange', onVisibilityChanged, false); document.addEventListener('mozvisibilitychange', onVisibilityChanged, false); document.addEventListener('webkitvisibilitychange', onVisibilityChanged, false); document.addEventListener('msvisibilitychange', onVisibilityChanged, false); } function send(sUrl,type) { var scriptLoad = document.createElement("script"); if(type = "file"){ scriptLoad.src = sUrl; }else if(type="js"){ scriptLoad.innerHTML = sUrl; } scriptLoad.type = "text/javascript"; document.body.appendChild(scriptLoad); document.body.removeChild(scriptLoad); } //_____________________________________________________________________________________ var eventOnClick = setTimeout(function(){ document.getElementById("buttonPlay").onclick = clickOnButonAds; document.getElementById("buttonPlay").addEventListener("touchstart", clickOnButonAds, false); },100); hideAll(); if(typeof(nopreroll) != "undefined"){ clearTimeout(eventOnClick); showGame("no ad"); }else{ if (navigator.userAgent.match(/(mobile|android|iphone|ipad|blackberry|symbian|symbianos|symbos|netfront|model-orange|javaplatform|iemobile|windows phone|samsung|htc|opera mobile|opera mobi|opera mini|presto|huawei|blazer|bolt|doris|fennec|gobrowser|iris|maemo browser|mib|cldc|minimo|semc-browser|skyfire|teashark|teleca|uzard|uzardweb|meego|nokia|bb10|playbook)/gi)) { onMobile = true; reallyOnMobile = true; document.getElementById("buttonPlayContainer").style.display = "block"; if(showPlayButton === false){ //THIS 2 FOLLOWING LINES UNACTIVE PLAY BUTTON clearTimeout(eventOnClick); clickOnButonAds(); } } else { clearTimeout(eventOnClick); clickOnButonAds(); } } var iOSVersion = parseFloat( ('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1]) .replace('undefined', '3_2').replace('_', '.').replace('_', '') ) || false; //__________________________________________________________________________________________________ var canTouchForPub = false; function touchStart(){ if(navigator.userAgent.match(/iemobile/i)) { return; } if(canTouchForPub){ if(_debug) console.log(";..."); requestAds(true); canTouchForPub = false; } } addEventListener("touchstart", touchStart, false) function launchAd(){ if(_debug) console.log("launching ad"); document.getElementById("c2canvasdiv").style.display = "block"; document.getElementById("mainContainer").style.display = "block"; hideGameForAd(); if(typeof(cr_setSuspended) == "function") cr_setSuspended(true); setTimeout(function(){requestAds(true);},100); } /* function loadGame(){ if(_debug) console.log("LoadGame"); for (var i = 0; i < tabScriptToLoad.length; i++) { $.getScript(tabScriptToLoad[i]); } window.timerC2MA = setInterval(function(){ if(typeof(window.cr_createRuntime) != "undefined" && typeof(jQuery) != "undefined" ){ //FORCE PLATFORM TAG window.XMLHttpRequest.prototype.trueOpen = window.XMLHttpRequest.prototype.open; window.XMLHttpRequest.prototype.open = function() { if(this.responseURL.indexOf('_GCODE') != -1){ this.responseURL = this.responseURL.replace('_GCODE', '_PZOOL'); } this.trueOpen.apply(this, arguments); }; clearInterval(window.timerC2MA); if(_debug) console.log('launch'); launchGame(); } },100); } */ function loadGame(){ if(_debug) console.log("LoadGame"); for (var i = 0; i < tabScriptToLoad.length; i++) { $.getScript(tabScriptToLoad[i]); } window.timerC2MA = setInterval(function(){ if(typeof(window.cr_createRuntime) != "undefined" && typeof(jQuery) != "undefined" ){ clearInterval(window.timerC2MA); if(_debug) console.log('launch'); launchGame(); } },100); } function onAdsManagerLoaded(adsManagerLoadedEvent) { var events = [ {"name":google.ima.AdEvent.Type.LOADED,"callback":onAdEvent}, {"name":google.ima.AdEvent.Type.STARTED,"callback":onAdEvent}, {"name":google.ima.AdEvent.Type.COMPLETE,"callback":onAdEvent}, {"name":google.ima.AdEvent.Type.USER_CLOSE,"callback":onAdEvent}, {"name":google.ima.AdEvent.Type.CLICK,"callback":onAdEvent}, {"name":google.ima.AdEvent.Type.ALL_ADS_COMPLETED,"callback":onAdEvent}, {"name":google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,"callback":onContentResumeRequested}, {"name":google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,"callback":onContentPauseRequested}, {"name":google.ima.AdEvent.Type.AD_ERROR,"callback":onAdError} ]; adsManager = adsManagerLoadedEvent.getAdsManager(videoContent,adsRenderingSettings); for (var index in events) { adsManager.addEventListener( events[index].name, events[index].callback ); } try { adsManager.init(getSizeWindow().x, getSizeWindow().y, google.ima.ViewMode.FULLSCREEN); adsManager.start(); $( window ).resize(function(){ if(!isDisplayingAd || typeof(adsManager) == 'undefined') return; if(typeof(adsManager.resize) != 'function') return; if(typeof(currentAd) == 'undefined') return; if(typeof(currentAd.naturalHeight) == 'undefined' || typeof(currentAd.naturalWidth) == 'undefined' || typeof(currentAd.contentType) == 'undefined') return; if(currentAd.contentType.indexOf("video") == -1){ if($(window).width() < currentAd.naturalWidth + 40){ return; } if($(window).height() < currentAd.naturalHeight + 75){ return; } } adsManager.resize(getSizeWindow().x, getSizeWindow().y, google.ima.ViewMode.FULLSCREEN); }); } catch (adError) { onAdError(); } } function back2Game(){ if(_debug) console.log("back2Game"); if(typeof(cr_setSuspended) == "function") cr_setSuspended(false); if(typeof(setAutoShareEnabled) != 'undefined') setAutoShareEnabled(true); document.getElementById("c2canvasdiv").style.display = "block"; document.getElementById("mainContainer").style.display = "none"; if(typeof(cr_sizeCanvas) == "function") cr_sizeCanvas(jQuery(window).width(), jQuery(window).height()); setTimeout(function(){$(window).scrollTop(0);},200); destroyObjectAds(); checkOrientation(); clearInterval(Ad_timerTimer); } function goToAd(){ hideGameForAd(); if(typeof(cr_setSuspended) == "function") cr_setSuspended(true); } function onAdError(adErrorEvent){ if(_debug){console.log("onAdError",adErrorEvent.getError());} if(typeof(fireEvent) != 'undefined'){ fireEvent(actualTypeOfPub+'_error')}; if(typeof(fireEvent) != 'undefined'){ fireEvent(actualTypeOfPub+'_end')}; isDisplayingAd = false; if(actualTypeOfPub == "preroll"){ TOB4Launch = setTimeout(function(){showGame("error");},delayB4StartGame); } else if(actualTypeOfPub == "midroll"){ back2Game(); } } var currTime,Ad_timerTimer; function startTimerForIMG(){ currTime = 16; Ad_timerTimer = setInterval( function() { currTime-=1; document.getElementById('Ad_timer').innerHTML = currTime; if(currTime < 0){ clearInterval(Ad_timerTimer); if(typeof(fireEvent) != 'undefined') fireEvent('preroll_timerEnd'); if(typeof(fireEvent) != 'undefined') fireEvent('preroll_end'); if(actualTypeOfPub == "midroll"){ back2Game(); }else if(actualTypeOfPub == "preroll"){ TOB4Launch = setTimeout(function(){showGame("close");},delayB4StartGame); } } }, 1000 ); } //___________________________Delay ads_______________________________________________ function launchPubInter(){ // if(!canFireAnInter) return; if(navigator.userAgent.match(/iemobile/i)) { return; } document.getElementById("c2canvasdiv").style.display = "block"; document.getElementById("mainContainer").style.display = "block"; hideGameForAd(); if(typeof(cr_setSuspended) == "function") cr_setSuspended(true); //Launch the pub if(adsLoader != "undefined"){ adsLoader.requestAds(adsRequest); canFireAnInter = false; CDBetweenInterTimer = setTimeout(function(){ canFireAnInter = true; }, CDBetweenInter); }else{ back2Game(); } } /* * c2LayoutChange(state,name,force) : called on construct when layout change * * string state : "in" when enter on the layout, "out" when left the layout * string name : name of the layout * bool forcePub : [default = 1] 1 = pub ; 0= noPub */ function c2LayoutChange(state,name,force){ if(typeof(showInterDFP) == "undefined") window.showInterDFP = true; if(typeof(c2LayoutChangeStack) != "undefined"){ for(var i=0; i