var ajaxUrl = 'http://kostroma.com/banner.ajax.php';
var banners;
var preTimer = setInterval(processBanners, 500);
var timer;
var timerStarted = false;

function processBanners()
{
    if (!timerStarted)
        banners = $('.banner');
    
    var h = $(window).height() + $(window).scrollTop();
    var w = $(window).width() + $(window).scrollLeft();
    var ids = '';
    
    banners.each(function(){
        banner = $(this);
        if (!banner.hasClass('shown'))
        {
            if (banner.offset().top < h && banner.offset().left < w)
            {
                banner.addClass('shown');
                ids += 'id[]=' + this.getAttribute('id').substr(6) + '&';
            }
        }
    });
    
    if (ids.length > 0)
        $.post(ajaxUrl, ids);
}

$(document).ready(function(){

    clearInterval(preTimer);
    
    banners = $('.banner');
    
    $(window).scroll(function(){
        clearTimeout(timer);
        timer = setTimeout(processBanners, 1000);
    });
    
    $(window).resize(function(){
        resize1();
        clearTimeout(timer);
        timer = setTimeout(processBanners, 1000);
    });
    
    timerStarted = true;    
    resize1();
    processBanners();
});

function resize1()
{
    var w = document.getElementById("container-tb").offsetWidth;

    if (w < 1100)
    {
        $("#menu-tb tr td a").css({fontSize: '10px'}) 
    }
    else
    {
        $("#menu-tb tr td a").css({fontSize: '12px'});
    }
}
