var AdSponsorBlock = Class.create(); AdSponsorBlock.prototype = { initialize: function(opt) { for (i in opt) { this[i] = opt[i]; } this.current_ids = [0, 0]; this.load(); }, load: function() { var obj = this; $.ajax({ url: BASE_URL+'/ad_sponsor_block', type: 'POST', data: { action: 'get_banner', 'current_ids[0]': obj.current_ids[0], 'current_ids[1]': obj.current_ids[1], id_type: obj.id_type, markets: obj.markets }, beforeSend: function() { }, dataType: 'json', error: function (request, textStatus, errorThrown) { //alert(textStatus +' ' + errorThrown); }, success: function(data) { if (typeof data.list == 'object') { obj.render(data.list, data.num_rows); setTimeout('banner_block['+obj.index+'].load()', obj.timeInterval); } }, complete: function(request, textStatus) { } }); }, render: function(list, num_rows) { this.container.empty(); var itemContainerStart = ''; var itemContainerEnd = ''; var html = ''; if (num_rows > 0) { html +=''; itemContainerStart = ''; } var item; var notifyUrl; for (var i in list) { item = list[i]; notifyUrl = BASE_URL + '/sponsor_click?id=' + item.id; this.current_ids[i] = item.id; html += itemContainerStart + '' + itemContainerEnd; } if (num_rows > 0) { html +='
'; itemContainerEnd = '
'; } this.container.html(html); } }; $(document).ready(initAdSponsorBlock); var banner_block = []; function initAdSponsorBlock() { $('div[sponsor_block]').each(function(){ var index = banner_block.length; var opt = { index: index, timeInterval: 30000, container:$(this), id_type:$(this).attr('sponsor_block'), markets:$(this).attr('markets') }; if (opt.id_type == '2') { opt.width = AD_BANNER_WIDTH; opt.height = AD_BANNER_HEIGHT; } banner_block[index] = new AdSponsorBlock(opt); }); }