SBN.HubPage={init:function(a){this.options=Object.extend(a||{},{});this.updateInterval=this.options.updateInterval||45},checkForUpdates:function(){url="/hub_pages/check_for_updates/"+this.options.hub_page.id+"?last_version="+this.options.hub_page.version+"&ids="+this.options.entry_ids;new Ajax.Request(url,{asynchronous:true,evalScripts:true,onSuccess:SBN.HubPage.handleUpdates})},startAutoUpdate:function(){SBN.HubPage.stopAutoUpdate();SBN.HubPage.autoUpdater=new PeriodicalExecuter(function(){SBN.HubPage.checkForUpdates()},SBN.HubPage.updateInterval)},autoUpdateRunning:function(){return(SBN.HubPage.autoUpdater!=undefined&&SBN.HubPage.autoUpdater.running)},stopAutoUpdate:function(){if(SBN.HubPage.autoUpdater!=undefined){SBN.HubPage.autoUpdater.stop();SBN.HubPage.autoUpdater=undefined}},handleUpdates:function(b){data=b.responseText.evalJSON();SBN.HubPage.options.entry_ids=data.entry_ids;$$("p.count.count-stream").each(function(c){c.removeClassName("new-update-count")});$$("p.count.count-link").each(function(c){c.removeClassName("new-update-count")});for(var a in data.updates){node_id="node_"+a+"_count_stream";html=data.updates[a];if($(node_id)){$(node_id).innerHTML=html.count;$(node_id).addClassName("new-update-count");if(html.headline!=undefined){ul=$("node_"+a+"_update_list");nli=new Insertion.Top(ul,html.headline);new Effect.Highlight(ul.parentNode,{duration:4})}}}}};SBN.HubPage.Commentary={init:function(a){Object.extend(this,a||{})},toggleEditor:function(){$(this.form_container_id).toggle()},cancel:function(){$(this.preview_id).innerHTML="";$(this.form_id).reset()},publish:function(){params=Form.serialize($(this.form_id));new Ajax.Request("/hub_pages/publish_commentary",{asynchronous:true,evalScripts:true,parameters:params,onSuccess:function(a){$(this.form_id).reset();$(this.preview_id).innerHTML="";this.toggleEditor()}.bind(this)})},preview:function(){params=Form.serialize($(this.form_id));new Ajax.Request("/hub_pages/preview_commentary",{asynchronous:true,evalScripts:true,parameters:params,onComplete:function(a){}.bind(this)})}};SBN.HubPage.RecentBlogPosts={init:function(a){this.options=Object.extend(a||{});Event.observe(window,"load",function(){this.recentPostsTabs=new Control.Tabs($("recent_posts_tab_list"),{defaultTab:"recent_posts_"+this.options.defaultTab});this.recentPostsTabs.observe("beforeChange",function(d){var c=this.recentPostsTabs.activeLink;if(c){var b=$(c.id+"s_for_feed");b.hide()}}.bind(this));this.recentPostsTabs.observe("afterChange",function(c){var d=this.recentPostsTabs.activeLink;if(d){var b=$(d.id+"s_for_feed");b.show()}}.bind(this))}.bind(this))}};