SBN.HubPage={init:function(a){this.options=Object.extend(a||{},{});this.updateInterval=this.options.updateInterval||45},checkForUpdates:function(){if(this.options.entry_ids){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||{});document.observe("dom:loaded",function(){this.recentPostsTabs=new Control.Tabs($("recent_posts_tab_list"),{defaultTab:"recent_posts_"+this.options.defaultTab});var c=this.recentPostsTabs.activeLink;if(c){var b=$(c.id+"s_for_feed");b.show()}this.recentPostsTabs.observe("beforeChange",function(f){var e=this.recentPostsTabs.activeLink;if(e){var d=$(e.id+"s_for_feed");d.hide()}}.bind(this));this.recentPostsTabs.observe("afterChange",function(e){var f=this.recentPostsTabs.activeLink;if(f){var d=$(f.id+"s_for_feed");d.show()}}.bind(this))}.bind(this))}};SBN.HubPage.Carousel={nodeCarousels:$H(),init:function(a){this.storyCarousel=new Carousel($("carousel-wrapper"),$$("#carousel-content .slide"),$$("a.carousel-jumper"),{visibleSlides:1,circular:true,auto:true,duration:0.1,frequency:10,wheel:false,afterMove:function(){this.storyCarousel.controls.each(function(c,b){if(this.storyCarousel.current&&c.rel==this.storyCarousel.current.id){c.addClassName("carousel-selected")}else{c.removeClassName("carousel-selected")}}.bind(this))}.bind(this)});this.storyCarousel.controls.first().addClassName("carousel-selected");document.observe("dom:loaded",function(){$$(".carousel-jumper").invoke("observe","mouseover",function(d){if(this.storyCarousel){this.storyCarousel.stop();this.storyCarousel.disabled=false;var b=Event.findElement(d,"a");try{var c=this.storyCarousel.options.duration;this.storyCarousel.options.duration=0;this.storyCarousel.moveTo(b.rel)}finally{this.storyCarousel.options.duration=c}}}.bind(this));$$(".carousel-jumper").invoke("observe","click",function(b){if(this.storyCarousel){this.storyCarousel.stop()}window.location=Event.findElement(b,"a").getAttribute("href")}.bind(this));$$(".node-control").invoke("observe","click",function(b){if(this.storyCarousel){this.storyCarousel.stop()}}.bind(this))}.bind(this))},initNodeCarousel:function(b){var a="node_"+b+"_update_list";var c="a.node-control-"+b;if($(a).childElements().length==2){$$(c).invoke("hide")}else{this.nodeCarousels.set(b,new Carousel($("nodescroll-wrapper-"+b),$$("#"+a+" .recent-update"),$$(c),{visibleSlides:1,circular:true,auto:false,wheel:false,duration:0.1,controlClassName:"node-control"}))}}};