var adsDiv = "
"; var adsDivWrapper = "
"; $("#xg_body").before(adsDivWrapper); $("#ads_div").html(adsDiv); var adDivNum = 5 ; var curAdDivNum = 0; var nextAdDivNum = 1; function rotateAds() { nextAdDivNum = ( curAdDivNum + 1 ) % adDivNum; $("#ads_div_"+curAdDivNum).fadeOut(1000, function () { $("#ads_div_"+nextAdDivNum).fadeIn(1000); }); curAdDivNum = nextAdDivNum; } setInterval("rotateAds()", 21000); randNum = Math.floor(Math.random() * (adDivNum + 1)); nextAdDivNum = ( randNum + 1 ) % adDivNum; $("#ads_div_"+curAdDivNum).fadeOut(100, function () { $("#ads_div_"+nextAdDivNum).fadeIn(100); }); curAdDivNum = nextAdDivNum;