function addloadfunc(f){
        if(window.attachEvent){
                window.attachEvent("onload", f);
        } else 
                if(document.addEventListener || window.addEventListener){
                        if(document.addEventListener){
                                document.addEventListener("load", f, false);   
                        };

                        if(window.addEventListener){
                                window.addEventListener("load", f, false); 
                        };

                } 
                else {
                        if(typeof window.onload == "function"){
                                var fOld = window.onload;
                                window.onload = function(){ fOld(); f(); };
                        } 
                        else {
                                window.onload = f;
                        };
                };

} 

function banner(element) {
    if (null == element) return;
    var obj = this;
    var elem = element;
    var links = null;
    var cur = null;
    var max = 0;
    
    this.click = function () {
        if (obj.links.length >0 && obj.cur >=0 && obj.cur <= obj.max) window.open('/adv/click/' + obj.links[obj.cur]);
        return false;
    }
    this.update = function () {
    	obj.cur += 1;
        if (obj.cur > obj.max){ obj.cur = 0; }
        elem.src = obj.images[obj.cur]
        setTimeout(obj.update, 20000);
    }
    setTimeout(this.update, 20000);
    elem.parentNode.onclick = this.click
}

function init_adv(){


      
         
        var adv_top0 = new banner(document.getElementById('adv_0'));
        if ( adv_top0 ) {
            adv_top0.links = ['29','37'];
            adv_top0.images = ['/images/adv/1c.gif','/images/adv/gidra.jpg'];
            adv_top0.max = 1;
            adv_top0.cur = Math.floor(Math.random() * adv_top0.max);
        }
      
    
      
         
        var adv_top1 = new banner(document.getElementById('adv_1'));
        if( adv_top1 ) {
            adv_top1.links = ['2','15','36'];
            adv_top1.images = ['/images/adv/cdo468x60x1.gif','/images/adv/cherniy-kot01.gif','/images/adv/zadvizhkin.jpg'];
            adv_top1.max = 2;
            adv_top1.cur = Math.floor(Math.random() * adv_top1.max);
        }    
    
    
      
         
        var adv_top2 = new banner(document.getElementById('adv_2'));
        if ( adv_top2 ) {
            adv_top2.links = ['17','7','26'];
            adv_top2.images = ['/images/adv/ufatime234x60.gif','/images/adv/virtual.gif','/images/adv/bashexpo.gif'];
            adv_top2.max = 2;
            adv_top2.cur = Math.floor(Math.random() * adv_top2.max);
        }
    
    
      
         
        var adv_top3 = new banner(document.getElementById('adv_3'));
        if ( adv_top3 ) {
            adv_top3.links = ['6','25'];
            adv_top3.images = ['/images/adv/niit234x60.gif','/images/adv/ufalive.jpg'];
            adv_top3.max = 1;
            adv_top3.cur = Math.floor(Math.random() * adv_top3.max);
        }
    
    

    
}

addloadfunc(init_adv);