var TSvideos; TSvideosRun(); function TSvideosRun() { if (!_topshop.videos.ad || _topshop.videos.ad.length == 0) { setTimeout(TSvideosRun, 100); return; } TSvideos = new TSvideos(_topshop.videos.ad); if (_topshop != null && _topshop.videos != null) { if (_topshop.videos.inline_color != null) { TSvideos.w_style.color = _topshop.videos.inline_color; } if (_topshop.videos.inline_count_max != null) { TSvideos.params.inline_limit = _topshop.videos.inline_count_max; } if (_topshop.videos.is_use_marked != null) { TSvideos.params.use_marked = _topshop.videos.is_use_marked; } if (_topshop.videos.autostart_video != null) { TSvideos.params.autostart_video = _topshop.videos.autostart_video; } } TSvideos.run(); } function fClick() { if (TSvideos.show_id > -1) { TSvideos.hideBanner(TSvideos.show_id); } } function fHitArea() { fClick(); } function TSvideos(ads) { this.ads = ads; this.params = { 'use_marked' : false, 'inline_limit' : 5, 'info_url' : 'http://www.topshoptv.com.ua/', 'show_timeout' : 100, 'hide_timeout' : 700, 'autostart_video': true }; this.skip = { 'SCRIPT': 1,'NOSCRIPT': 1,'H1': 1,'H2': 1,'H3': 1,'H4': 1,'H5': 1,'H6': 1,'BIG': 1,'A': 1,'TH': 1,'FIELDSET': 1,'TEXTAREA': 1,'SELECT': 1,'LEGEND': 1,'ACRONYM': 1,'ADDRESS': 1,'LABEL': 1 } this.w_bounds = '(^|$|[^0-9a-zA-Zа-яА-Я_])'; this.w_style = { 'cursor' : 'pointer', 'color' : '#ff0000', 'textDecoration' : 'none', 'borderStyle' : 'solid', 'borderWidth' : '0 0 1px 0' }; this.inline_count = 0; this.showTimer = false; this.hideTime = false; this.show_id = -1; this.run = function() { var n = document.getElementsByTagName("body")[0]; this.prepareRegexp(); this.scanBlocks(n); this.setEvents(); } this.prepareRegexp = function() { var i, j; this.ads.sort(function(){return (Math.round(Math.random())-0.5);}); for (i = 0; i < this.ads.length; i++) { this.ads[i].words = this.ads[i].keyword.split(";"); this.ads[i].words.sort(function(){return (Math.round(Math.random())-0.5);}); this.ads[i].regexp = new Array(); this.ads[i].inlined = new Array(); this.ads[i].word = new Array(); for (j = 0; j < this.ads[i].words.length; j++) { this.ads[i].regexp[j] = new RegExp(this.w_bounds + '(' + this.ads[i].words[j] + ')' + this.w_bounds, 'ig'); this.ads[i].inlined[j] = false; } } } this.scanBlocks = function(n, b) { if (n.nodeType == 3) { if (this.params.use_marked && !b) { return; } if (n.data.replace(/\s+/g, "")) { this.scanWords(n); } } else { for (var i = n.firstChild; i != null; i = i.nextSibling) { if (this.inline_count >= this.params.inline_limit) { break; } if (this.skip[i.nodeName.toUpperCase()] == 1) { continue; } if (i.className) { if (i.className.indexOf("_noreachbanner_") != -1) { continue; } if (i.id && i.id.indexOf("y5_direct") != -1) { continue; } if (i.className.indexOf("_reachbanner_") != -1) { this.scanBlocks(i, true); continue; } } this.scanBlocks(i, b); } } } this.scanWords = function(n) { var i, j, r, nn; for (i = 0; i < this.ads.length; i++) { if (this.inline_count >= this.params.inline_limit) { break; } for (j = 0; j < this.ads[i].words.length; j++) { if (this.ads[i].inlined[j]) { continue; } r = this.ads[i].regexp[j].exec(n.data); if (r != null) { nn = this.inlineWord(n, i, j, r.index + r[1].length, r[2].length); if (nn) { n = nn; } if (this.inline_count >= this.params.inline_limit) { break; } } } } } this.inlineWord = function(n, i, j, b, l) { var pn = n.parentNode; if (pn) { var wn = this.makeWordHTML(i, j, n.data.substr(b, l)); var bn = b > 0 ? document.createTextNode(n.data.substr(0, b)) : document.createTextNode(""); var an = (b + l) < n.data.length ? document.createTextNode(n.data.substr(b + l, n.data.length - (b + l))) : document.createTextNode(""); pn.replaceChild(an, n); pn.insertBefore(wn, an); pn.insertBefore(bn, wn); this.ads[i].inlined[j] = true; this.inline_count++; return an; } return null; } this.makeWordHTML = function(i, j, w) { var n = document.createElement("A"); n.appendChild(document.createTextNode(w)); n.href = 'javascript://'; for (var p in this.w_style) { n.style[p] = this.w_style[p]; } this.ads[i].word[j] = n; return n; } this.makeBannerHTML = function(i) { var o, u, n; u = this.ads[i].flash_url + '?atype=2&clickTAG=' + escape(this.ads[i].click_url) + '&fileURL=' + escape(this.ads[i].video_url) + '&infoURL=' + escape(this.params.info_url); for (var k in this.ads[i].flash_vars) { u += "&"+k+"="+escape(this.ads[i].flash_vars[k]); } if (!this.params.autostart_video) { u += "&jsPause=PAUSE_ON"; } o = ''; o += ''; o += ''; o += ''; o += ''; o += ''; o += ''; o += ''; o += ''; n = document.createElement("DIV"); n.className = '_noreachbanner_'; n.innerHTML = o; n.style.display = 'none'; n.style.position = 'absolute'; n.style.zIndex = 99999; n.style.width = this.ads[i].width + 'px'; n.style.height = this.ads[i].height + 'px'; return n; } this.showBanner = function(i, j) { this.createBanner(i, j); var b = this.ads[i].banner; if (b == null) { return; } var w = this.getPageWidth(); var h = this.getPageHeight(); var sy = this.getScrollY(); var x = this.getPosX(this.ads[i].word[j]); var y = this.getPosY(this.ads[i].word[j]); var kw = this.ads[i].word[j].offsetWidth; var kh = this.ads[i].word[j].offsetHeight; var bx, by; var body = document.getElementsByTagName("body")[0]; if (x < (w / 2)) { bx = x; } else { bx = x - this.ads[i].width + 30; } if ((y - sy) < (h / 2)) { by = y + kh + 3; } else { by = y - this.ads[i].height - 3; } b.style.top = by + 'px'; b.style.left = bx + 'px'; b.style.display = 'block'; if (!this.ads[i].trace) { if (this.ads[i].trace_url) { this.cacheFile(this.ads[i].trace_url); } if (this.ads[i].trace_url2 && this.ads[i].trace_url2.length > 0) { this.cacheFile(this.ads[i].trace_url2); } this.ads[i].trace = true; } if (body) { body.appendChild(b); } TSvideos.show_id = i; TSvideos.showTimer = false; } this.hideBanner = function(i) { var n = this.ads[i].banner; if (n) { var body = document.getElementsByTagName("body")[0]; n.style.display = 'none'; if (body) { body.removeChild(n); } } TSvideos.show_id = -1; TSvideos.hideTimer = false; } this.createBanner = function(i, j) { if (this.ads[i].word[j]) { this.ads[i].banner = this.makeBannerHTML(i, j); this.ads[i].banner.onmouseover = new Function('TSvideos.eventBannerMouseOver('+i+','+j+')'); this.ads[i].banner.onmouseout = new Function('TSvideos.eventBannerMouseOut('+i+','+j+')'); } } this.setEvents = function() { var i, j; for (i = 0; i < this.ads.length; i++) { for (j = 0; j < this.ads[i].word.length; j++) { if (this.ads[i].word[j]) { this.ads[i].word[j].onmouseover = new Function('TSvideos.eventWordMouseOver('+i+','+j+')'); this.ads[i].word[j].onmouseout = new Function('TSvideos.eventWordMouseOut('+i+','+j+')'); } } } } this.eventWordMouseOver = function(i, j) { this.ads[i].word[j].style.borderWidth = '0 0 2px 0'; if (TSvideos.show_id > -1) { if (TSvideos.show_id == i) { if (TSvideos.hideTimer) { clearTimeout(TSvideos.hideTimer); TSvideos.hideTimer = false; } return; } else { TSvideos.hideBanner(TSvideos.show_id); } } TSvideos.showTimer = setTimeout('TSvideos.showBanner('+i+','+j+')', TSvideos.params.show_timeout); } this.eventWordMouseOut = function(i, j) { this.ads[i].word[j].style.borderWidth = this.w_style['borderWidth']; if (TSvideos.showTimer) { clearTimeout(TSvideos.showTimer); TSvideos.showTimer = false; } if (TSvideos.show_id > -1) { TSvideos.hideTimer = setTimeout('TSvideos.hideBanner('+i+')', TSvideos.params.hide_timeout); } } this.eventBannerMouseOver = function(i, j) { if (TSvideos.hideTimer) { clearTimeout(TSvideos.hideTimer); TSvideos.hideTimer = false; } } this.eventBannerMouseOut = function(i, j) { TSvideos.hideTimer = setTimeout('TSvideos.hideBanner('+i+')', TSvideos.params.hide_timeout); } this.cacheFile = function(u) { (new Image(10, 10)).src = u.replace("{rid}", Math.random()); } this.getPosX = function(o) { var x = 0; if (o.offsetParent) { while (o) { x += o.offsetLeft; o = o.offsetParent; } } else { if (o.x) { x = o.x; } } return x; } this.getPosY = function(o) { var y = 0; if (o.offsetParent) { while (o) { y += o.offsetTop; o = o.offsetParent; } } else { if (o.y) { y = o.y; } } return y; } this.getPageWidth = function() { var x = 0; if (typeof(window.innerWidth) == 'number') { x = window.innerWidth; } else if (document.documentElement && document.documentElement.clientWidth) { x = document.documentElement.clientWidth; } else if (document.body && document.body.clientWidth) { x = document.body.clientWidth; } return x; } this.getPageHeight = function() { var y; if (typeof(window.innerHeight) == 'number') { y = window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { y = document.documentElement.clientHeight; } else if (document.body.clientHeight) { y = document.body.clientHeight; } return y; } this.getScrollX = function() { var x = 0; if (typeof(window.pageXOffset) == 'number') { x = window.pageXOffset; } else if (document.body && document.body.scrollLeft) { x = document.body.scrollLeft; } else if (document.documentElement && document.documentElement.scrollLeft) { x = document.documentElement.scrollLeft; } return x; } this.getScrollY = function() { var y = 0; if (typeof(window.pageYOffset) == 'number') { y = window.pageYOffset; } else if (document.body && document.body.scrollTop) { y = document.body.scrollTop; } else if (document.documentElement && document.documentElement.scrollTop) { y = document.documentElement.scrollTop; } return y; } }