function SC_Interstitial() { if (SC_Interstitial.singleton == null) { SC_Interstitial.singleton = new SC_InterstitialClass(); } return SC_Interstitial.singleton; } function SC_InterstitialClass() { this.debugLayer = document.getElementById('SC_DEBUGLAYER'); this.browser = 'UNKNOWN'; this.IEVersion = -1; this.version = 0.0; this.opacity = 0.8; this.mediaPlayerClassId = '6BF52A52-394A-11D3-B153-00C04F79FAA6'; this.flashClassId = 'D27CDB6E-AE6D-11CF-96B8-444553540000'; this.cdnBase = 'http://cdn.smartclip.net/interstitial/'; this.miniPlayerUrl = this.cdnBase + 'interstitial.swf?' + Math.random() * 100000000; this.backgroundColor = '000000'; this.audioVolume = 100; this.videoAdUrl = null; this.videoAdXML = null; this.layer = null; this.layerframe = null; this.playerLayer = null; this.adisavailable = false; this.player = null; this.adWidth = 640; this.adHeight = 360; this.zIndex = 10000; this.flashHiding = true; this.polite = true; this.offSetLeft = 0; this.onStartCallback = null; this.onEndCallback = null; this.headerText = 'Weiter geht es nach einem kurzen Werbespot'; this.headerTextColor = 'FFFFFF'; this.closeText = 'Schliessen'; this.closeDelay = 0; this.borderWidth = 12; this.controlHeight = 30; this.colorSet = 0; this.timeText = 'Sekunden'; this.setDimension = function (_width, _height) { this.debug('- setDimension(' + _width + ', ' + _height + ')'); this.adWidth = _width; this.adHeight = _height; return this; } this.setColorSet = function (_colorSet) { this.debug('- setColorSet(' + _colorSet + ')'); this.colorSet = _colorSet; return this; } this.setPosLeft = function (_offSetLeft) { this.debug("- setPosLeft(" + _offSetLeft + ")"); this.offSetLeft = _offSetLeft; return this; }; this.setBorderWidth = function (_width) { this.debug('- setBorderWidth(' + _width + ')'); this.borderWidth = _width; return this; } this.setTimeText = function (_text) { this.debug('- setTimeText(' + _text + ')'); this.timeText = _text; return this; } this.setHeaderText = function (_text) { this.debug('- setHeaderText(' + _text + ')'); this.headerText = _text; return this; } this.setHeaderTextColor = function (_color) { this.debug('- setHeaderTextColor(' + _color + ')'); this.headerTextColor = _color; return this; } this.setCloseText = function (_text) { this.debug('- setCloseText(' + _text + ')'); this.closeText = _text; return this; } this.setCloseDelay = function (_delay) { this.debug('- setCloseDelay(' + _delay + ')'); this.closeDelay = _delay; return this; } this.setOnStartCallback = function (_onStartCallback) { this.debug('- setOnStartCallback(' + typeof (_onStartCallback) + ')'); this.onStartCallback = _onStartCallback; return this; } this.setOnEndCallback = function (_onEndCallback) { this.debug('- setOnEndCallback(' + typeof (_onEndCallback) + ')'); this.onEndCallback = _onEndCallback; return this; } this.setPolite = function (_polite) { this.debug('- setPolite(' + _polite + ')'); this.polite = _polite; return this; } this.setZIndex = function (_zIndex) { this.debug('- setZIndex(' + _zIndex + ')'); this.zIndex = new String(_zIndex); if (this.zIndex == null || !this.zIndex.match(/^[1-9][0-9]*$/)) { this.zIndex = 10000; this.debug('- Redefining z-index ' + _zIndex + ' with ' + this.zIndex + '.'); } return this; } this.setBackgroundColor = function (_color) { this.debug('- setBackgroundColor(' + _color + ')'); this.backgroundColor = _color; if (this.backgroundColor == null || typeof (this.backgroundColor.match) == 'undefined' || !this.backgroundColor.match(/^[A-Fa-f0-9]{6}$/)) { this.backgroundColor = '000000'; this.debug('- Redefining invalid color ' + _color + ' with ' + this.backgroundColor + '.'); } return this; } this.setAudioVolume = function (_volume) { this.debug('- setAudioVolume(' + _volume + ')'); this.audioVolume = _volume; if (isNaN(this.audioVolume)) { this.audioVolume = 100; this.debug('- redefining invalid volume ' + _volume + ' with ' + this.audioVolume); } return this; } this.setOpacity = function (_opacity) { this.debug('- setOpacity(' + _opacity + ')'); this.opacity = _opacity; if (isNaN(this.opacity) || this.opacity < 0.0 || this.opacity > 1.0) { this.opacity = 0.8; this.debug('- Redefining invalid opacity ' + _opacity + ' with ' + this.opacity); } return this; } this.setVideoAdUrl = function (_url) { this.debug('- setVideoAdUrl(' + _url + ')'); this.videoAdUrl = _url; return this; } this.setVideoAdXML = function (_xml) { this.debug('- setVideoAdXML(' + _xml + ')'); this.videoAdXML = _xml; return this; } this.disableFlashHiding = function () { this.flashHiding = false; return this; } this.init = function () { this.debug('- init(polite = ' + this.polite + ')'); var onLoad = false; var onResize = this.addEvent(window, "resize", SC_onResize); var onScroll = this.addEvent(window, "scroll", SC_onResize); var flashVer = this.getFlashVersion(); if (!onResize || !onScroll || flashVer < 9 || !this.detectBrowser()) { this.removeEvent(window, "resize", SC_onResize); this.removeEvent(window, "scroll", SC_onResize); this.endAd(); } else if (this.polite) { onLoad = this.addEvent(window, "load", SC_onLoad); if (!onLoad) { this.removeEvent(window, "load", SC_onLoad); this.removeEvent(window, "resize", SC_onResize); this.removeEvent(window, "scroll", SC_onResize); this.endAd(); } } else { this.initLayers(); } } this.loadAd = function () { this.debug('- loadAd(' + this.videoAdUrl + ', ' + this.adWidth + ', ' + this.adHeight + ')'); if (this.videoAdUrl != null) { this.player.loadVideoAdFromUrl(this.videoAdUrl, this.audioVolume); } else { this.player.loadVideoAdFromXML(this.videoAdXML, this.audioVolume); } } this.startingAd = function (_width, _height) { this.debug('- startingAd(P[' + this.adWidth + ',' + this.adHeight + '], V[' + _width + ',' + _height + '])'); this.adisavailable = true; this.onResize(); if (this.flashHiding) { this.hideObjectsAndEmbeds(); } this.layer.style.visibility = 'visible'; this.makeTransparent(this.playerLayer, 1.0); if (this.onStartCallback != null) { try { this.onStartCallback(); } catch (e) { this.debug('Couldnt call on start callback function - ' + e); } } } this.hideObjectsAndEmbeds = function () { if (typeof (document.getElementsByTagName) != 'undefined' && document.getElementsByTagName != null) { var tags = ['object', 'embed']; for (var j = 0; j < tags.length; j++) { var objects = document.getElementsByTagName(tags[j]); for (var i = 0; i < objects.length; i++) { if (objects[i].getAttribute('id') != 'SC_InterstitialPlayer') { objects[i].setAttribute('sc_ov', objects[i].style.visibility == null ? 'visible' : objects[i].style.visibility); objects[i].style.visibility = 'hidden'; } } } } } this.endAd = function () { this.debug('- endAd()'); if (this.layer != null) { this.layer.style.visibility = 'hidden'; } if (this.playerLayer != null) { this.playerLayer.style.visibility = 'hidden'; } if (this.flashHiding) { this.showObjectsAndEmbeds(); } if (this.onEndCallback != null) { try { this.onEndCallback(); } catch (e) { this.debug('Couldn\'t call on end callback function'); } } } this.showObjectsAndEmbeds = function () { if (typeof (document.getElementsByTagName) != 'undefined' && document.getElementsByTagName != null) { var tags = ['object', 'embed']; for (var j = 0; j < tags.length; j++) { var objects = document.getElementsByTagName(tags[j]); for (var i = 0; i < objects.length; i++) { var ov = objects[i].getAttribute('sc_ov'); if (ov != null) { objects[i].style.visibility = ov; } } } } } this.stopAd = function () { this.debug('- stopAd()'); this.player.stopVideoAd(); } this.onResize = function () { this.debug('- onResize()'); if ((this.layer != null && this.playerLayer != null) && this.adisavailable == true) { var scroll = this.getScrolling(); var viewport = this.getViewport(); var popWidth = viewport[0]; if (popWidth < scroll[2]) { popWidth = scroll[2]; } var popHeight = viewport[1]; if (popHeight < scroll[3]) { popHeight = scroll[3]; } this.layer.style.height = popHeight + "px"; this.layer.style.width = popWidth + "px"; this.playerLayer.style.width = this.adWidth + 2 * this.borderWidth + "px"; this.playerLayer.style.height = this.adHeight + 2 * this.borderWidth + this.controlHeight + "px"; if (this.offSetLeft != 0) { this.playerLayer.style.left = this.offSetLeft + "px"; } else { this.playerLayer.style.left = Math.round(scroll[0] + (viewport[0] - this.adWidth - 2 * this.borderWidth) / 2) + "px"; } this.playerLayer.style.top = Math.round(scroll[1] + (viewport[1] - this.adHeight - 2 * this.borderWidth - this.controlHeight) / 2) + "px"; } } this.addEvent = function (_obj, _event, _func) { if (_obj.addEventListener) { _obj.addEventListener(_event, _func, false); return true; } else if (_obj.attachEvent) { return _obj.attachEvent("on" + _event, _func); } return false; } this.removeEvent = function (_obj, _event, _func) { if (typeof (_obj.removeEventListener) != 'undefined') { _obj.removeEventListener(_event, _func, false); return true; } else if (typeof (_obj.detachEvent) != 'undefined') { return _obj.detachEvent("on" + _event, _func); } return false; } this.getViewport = function () { if (window.innerHeight != window.undefined) { return [window.innerWidth - 15, window.innerHeight - 15]; } else if (document.compatMode == 'CSS1Compat') { return [document.documentElement.clientWidth - 15, document.documentElement.clientHeight - 15]; } else if (document.body) { return [document.body.clientWidth - 15, document.body.clientHeight - 15]; } return false; } this.makeTransparent = function (_obj, _value) { if (this.browser == 'IE') { _obj.style.filter = 'alpha(opacity=' + (_value * 100) + ')'; } else { _obj.style.opacity = _value; } } this.getScrolling = function () { if (document.compatMode == 'CSS1Compat') { return [document.documentElement.scrollLeft, document.documentElement.scrollTop, document.documentElement.scrollWidth, document.documentElement.scrollHeight]; } else { return [document.body.scrollLeft, document.body.scrollTop, document.body.scrollWidth, document.body.scrollHeight]; } } this.initLayers = function () { this.debug('- initLayers()'); if (this.browser == 'IE') { if (this.IEVersion == 9) { var playerElement = document.createElement('div'); playerElement.innerHTML = ' '; this.player = playerElement.firstChild; } else { this.player = document.createElement(''); this.player.appendChild(this.createParam('movie', this.miniPlayerUrl)); } } else { this.player = document.createElement('object'); this.player.setAttribute('id', 'SC_InterstitialPlayer'); this.player.setAttribute('width', '100%'); this.player.setAttribute('height', this.adHeight + this.borderWidth + this.controlHeight); this.player.setAttribute('type', 'application/x-shockwave-flash'); this.player.setAttribute('data', this.miniPlayerUrl); } this.player.appendChild(this.createParam('menu', 'false')); this.player.appendChild(this.createParam('scale', 'noscale')); this.player.appendChild(this.createParam('wmode', 'window')); this.player.appendChild(this.createParam('bgcolor', '#' + this.backgroundColor)); this.player.appendChild(this.createParam('allowScriptAccess', 'always')); this.player.appendChild(this.createParam('FlashVars', 'adWidth=' + this.adWidth + '&adHeight=' + this.adHeight + '&format=' + 'interstitial' + '&audioVolume=' + this.audioVolume + '&frameThickness=' + this.borderWidth + '&closeText=' + this.closeText + '&closeButtonDelay=' + this.closeDelay + '&frameTextColor=' + this.headerTextColor + '&frameText=' + this.headerText + '&colorSet=' + this.colorSet + '&timeText=' + this.timeText)); if (this.browser == 'IE') { if (this.IEVersion == 8) { this.layer = document.createElement('