(function($) {
    $.fn.extend({
        showInterstitial: function(options) {
            var blockingCookiePair = 'adzone_interstitial=blocked';
            if (options.blockingCookie && document.cookie.indexOf(blockingCookiePair) > -1) {
                return;
            }
            $('#advert-interstitial > a:eq(0)').click(function() {
                $().closeInterstitial();
                return false;
            });

            $('body').addClass('interstitial');

            if (options.timeout) {
                setTimeout(function() { $().closeInterstitial() }, options.timeout * 1000);
            }
            if (options.bodyCss) {
                if ($('#advert-interstitial').attr('style') !== undefined) {
                    $('#advert-interstitial').attr('styleOrig', $('body').attr('style'));
                }
                $('#advert-interstitial').css(options.bodyCss);
            }
            if (options.boxCss) {
                $('#advert-interstitial').css(options.boxCss);
            }
            if (options.blockingCookie) {
                var expires = '';
                if (options.cookieExpirationSeconds) {
                    var milliSeconds = (new Date()).getTime() + options.cookieExpirationSeconds * 1000;
                    expires = ";expires=" + (new Date(milliSeconds)).toGMTString();
                }
                document.cookie = blockingCookiePair + expires;
            }
        },
        closeInterstitial: function() {
            if ($('#advert-interstitial').attr('styleOrig') !== undefined) {
                $('#advert-interstitial').attr('style', $('body').attr('styleOrig'));
            }
            $('body').removeClass('interstitial');
        },
        showStickyLeaderboard: function() {
            var lb = $('#advert-ahead');
            lb.addClass('sticky').css({left:$("#navigation").position().left}).next().css({'padding-top':lb.height()});
        },
        closeStickyLeaderboard: function() {
            $('#advert-ahead.sticky').removeClass('sticky').css({left:"auto"}).next().css('padding-top', '0');
        },
        showStickySkyscraper: function() {
            $(window).scroll(function(){
		if($(window).scrollTop() < ($("#page-navigation").height() + $("#page-column-left").height()-$("#advert-sky").height()) )
		{
			if($(window).scrollTop()>$("#page-navigation").height())
			{
				$("#advert-sky").css("top", $(window).scrollTop()-$("#page-navigation").height());
			}
		}
   	    });

	    $(window).bind('scrollstop', function(e){
	    	if($(window).scrollTop()<5) 
	    	{
			$("#advert-sky").css("top", 0);
	    	}
	    });
        },
        closeStickySkyscraper: function() {
        },
	setWallPaperLabel: function(idSpot){
		$(window).bind("load", function(){
			if(typeof(AV_posArr)!="undefined" && typeof(AV_posArr[idSpot])!="undefined" && typeof(AV_posArr[idSpot]["html"])!="undefined")
			{
				$("#advantage-label-" + idSpot).html("<div align='center'><small>reklama</small></div>");
			}
		});
	}
   });
})(jQuery);


//**************************************************
// SKYSCRAPER HANDLER
//**************************************************
$(document).ready(function(){
	var ViewAfterWidth = 1280;
	var bbs=screen;
	if(! (((bbs.availWidth && bbs.availWidth!="undefined") && bbs.availWidth>=ViewAfterWidth) || ((bbs.width && bbs.width!="undefined") && bbs.width>=ViewAfterWidth)))
	{
		$("#advert-sky").hide();
	}
});

(function(){
 
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
 
    special.scrollstart = {
        setup: function() {
 
            var timer,
                handler =  function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
 
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid1, handler);
 
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
 
    special.scrollstop = {
        latency: 300,
        setup: function() {
 
            var timer,
                    handler = function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    }
 
                    timer = setTimeout( function(){
 
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
 
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid2, handler);
 
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };
 
})();




