var console = window.console || { log: function() {}, error: function() {}, warn: function() {} };
/* pouze pokud je jQuery */
function mixer() {
/* zamicha reklamni zony s class="mixer" a podle mixgroup="name" */
var groupname = 'mixgroup'
var groupname2 = 'ts:mixgroup'
var groupname3 = 'data-mixgroup'
var elems = []
$(".mixer").each( function(index) {
$(this).attr(groupname, $(this).attr(groupname) || $(this).attr(groupname2) || $(this).attr(groupname3) ) // sjednotim
if ( $(this).attr(groupname) ) {
$(this).attr('mix-index',index)
elems.push( $(this) );
$(this).after('')
}
} )
elems.sort(function(a,b) {
if (a.attr(groupname) == b.attr(groupname)) {
return (Math.round(Math.random())-0.5);
}
else {
return Number(a.attr(groupname) > b.attr(groupname) )-0.5; // vraci 0.5 nebo -0.5
}
})
for (i=0;i0)
return;
var initTop = elem.offset().top-STICKY_TOP;
var stop = 0;
var attrStop = elem.attr('stickystop');
var id = elem.attr('id');
if (attrStop && $("#sticky-stop-" + attrStop)) {
stop = $("#sticky-stop-" + attrStop).offset().top; //-30
} else if (id && $("#sticky-stop-"+ id.replace(/\./g,'-')).length) {
stop = $("#sticky-stop-" + id.replace(/\./g,'-')).offset().top; //-30
} else if ($("#sticky-stop").length) {
stop = $("#sticky-stop").offset().top; //-30
} else {
stop = $(document).height();
}
var maxOffset = stop - initTop - elem.outerHeight(true) - STICKY_TOP;
if (maxOffset < 0) maxOffset = 0;
elem.attr({
'initTop': initTop,
'maxOffset': maxOffset
});
}
stickyHandler = function() {
/* init */
var windowTop = $(window).scrollTop();
$(".sticky").each( function(index) {
initSticky($(this));
if ($(this).attr('initTop')==undefined)
return;
var offset = windowTop-$(this).attr('initTop')
var maxOffset = $(this).attr('maxOffset');
if (offset > maxOffset) offset = maxOffset;
if (offset < 0) offset = 0;
var cTime = new Date().getTime();
var initTime = $(this).attr('initTime')||0;
var initCnt = $(this).attr('initCnt')||0;
if (offset==0 && (cTime-initTime)>1000 && initCnt<10) {
$(this).attr({
'initTop': 0,
'initTime': cTime,
'initCnt': initCnt+1
});
}
if (offset==0 || offset == maxOffset) {
$(this).css({
marginTop: offset + 'px',
'position':'static',
'top':0
});
return;
}
$(this).css({
marginTop: '0px',
'position':'fixed',
'top':STICKY_TOP
});
});
var scrollLeft = $(window).scrollLeft();
if (scrollLeft != hScroll) {
hScroll = scrollLeft;
stickyWinResize();
}
}
function stickyWinResize() {
$(".sticky").each(function(){
var position=$(this).css('position');
$(this).css({'position':'static'});
$(this).css({
'left': $(this).offset().left-$(window).scrollLeft(),
'position': position
});
})
}
function sticky() {
//if (STICKY_ACTIVE) { return }
//STICKY_ACTIVE=1
stickyHandler();
$(window).unbind('scroll', stickyHandler);
$(window).bind('scroll', stickyHandler);
/* pouze pro safari a ipad iphone */
//if (/(iPhone|iPad|iPod|safari|mac os|Macintosh)/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent)) {
$(window).unbind('resize', stickyWinResize)
$(window).bind('resize', stickyWinResize)
stickyWinResize()
//}
}
function hideEmpty() {
$(".bbtitle").each(function() {
if ($(this).height()<15) {
$(this).hide()
}
})
}
// puvodni funkce - nahrazena isiPad promennou kvuli skyscraperu
function isTouchDevice() {
return !!('ontouchstart' in window) // works on most browsers
|| !!('onmsgesturechange' in window); // works on ie10
};
var isiPad = navigator.userAgent.match(/iPad/i) != null;
if (typeof(jQuery) != 'undefined' && typeof(bbFixExist)=='undefined') {
mixer()
$(function() {
if (isiPad) {
$(".hide-touch").remove() // schovat na dotykacich oznacene divy
}
if (/(Google Web Preview|screenshot-generator)/i.test(navigator.userAgent)) {
$(".hide-screenbot").remove()
}
$("a[rel~='external']").attr("target","_blank")
} )
$(window).load(function(){
setTimeout("sticky()",100)
setTimeout("hideEmpty()",100)
} )
} else {
console.warn("bb-fix exist")
}
bbFixExist = 1
/* example: bbReload('18447.1.5.6') */
function BbReloadObj() {
this.jsList = []
//this.locked = 0
this.zoneList = []
this.zone = null;
this.zoneId = null
this.targetWrite = null
this.targetBuffer = ''
/*
this.log = function() {
if (console && console.log) {
var args = Array.prototype.slice.call(arguments)
if (console.log.apply) { console.log.apply(console, args); } else { console.log(args); } // nicer display in some browsers
}
}*/
console.log('bbreload: init')
this.$e = function(id) {
return document.getElementById(id)
}
this.$t = function(tag) {
return document.getElementsByTagName(tag)[0]
}
var self = this;
this.addZone = function(zoneId) {
/* dam az sem, abych nepresmahnul document write uz na zacatku */
document.write = window.document.write = document.writeln = window.document.writeln = function(txt) {
console.log('write: '+txt.substring(0,100).replace(/\r?\n/g,'\\n')+' ...')
self.targetBuffer += txt
}
if (this.zoneList.indexOf(zoneId) > -1) {
console.log('skip: zone '+zoneId+' in zoneList')
return
}
if (zoneId == this.zoneId) {
console.log('skip: zone '+zoneId+' now runnig')
return
}
if (this.zoneList.indexOf(zoneId) == -1 && zoneId!=this.zoneId) {
console.log('add ok '+zoneId)
this.zoneList.push(zoneId)
console.log('jsList len',this.jsList.length)
if (this.jsList.length==0) {
this.runNextZone() // nic nebezi, tak zacnu
}
}
}
this.runNextZone = function() {
/* vytahne prvni z fronty */
this.zoneId = this.zoneList.shift()
console.log('get next zone:',this.zoneId, 'from', this.zoneList)
if(this.zoneId) {
this.reloadZone(this.zoneId)
}
else {
console.log('end - empty zoneList')
}
//document.write('aaa'+zoneId)
}
this.flushBuffer = function() {
console.log('flush', this.targetBuffer.length+'bytes to ', this.targetWrite)
this.targetWrite.innerHTML += this.targetBuffer;
this.targetBuffer = '';
}
this.getJSList = function() {
var arr_tmp = this.zone.getElementsByTagName('script')
arr_tmp = Array.prototype.slice.call(arr_tmp) // copy
var arr = [];
for(var i=0; i < arr_tmp.length; i++) { //>
var js = arr_tmp[i];
if (!js.getAttribute('is-orig') && !js.getAttribute('is-copy')) {
//this.log('js-array',js)
arr.push(js)
}
}
console.log('array len '+arr.length)
return arr;
}
this.runNextJs = function() {
this.flushBuffer();
this.jsList = this.getJSList()
var js = this.jsList.shift() // vytahnu prvni script ze zasobniku
if (!js) {
console.log('end - empty js list - zone '+this.zoneId+' complete')
this.runNextZone();
return
}
js.setAttribute('is-orig',1)
var script = document.createElement('script');
script.setAttribute('is-copy',1)
if (js.text) {
console.log("script: inline")
script.text = js.text //run script inside div
}
else {
console.log("script: src "+js.src)
script.src = js.src
}
script.onload = function() { console.log('script-src: loaded '+this.src); self.runNextJs() }
script.onerror = function() { console.log('script-src: error '+this.src); self.runNextJs() }
var span = document.createElement('span');
js.parentNode.insertBefore(span, js.nextSibling); // vlozim za orig script
js.parentNode.insertBefore(script, js.nextSibling); // vlozim za orig script
this.targetWrite = span
if (js.text) { this.runNextJs() }
}
this.reloadZone = function(zoneId) {
// cistka starych dat
var b2n = this.$e('bmone2n-'+zoneId)
if (b2n) { b2n.innerHTML = '' }
var b2t = this.$e('bmone2t-'+zoneId)
if (b2t) { b2t.parentNode.removeChild(b2t); }
var b2t = document.createElement('div')
b2t.id = 'bmone2t-'+zoneId
b2t.style.cssText = "display:none;"
this.$t('body').appendChild(b2t)
this.targetWrite = b2t
this.zone = b2t
//bmone2n.adRepository = {}
bmone2n.positions = {}
bmone2n.addPosition(zoneId,'');
bmone2n.getAd('go.cz.bbelements.com','',''+(typeof(bburlparam)=='string'?'&'+bburlparam:''),'utf-8');
bmone2n.makeAd(zoneId);
//bmone2n.moveAd();
this.runNextJs() /* dela flush */
}
}
var _bbReload = new BbReloadObj()
function bbReload(zoneId) {
/* back compatibility */
_bbReload.addZone(zoneId)
}