var HeaderBuzz = function(){ this.abtest = 0; this.header_buzz = $A(); this.page_quantity = 3; this.current_page = 1; this.clicktrack = false; this.total_items = this.header_buzz.length; this.attach_click_handlers = function(){ universal_dom.assign_handler({bucket:'abtrack',event:'mousedown',handler:this.click_handler}); }.bind(this); this.click_handler = function( event ){ // if ( typeof _gaq != 'undefined' && _gaq != null ){ // _gaq.push(['_trackPageview', '/_ga/click/hot_top/test007/click/']); // } }.bind(this); this.draw_page = function( page ){ if( 1 == page ){ $('hothead-scripted').hide(); $('hothead-unscripted').show(); return; } var start_index = ((page - 1) * this.page_quantity) - this.page_quantity; var buzzes = this.header_buzz.slice( start_index, start_index + this.page_quantity ); var html = $A(''); for( var i = 0; i < buzzes.length; i++ ){ if(!buzzes[i].badge_type) buzzes[i].no_badge = 'no-badge'; buzzes[i].referrer_info = ''; if (buzzes[i].referrer_title) { buzzes[i].referrer_info = '
'+ buzzes[i].referrer_title +'
'; } else if (buzzes[i].referrer_domain) { buzzes[i].referrer_info = '
Hot On '+ buzzes[i].referrer_domain +'
'; } if (buzzes[i].form == 'link' && buzzes[i].user_partner) { buzzes[i].gt_label = 'partner/' + buzzes[i].link_buzz.match(/:\/\/(www\.)?(.[^/:]+)/)[2]; } else { if (buzzes[i].login_type == 'terminal') {buzzes[i].gt_label = 'editor/' + buzzes[i].username;} else {buzzes[i].gt_label = 'user/' + buzzes[i].username;} } var buzz_str = this.buzz_template.evaluate({ buzz: buzzes[i], slot: (i+1) }); html.push( buzz_str ); } $('hothead-unscripted').hide(); $('hothead-scripted').update( html.join('') ); $('hothead-scripted').show(); universal_dom.update($('hothead-scripted')); if (this.clicktrack && typeof gtrack != 'undefined') gtrack._init(this.clicktrack, {skip_impression:true}); }; this.init = function(){ var next_link = this.next_link(); var previous_link = this.previous_link(); if( next_link ) next_link.observe( 'click', this.next_handler ); if( previous_link ) previous_link.observe( 'click', this.previous_handler ); if( this.abtest ){ universal_dom.assign_handler({bucket:'abtrack',event:'mousedown',handler:this.click_handler}); } }; this.is_first_page = function(){ return 1 >= this.current_page; }; this.is_last_page = function(){ return ( (this.current_page * this.page_quantity) - this.page_quantity >= this.header_buzz.length ); }; this.next_handler = function( event ){ event.stop(); var next = this.next_page(); if( next ){ this.draw_page( next ); this.current_page = next; this.previous_link().show(); if( this.is_last_page() ){ this.next_link().hide(); } } }.bind( this ); this.next_link = function(){ return $('header_buzz_next'); }; this.next_page = function(){ if( this.is_last_page() ){ return null; } return this.current_page + 1; }; this.previous_handler = function( event ){ event.stop(); var prev = this.previous_page(); if( prev ){ this.draw_page( prev ); this.current_page = prev; this.next_link().show(); if( this.is_first_page() ){ this.previous_link().hide(); } } }.bind( this ); this.previous_link = function(){ return $('header_buzz_previous'); }; this.previous_page = function(){ if( this.is_first_page() ){ return null; } return this.current_page - 1; }; this.set_header_buzz = function( json ){ this.header_buzz = $A( json ); }; }; load_header_buzz();