CNB.Toolbox={toolbars:[],votes:[]};CNB.Toolbar=new Class({Implements:Options,options:{cid:null,rid:null,pdf:null,embed:false,print:false,share:true,transcript:false,voteMinus:false,shareOffset:{x:0,y:2},shareRelative:null},initialize:function(options){this.setOptions(options);this.load()},load:function(){var jsonp=new Request.JSONP({url:CNB.env.apiService+'service/spot/',data:{'spot':'toolbar','format':'xml','cid':this.options.cid,'ct':CNB.env.host,'viewType':'json'},onComplete:this.extract.bind(this)}).send()},extract:function(data){if($chk(data)){var toolbarData=($type(data.Toolbar.Content)=='array')?data.Toolbar.Content:[data.Toolbar.Content];toolbarData.each(function(el){var cmntCount=el.Comments['$'];var rating=el.Rating['$'];var contentId=el['@id'];if($('toolbar-'+contentId)){this.buildTools(contentId);this.buildVoting(contentId,rating)}if($('comment-count-'+contentId)){this.setCmntCount(contentId,cmntCount)}}.bind(this))}},buildTools:function(contentId){this.toolbar=new Element('ul',{'class':'toolbar'}).inject($('toolbar-'+contentId),'top');this.tools={container:[],anchor:[]};this.toolVals=CNB.Toolbox.toolbars[contentId];if(this.toolVals.share){var emailUrl=($chk(this.toolVals.emailUrl))?this.toolVals.emailUrl:null;this.makeTool({'title':'Share','className':'t-share'});var share=new CNB.Share({cid:contentId,title:this.toolVals.title,url:this.toolVals.url,emailUrl:emailUrl,btn:this.tools.container['t-share'],shareOffset:this.options.shareOffset,shareRelative:this.options.shareRelative})}if(this.toolVals.pdf){var pdfUrl=this.toolVals.pdf;this.makeTool({'title':'Download PDF','className':'t-pdf','events':{'click':function(){location.href=pdfUrl}}})}if(this.toolVals.print){var printUrl=($chk(this.toolVals.printUrl))?this.toolVals.printUrl:false;this.makeTool({'title':'Print','className':'t-print','events':{'click':function(){if(printUrl){location.href=printUrl}else{window.print()}}}})}if(this.toolVals.embed){this.makeTool({'title':'Embed this video','className':'t-embed','events':{'click':function(){var layered=new CNB.Layered($('embed-'+contentId),{title:'Embed this video',className:'embed'})}}})}if(this.toolVals.transcript){this.makeTool({'title':'Transcript','className':'t-transcript','events':{'click':function(){var layered=new CNB.Layered($('transcript-'+contentId),{title:'Transcript'})}}})}},buildVoting:function(contentId,rating){var voteTool=new Element('li',{'class':'t-vote'}).inject(this.toolbar,'bottom');var optionsBox=new Element('span',{'class':'t-vote-options'}).inject(voteTool,'bottom');var scoreBox=new Element('span',{'class':'t-vote-score','text':rating}).inject(voteTool,'bottom');CNB.Toolbox.votes[contentId]=new CNB.Voting({cid:contentId,title:this.toolVals.title,url:this.toolVals.url,rid:this.options.rid,scoreBox:scoreBox,optionsBox:optionsBox});if(CNB.Toolbox.votes[contentId].hasVoted){optionsBox.addClass('t-thanks')}else{var gatedVoting=function(voteFn){if(CNB.UserVars.get('loggedIn')||$chk(CNB.UserVars.get('regId'))){voteFn()}else{if(typeof(CNB.Reg)!='undefined'){CNB.Reg.addEvent('logInFormLoad',CNB.Reg.addNotify.bind(CNB.Reg,'Please Log In to vote.'));CNB.Reg.addEvent('executeBehavior',voteFn);CNB.Reg.setOptions({'regSource':'tbar-vote'});CNB.Reg.logIn()}else{location.href=CNB.env.ursLogin+'?path='+encodeURIComponent(document.location.href)}}};var rec=new Element('a',{'class':'t-vote-plus','text':'Recommend','events':{'click':function(){gatedVoting(function(){CNB.Toolbox.votes[contentId].vote('1')})}}}).inject(optionsBox,'bottom');if(this.options.voteMinus){var noRec=new Element('a',{'class':'t-vote-minus','text':'Don\'t Recommend','events':{'click':function(){gatedVoting(function(){CNB.Toolbox.votes[contentId].vote('-1')})}}}).inject(optionsBox,'bottom')}}},makeTool:function(options){this.tools.container[options.className]=new Element('li',{'class':options.className}).inject(this.toolbar,'bottom');this.tools.anchor[options.className]=new Element('a',{'href':options.href,'title':options.title,'text':options.title,'events':options.events}).inject(this.tools.container[options.className],'top')},setCmntCount:function(contentId,cmntCount){var cmntText=(cmntCount.toInt()==1)?'Comment':'Comments';$('comment-count-'+contentId).set('html','<b>'+cmntCount+'</b> '+cmntText)}});CNB.Voting=new Class({Implements:Options,options:{cid:null,title:'',url:'',rid:null,optionsBox:null,scoreBox:null},initialize:function(options){this.setOptions(options);this.hasVoted=false;this.regId=($chk(this.options.rid))?this.options.rid:'';var history=Cookie.read('service');this.voteHistory=(history)?history:'';this.voteHistory.split('~').each(function(el){if(el==this.options.cid){this.hasVoted=true}}.bind(this))},vote:function(credit){CNB.log('vote: '+credit);var jsonp=new Request.JSONP({url:CNB.env.apiService+'service/spot/',data:{'spot':'rate','format':'xml','cid':this.options.cid,'ct':CNB.env.host,'title':this.options.title.trim(),'url':this.options.url.trim(),'rid':CNB.UserVars.get('regId'),'cr':credit,'viewType':'json'},onComplete:this.extract.bind(this)}).send()},extract:function(data){if($chk(data)){this.score=data.Votes.Content.VoteCount['$'];this.processVote()}},processVote:function(el){this.setScore();this.setThanks();this.setCookie()},setScore:function(){this.options.scoreBox.set('html',this.score);CNB.log("this.score: "+this.score)},setThanks:function(){this.options.optionsBox.set('html','thanks').addClass('t-thanks');this.hasVoted=true},setCookie:function(){Cookie.write('service',this.voteHistory+'~'+this.options.cid,{duration:30,domain:CNB.env.cookieHost,path:'/'})}});CNB.Share=new Class({Implements:Options,options:{cid:null,title:'',url:'',emailUrl:null,btn:null,shareRelative:null,shareOffset:{x:0,y:0}},initialize:function(options){this.setOptions(options);this.buildContainer();this.buildItems();var shareRelative=($chk(this.options.shareRelative))?this.options.shareRelative:this.options.btn;var pop=new CNB.Pop(this.options.btn,this.container,{relative:shareRelative,offset:this.options.shareOffset})},buildContainer:function(){this.container=new Element('div',{'class':'t-share-options'}).inject(this.options.btn,'bottom');this.shareList=new Element('ul').inject(this.container,'bottom')},buildItems:function(){var title=encodeURIComponent(this.options.title);var url=encodeURIComponent(this.options.url);var path=encodeURIComponent(document.location);var emailUrl=this.options.emailUrl;if(CNB.env.site=='bnet'){this.makeItem({'title':'MyBNET','className':'t-share-mybnet','events':{'click':function(){var action=function(){CNB.log('http://www.bnet.com/5262-13093-0.html?link='+url+'&title='+title+'&path='+path);location.href='http://www.bnet.com/5262-13093-0.html?link='+url+'&title='+title+'&path='+path};if(CNB.UserVars.get('loggedIn')){action()}else{if(typeof(CNB.Reg)!='undefined'){CNB.Reg.addEvent('logInFormLoad',CNB.Reg.addNotify.bind(CNB.Reg,'Please Log In to to save this link to myBNET.'));CNB.Reg.addEvent('executeBehavior',action);CNB.Reg.setOptions({'regSource':'tbar-mybnet'});CNB.Reg.logIn()}else{action()}}}}})}this.makeItem({'title':'Email','className':'t-share-email','events':{'click':function(){if(emailUrl){location.href=emailUrl}else{window.open('mailto:?subject='+title+'&body='+url)}}}});this.makeItem({'title':'Digg','className':'t-share-digg','events':{'click':function(){window.open('http://digg.com/submit?url='+url+'&title='+title)}}});this.makeItem({'title':'Facebook','className':'t-share-fb','events':{'click':function(){var d=document,f='http://www.facebook.com/share',l=d.location,e=encodeURIComponent,p='.php?src=bm&v=4&i=1208544185&u='+e(l.href)+'&t='+e(d.title);1;try{if(!/^(.*\.)?facebook\.[^.]*$/.test(l.host))throw(0);share_internal_bookmarklet(p)}catch(z){a=function(){if(!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=0,width=626,height=436'))l.href=f+p};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0)}}});this.makeItem({'title':'Twitter','className':'t-share-tweet','events':{'click':function(){window.open('http://twitter.com/home?status='+title+'%20'+url)}}});this.makeItem({'title':'Google','className':'t-share-goog','events':{'click':function(){var a=window,b=document,c=encodeURIComponent,d=a.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+c(b.location)+"&title="+c(b.title),"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height=420px,width=550px,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus()},300)}}});this.makeItem({'title':'Delicious','className':'t-share-del','events':{'click':function(){window.open('http://del.icio.us/post?url='+url+'&title='+title)}}});this.makeItem({'title':'StumbleUpon','className':'t-share-su','events':{'click':function(){window.open('http://www.stumbleupon.com/submit?url='+url)}}});this.makeItem({'title':'Newsvine','className':'t-share-nv','events':{'click':function(){window.open('http://www.newsvine.com/_wine/save?popoff=1&u='+url,'newsvine','toolbar=no,width=590,height=600,resizable=yes,scrollbars=yes')}}});this.makeItem({'title':'LinkedIn','className':'t-share-linkedin','events':{'click':function(){window.open('http://www.linkedin.com/shareArticle?mini=true&url='+url+'&title='+title+'&source='+CNB.env.domain)}}});this.makeItem({'title':'My Yahoo','className':'t-share-yahoo','events':{'click':function(){var d=document,f='http://bookmarks.yahoo.com/toolbar/savebm?',l=d.location,e=encodeURIComponent,p='u='+e(l.href)+'&t='+e(d.title)+'&opener=bm&ei=UTF-8';1;a=function(){if(!window.open(f+p,'popup','toolbar=0,status=0,resizable=1,scrollbars=1,width=450,height=480'))l.href=f+p};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}void(0)}}});this.makeItem({'title':'Technorati','className':'t-share-techno','events':{'click':function(){window.open('http://technorati.com/faves?add='+url)}}});this.makeItem({'title':'Reddit','className':'t-share-reddit','events':{'click':function(){window.open('http://reddit.com/submit?url='+url+'&title='+title)}}})},makeItem:function(options){var item=new Element('li').inject(this.shareList,'bottom');var anchor=new Element('a',{'class':options.className,'title':options.title,'text':options.title,'events':options.events}).inject(item,'top')}});