var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function encode64(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;do{chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}
output=output+keyStr.charAt(enc1)+keyStr.charAt(enc2)+
keyStr.charAt(enc3)+keyStr.charAt(enc4);}while(i<input.length);return output;}
function decode64(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{enc1=keyStr.indexOf(input.charAt(i++));enc2=keyStr.indexOf(input.charAt(i++));enc3=keyStr.indexOf(input.charAt(i++));enc4=keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}
if(enc4!=64){output=output+String.fromCharCode(chr3);}}while(i<input.length);return output;}
HistoryManager=Class.create({listener:null,waitTime:200,currentWaitTime:0,currentLocation:null,iframe:null,ignoreLocationChange:null,fireOnNewListener:null,firstLoad:null,initialize:function(){this.currentLocation=this.getCurrentLocation();this.createDomElements();if(Prototype.Browser.IE){this.ignoreLocationChange=true;this.firstLoad=false;}else{this.ignoreLocationChange=false;}
this.fireOnNewListener=true;setInterval(this.checkLocation.bind(this),200);Event.observe(window,'unload',function(){this.firstLoad=null}.bind(this));},addListener:function(listener){this.listener=listener;if(this.fireOnNewListener){this.fireHistoryEvent(this.currentLocation);this.fireOnNewListener=false;}},add:function(newLocation){if(!newLocation)return;if(Prototype.Browser.WebKit){newLocation=this.removeHash(newLocation);this.currentLocation=newLocation;window.location.hash=newLocation;}else{window.setTimeout(function(){this.addImpl(newLocation)}.bind(this),this.currentWaitTime);this.currentWaitTime=this.currentWaitTime+this.waitTime;}},addImpl:function(newLocation){if(this.currentWaitTime>0){this.currentWaitTime=this.currentWaitTime-this.waitTime;}
newLocation=this.removeHash(newLocation);if(newLocation&&$(newLocation)&&this.debugMode){var e="Exception: History locations can not have the same value as _any_ IDs that might be in the document. "+newLocation;throw new Error(e);}
this.ignoreLocationChange=true;this.currentLocation=newLocation;window.location.hash=newLocation;if(Prototype.Browser.IE){this.iframe.src="/blank.html?"+newLocation;}},getCurrentLocation:function(){var r=window.location.href;var i=r.indexOf("#");return(i>=0?r.substr(i+1):"");},createDomElements:function(){if(Prototype.Browser.Opera){this.waitTime=400;var imgHTML='<img src="javascript:location.href=\'javascript:dhtmlHistory.checkLocation();\';" style="display:none" />';$(document.body).insert(imgHTML);}else if(Prototype.Browser.IE){this.waitTime=400;this.iframe=new Element('iframe',{'src':'/blank.html?'+this.currentLocation}).hide();$(document.body).insert(this.iframe);Event.observe(this.iframe,'load',function(){this.iframeLoaded(this.iframe.contentWindow.location)}.bind(this));}},fireHistoryEvent:function(newHash){if(this.listener)
this.listener.call(null,newHash);},checkLocation:function(){if(!Prototype.Browser.IE&&this.ignoreLocationChange){this.ignoreLocationChange=false;return;}
var hash=this.getCurrentLocation();if(hash==this.currentLocation)return;if(Prototype.Browser.IE){if(this.getIframeHash()!=hash){this.iframe.src="/blank.html?"+hash;}else{return;}}
this.currentLocation=hash;this.fireHistoryEvent(hash);},getIframeHash:function(){var doc=this.iframe.contentWindow.document;var hash=String(doc.location.search);if(hash.length==1&&hash.charAt(0)=="?"){hash="";}else if(hash.length>=2&&hash.charAt(0)=="?"){hash=hash.substring(1);}
return hash;},removeHash:function(hashValue){return hashValue.toString().replace(/.*#/,'');},iframeLoaded:function(newLocation){if(this.ignoreLocationChange){this.ignoreLocationChange=false;return;}
var hash=String(newLocation.search);if(hash.length==1&&hash.charAt(0)=="?"){hash="";}
else if(hash.length>=2&&hash.charAt(0)=="?"){hash=hash.substring(1);}
window.location.hash=hash;this.currentLocation=hash;this.fireHistoryEvent(hash);}});if(typeof timer=="undefined"){(function(){timer={start:function(){},stop:function(){},clear:function(){},report:function(){},report_totals:function(){}}})();}
Workfeed.valid_history_options={'feed_key':true,'older_than':true,'polling':true,'threaded':true,'prev_older_than':true,'bosh_polling':true};Workfeed.unread_message_regex=/^\((\d+)\) /;Workfeed.MessageList=Class.create({initialize:function(options){Object.extend(this,{mlv:options.messagelist_options.mlv,last_update_time:new Date(),now_polling:false,blurred:false,add_update_options_observer:false,display_options:{},filter_options:{},bosh_options:{},initialized:false,max_uploads:20});this.init_options();Event.observe(document,'dom:loaded',function(){this.onLoad(options)}.bind(this));},init_options:function(){this.unread_message_count=0;this.unread_message_ids=[];this.fetched_threads={};this.older_than=null;if(this.filter_options)delete this.filter_options.newer_than;},onLoad:function(options){this.historymanager=new HistoryManager();this.addObservers();this.show_spinner();this.update(options);this.setFilterOptionsFromLocation();this.historymanager.addListener(this.locationListener.bind(this));if(options.filter_options&&options.filter_options.bosh_polling){new PeriodicalExecuter(this.update_message_times.bind(this),30);this.xmpp_messagelist=new Workfeed.StropheMessageList(options["bosh_options"]);this.xmpp_messagelist.connect();}else if(options.messagelist_options&&options.messagelist_options.message_refresh_interval&&options.filter_options&&options.filter_options.polling){this.setMessagePoller();}
if(options.apiv2_messages&&options.apiv2_messages.messages){this.initialized=true;this.hide_spinner();}else{timer.start('first messages fetch');this.set_selected_tab();this.refresh_message_list({asynchronous:false});this.set_ui_state();timer.stop('first messages fetch');}
this.register_message_events();},addHistory:function(){var det=$H(this.filter_options).detect(function(pair){if(Workfeed.valid_history_options[pair.key]&&this.orig_filter_options[pair.key]!=pair.value){return true;}else{return false;}}.bind(this));var filter_options;if(!det){this.current_location='';if(this.historymanager.currentLocation!=''){this.historymanager.add('home');}
return;}else{filter_options=$H(this.filter_options);}
if(!filter_options.search){filter_options.keys().each(function(op){if(Object.isUndefined(Workfeed.valid_history_options[op])){filter_options.unset(op);}});}
if(filter_options.feed_key!=this.orig_filter_options.feed_key)filter_options=filter_options.merge({ofk:this.orig_filter_options.feed_key});var current_location=filter_options.toQueryString();this.current_location=current_location;if(det)this.historymanager.add(current_location);},locationListener:function(current_location){if(this.initialized&&current_location==''||current_location=='home'){this.switch_feed(this.orig_filter_options);}else if(current_location!=this.current_location){this.setFilterOptionsFromLocation();this.switch_feed(this.filter_options);}},setFilterOptionsFromLocation:function(){this.current_location=this.historymanager.currentLocation||'';if(this.current_location!=''&&this.current_location!='home'){var filter_options=this.current_location.toQueryParams();this.orig_filter_options.feed_key=filter_options.ofk;$H(Workfeed.valid_history_options).keys().each(function(key){if(filter_options[key]=="true"){filter_options[key]=true;}else if(filter_options[key]=="false"){filter_options[key]=false;}});this.filter_options=filter_options;this.set_ui_state();}},register_message_events:function(){if(!$('messages'))return;$('messages').observe('click',function(event){var message_id=Event.findElement(event,'li').id.replace('message_','');var message_link=Event.findElement(event,'a');if(!message_link)return;switch(message_link.className){case'email':this.email_message(message_id);this.track_page_view("/post/email");event.stop();break;case'delete':if(confirm(t('delete_confirm',{'default':"Are you sure you want to delete this message?"}))){this.remove_message(message_id);this.track_page_view("/post/delete");}
event.stop();break;case'reply':var group_id=null;if($('message_'+message_id))group_id=$('message_'+message_id).getAttribute('group_id');show_reply_form(event,message_id,group_id);


RedBox.showInline('reply');

if($('reply_form_attachments'))
{
	
	$('reply_form').select("input[name='message[pending_attachment_ids][]']").invoke('remove');
	$('reply_form_attachments').update();
	$('reply_form_message_body').value="";
}


this.track_page_view("/post/reply");
event.stop();
break;

case'responses':
this.toggle_threaded_thread(message_id);
this.track_page_view("/post/view_replies");event.stop();break;default:break;}}.bind(this));},replay_last_update:function(){this.update(this.last_update_options);},update:function(options){try{this.last_update_options=options;if(this.mlv&&options.messagelist_options&&options.messagelist_options.mlv&&options.messagelist_options.mlv!=this.mlv){window.location.reload();return;}
if(options["notice"]){show_flash('notice',options["notice"]);}
if(options["error"]){show_flash('error',options["error"]);}
if(options.sidebar)this.update_sidebar(options.sidebar);if(options.messagelist_options)Object.extend(this,options.messagelist_options);if(options.display_options)Object.extend(this.display_options,options.display_options);if(options.filter_options)Object.extend(this.filter_options,options.filter_options);if(options.bosh_options)Object.extend(this.bosh_options,options.bosh_options);if(!this.orig_filter_options)this.orig_filter_options=Object.clone(this.filter_options);delete this.orig_filter_options.newer_than;if(options.apiv2_messages&&options.apiv2_messages.messages){this.update_messages(options);}else{this.update_message_times();}
if($('messages')&&!$('messages').down('li')){this.update_no_messages();}}catch(e){this.handle_infinite_spinner(e);}},update_messages:function(options){if(!options.apiv2_messages)return;if($('no_messages_alert'))$('no_messages_alert').remove();timer.start('update_messages');timer.start('new_feed');this.last_feed=new Workfeed.Feed(options.apiv2_messages);timer.stop('new_feed');var messages=this.last_feed.messages;if(!this.initialized){if(this.filter_options.search){if(options.messagelist_options)this.older_available=options.messagelist_options.older_available;}else if(options.apiv2_messages.meta&&options.apiv2_messages.meta.older_available){this.older_available=true;}else{this.older_available=false;}
this.set_pagination_links_state();}
if(options.filter_options&&options.filter_options.newer_than)this.filter_options.newer_than=options.filter_options.newer_than;if(this.filter_options.threaded&&this.initialized){if(messages.length>0){var new_message_ids=messages.collect(function(msg){if(!$('message_'+msg.id))return msg.id}).compact();if(!options.filter_options.newer_than)this.filter_options.newer_than=new_message_ids.sort(function(a,b){return b-a})[0];this.update_message_counts(new_message_ids);this.show_new_message_notice();}}else{this.add_messages(messages,options);}
this.update_message_times();this.setMessagePoller();timer.stop('update_messages');},update_no_messages:function(feed_key){if(!feed_key)feed_key=this.filter_options.feed_key;if($('spinner_timeout')&&$('spinner_timeout').visible())return;var message;if(feed_key)
message=(feed_key.match(/feed_following/))?t('no_messages_following',{'default':"There are no messages for items you are following."}):(feed_key.match(/feed_received/))?t('no_messages_received_yet',{'default':"You haven't received any messages yet."}):(feed_key.match(/feed_user/))?t('no_messages_sent_yet',{'default':"You haven't sent any messages yet."}):(feed_key.match(/feed_group/))?t('no_group_posts_yet',{'default':"No messages posted to this group yet."}):null;if(!message)message=t('no_messages_found',{'default':"No messages were found."});var message_li=new Element('li',{'id':'no_messages_alert','class':'notice'}).update(message);$('messages').update();$('messages').insert(message_li);},add_messages:function(messages,options){if(!messages||messages.size==0)return;var new_message_ids=[];var last_posted_message_by_me=null;var thread_ids={};timer.start('add_messages');var errors=[];for(var i=messages.length-1;i>-1;i--){try{var message=messages[i];if(!$('message_'+message.id)){if(!this.filter_options.newer_than||message.id>this.filter_options.newer_than)this.filter_options.newer_than=message.id;if(message.sender_id==this.current_user_id){if(!this.last_posted_message_by_me_id||this.last_posted_message_by_me_id<message.id){if(!last_posted_message_by_me||last_posted_message_by_me.id<message.id){last_posted_message_by_me=message;}}}
var message_html=this.build_message(message,options);if(this.filter_options.threaded&&!message.thread_starter){if($('message_'+message.thread_id)&&$('message_'+message.thread_id+'_replies')){if(!$('message_'+message.id)){$('message_'+message.thread_id+'_replies').insert(this.build_message(message));}}}else{new_message_ids.push(message.id);$('messages').insert({top:message_html});}}}catch(e){errors.push(e);}}
if(errors.length>0)log_javascript_errors(errors);this.prune_messages(this.messages_per_page);if(this.initialized&&options.hide_new_messages!=false){this.blind_messages(new_message_ids);}
this.update_message_counts(new_message_ids);timer.stop('add_messages');},update_invite_count:function(count){if(!$('invite_count'))return;var count_text=(count>0)?"("+count+")":"";$('invite_count').update(count_text);},setMessagePoller:function(){if((!this.message_refresh_interval)||(!this.filter_options.polling)||this.filter_options.polling==false)return;if(this.filter_options.older_than)return;if(this.poller){this.poller.stop();this.poller=null;}
this.poller=new PeriodicalExecuter(this.refresh_message_list.bind(this),this.message_refresh_interval);},stop_poller:function(){if(this.poller){this.poller.stop();this.poller=null;}},fetch_replies:function(thread_id){options={"asynchronous":false,"evalScripts":false,"method":"get","evalScripts":false,"evalJSON":false,"sanitizeJSON":false,"evalJS":false,"onException":this.handle_exception_response.bind(this),"onFailure":this.handle_error_response.bind(this)};options["onSuccess"]=function(request){timer.stop("fetch_replies");timer.start("parse_replies");var options=request.responseText.evalJSON(true);timer.stop("parse_replies");if(options){this.initialized=false;this.last_feed=new Workfeed.Feed(options);var messages=this.last_feed.messages;this.add_messages(messages,{hide_new_messages:false});if($('now_show_msgs_'+thread_id))$('now_show_msgs_'+thread_id).show();timer.report_totals();this.fetched_threads[thread_id]=true;this.initialized=true;}}.bind(this);timer.start("fetch_replies");var response=Workfeed.Ajax.ajax_js_request("/messages/in_thread/"+thread_id,options);},refresh_message_list:function(options){timer.start('fetch_messages');if(this.now_polling)return;if(Object.isUndefined(options))options={};this.now_polling=true;var filter_options=$H(this.filter_options);if(window.location.pathname.indexOf('/home')==0)filter_options=filter_options.merge({"cntrl":'home'});options["parameters"]=Object.toQueryString($H(filter_options));options["evalScripts"]=false;options["evalJSON"]=false;options["sanitizeJSON"]=false;options["evalJS"]=false;options["method"]="get";options["onSuccess"]=this.handle_response.bind(this);options["onException"]=this.handle_exception_response.bind(this);options["onFailure"]=this.handle_error_response.bind(this);options["on403"]=this.handle_redirect_response;options["on402"]=this.handle_redirect_response;options["on401"]=this.handle_redirect_response;var action=this.filter_options.search?'/search':'/messages';if(this.last_message_list_ajax_request){if(this.last_message_list_ajax_request.transport){try{this.last_message_list_ajax_request.transport.abort();}
catch(err){}}
this.last_message_list_ajax_request=null;}
this.last_message_list_ajax_request=Workfeed.Ajax.ajax_js_request(action,options);this.now_polling=false;this.track_page_view('/poll');},handle_redirect_response:function(response){location=response.getHeader("Location");},handle_error_response:function(response){this.track_page_view("/ajax_error");this.handle_infinite_spinner();console.log("ERROR in AJAX code:"+response.status+" msg:"+response.statusText);},handle_exception_response:function(response,exception){if(typeof(response.responseText)=="undefined"||response.responseText=='')return;this.handle_infinite_spinner(exception);console.log("EXCEPTION in AJAX responseTxt: "+response.responseText+" code:"+response.status+" msg:"+response.statusText+" exception:"+exception);for(m in exception){console.log(m+"="+eval("exception."+m));}},handle_response:function(request){timer.stop('fetch_messages');timer.start('handle_response');timer.start('handle_response_eval');var response=request.responseText.evalJSON(true);timer.stop('handle_response_eval');this.response=response;this.update(response);if(this.switching_feeds){this.addHistory();}
this.hide_spinner();this.initialized=true;this.switching_feeds=false;timer.stop('handle_response');timer.report_totals();timer.clear();},update_sidebar:function(sidebar_options){if(Object.isUndefined(sidebar_options))return;timer.start('update_sidebar');if(!Object.isUndefined(sidebar_options['group_invites_count'])||!Object.isUndefined(sidebar_options['group_requests_count'])){this.add_group_invitations(sidebar_options['group_invites_count'],sidebar_options['group_requests_count']);}
if(sidebar_options.stats){$H(sidebar_options.stats).keys().each(function(stat){if($(stat))$(stat).update(number_with_delimiter(sidebar_options.stats[stat]));})}
if(sidebar_options.device_settings)this.update_device_settings_sidebar(sidebar_options.device_settings);timer.stop('update_sidebar');},add_group_invitations:function(group_invitations_count,group_requests_count){if(!$('message_form_container'))return;if($('invite_notification')){var invites_div=$('invite_notification').update();}else{var invites_div=new Element('div',{'id':'invite_notification'}).hide();$('message_form_container').insert(invites_div);}
var invitation_msg='';var request_msg='';var combined_message='';var total_request_count=group_invitations_count+group_requests_count
if(total_request_count==0){if($('invite_notification').visible())Effect.Fade(invites_div,{delay:0,duration:0.3});}else{invites_div.insert(t('num_group_requests',{"count":total_request_count,'default':'You have #{total_request_count} group requests'})+".")
invites_div.insert("&nbsp; "+t('please_view')+"&nbsp;"+(total_request_count>1?t('them'):t('it'))+"&nbsp;"+t('on_the')+"&nbsp;").insert(new Element('a',{'href':'/group_invitations'}).insert(t('invitations_page'))).insert(".");if(!invites_div.visible()){Effect.Appear(invites_div,{delay:0,duration:0.3});}}
this.update_invite_count(group_invitations_count);},update_device_settings_sidebar:function(device_settings){if(Object.isUndefined(device_settings)||!$('device_notifications'))return;$('device_notifications').select('a').each(function(a){if(a.getAttribute('device_type')){var device_type=a.getAttribute('device_type');var device_type_verbose=(device_type=='mobile')?t('mobile_phone',{'default':"mobile phone"}):(device_type=='im')?t('instant_messenger',{'default':"instant messenger"}):'device';if(Object.isUndefined(device_settings[device_type])){a.setAttribute('class','off');a.setAttribute('title',t('click_here_to_stop',{'default':"Click here to stop sending and receiving updates via your "})+device_type_verbose);}else{if(device_settings[device_type]){a.setAttribute('class','on');a.setAttribute('title',t('click_here_to_stop',{'default':"Click here to stop sending and receiving updates via your "})+device_type_verbose);}else{a.setAttribute('class','off');a.setAttribute('title',t('click_here_to_start',{'default':"Click here to send and receive updates via your "})+device_type_verbose);}}}});},handle_infinite_spinner:function(e){if(e){console.log(e);log_javascript_error(e);}
if($('messages').visible()||!$('spinner').visible()||$('spinner_timeout').visible())return;this.stop_poller();$('spinner').hide();$('spinner_timeout').show();},show_spinner:function(){if(!$('spinner'))return;this.spinner_watcher=new PeriodicalExecuter(function(pe){pe.stop();if($("messages")&&$("messages").visible())return;this.handle_infinite_spinner();}.bind(this),10);$('spinner').show();$('spinner_timeout').hide();$('messages').hide();$('view_filter').hide();},hide_spinner:function(){if(!$('spinner'))return;$('messages').show();$('view_filter').show();if(this.spinner_watcher)this.spinner_watcher.stop();$('spinner_timeout').hide();$('spinner').hide();},remove_all_messages:function(){$$('#messages>li').invoke('remove');},set_ui_state:function(){this.set_selected_tab();this.show_feed();this.set_pagination_links_state();klass=this.filter_options.threaded?'threaded':'messages';mode_btn=$(klass+'_mode_btn');if(mode_btn){mode_btn.addClassName('selected');mode_btn.adjacent('a')[0].removeClassName('selected');mode_btn.up().className="toggle view_mode_"+klass;}},show_feed:function(){this.hide_ui_elements();this.show_everyone_explanation();if($('message_form_container'))$('message_form_container').show();if($('message_feed'))$('message_feed').show();},show_page:function(){this.hide_ui_elements();if(!$('content_page')){$('main_content').insert({top:new Element('div',{'id':'content_page'})});}else{$('content_page').update().show();}
var page_title=this.filter_options.feed_key.match(/^page_(.+)$/)[1].capitalize();$('content_page').insert('<h2>'+page_title+'</h2>');},hide_ui_elements:function(){$('message_feed','message_form_container','following_options','group_options','received_options','network_options','content_page','spinner_timeout','everyone_explanation').each(function(el){if(el)el.hide();})},set_pagination_links_state:function(){if($('older_link')){if(this.older_available){$('older_link').show();}else{$('older_link').hide();}}
if($('newer_link')){if(this.filter_options.older_than||(this.filter_options.search&&this.filter_options.page>1)){$('newer_link').show();}else{$('newer_link').hide();}}
if($('newer_link')&&$('newer_link').visible()&&$('older_link')&&$('older_link').visible()){if($('pagination_separator'))$('pagination_separator').show();}else{if($('pagination_separator'))$('pagination_separator').hide();}},paginate:function(direction){if(this.filter_options.search)return this.paginate_search(direction);var filter_options={};var prev_older_than=null;if(this.filter_options.prev_older_than){prev_older_than=this.filter_options.prev_older_than.split(":");}
if(direction=='newer'){if(prev_older_than){filter_options.older_than=prev_older_than.last();filter_options.prev_older_than=prev_older_than.slice(0,-2).join(':');}}else{if(this.filter_options.older_than){if(prev_older_than){filter_options.prev_older_than=this.filter_options.prev_older_than+':'+this.filter_options.older_than;}else{filter_options.prev_older_than=this.filter_options.older_than;}}
filter_options.older_than=this.older_than;}
if(filter_options.older_than){filter_options.polling=false;}else{filter_options.polling=true;}
this.switch_feed(filter_options);},paginate_search:function(direction){var filter_options=Object.clone(this.filter_options);if(direction=='newer'){if(filter_options.page<3){delete filter_options.page;}else{filter_options.page=parseInt(filter_options.page)-1;}}else{filter_options.page=parseInt(filter_options.page)+1;}
this.switch_feed(filter_options);},switch_modes:function(mode_btn,threaded){var filter_options={};if(threaded){filter_options.threaded=true;filter_options.set_threaded=true;this.track_page_view("/mode/threaded");}else{klass='messages';filter_options.threaded=false;filter_options.set_threaded=false;this.track_page_view("/mode/message");}
filter_options.polling=true;this.switch_feed(filter_options);},switch_tabs:function(tab){this.track_page_view("/home/"+tab);this.set_selected_tab(tab);this.switch_feed({polling:true,feed_key:home_tab_info[tab].feed_key});},set_selected_tab:function(tab){if(!home_tab_info)return;if(!tab){if($('home_tabs')&&this.filter_options.feed_key){var feed_key=this.filter_options.feed_key;var selected_tab=$H(home_tab_info).detect(function(pair){if(pair.value.feed_key==feed_key)return true;});if(selected_tab){tab=selected_tab[0];}}else{return;}}
if(home_tab_info[tab]){$$('#home_tabs a.selected,#home_tabs li.selected').invoke('removeClassName','selected');if($('message_form')&&$('message_form')["message_group_id"]){if(home_tab_info[tab]['feed_type']=='group'){$('message_form')["message_group_id"].value=home_tab_info[tab].group_id?home_tab_info[tab].group_id:'';var name=home_tab_info[tab].name;if($('message_form_label'))$('message_form_label').update(t("Share something with")+"&nbsp;"+home_tab_info[tab].select_name+":");}else{$('message_form')["message_group_id"].value="";this.build_group_menu();}}
if($("home_tab_"+tab))$("home_tab_"+tab).addClassName("selected");}else{this.switch_tabs('following');}
this.selected_tab=home_tab_info[tab];},build_group_menu:function(){if(!$('message_form_label'))return;var group_menu_items=[];var general_group=null;group_menu_items=group_menu_items.concat(groups.collect(function(g){return{name:g[0],callback:this.set_message_form_label.bind(this,g[2],g[0])}}.bind(this)).compact());group_menu_items.unshift({name:this.network_name,callback:this.set_message_form_label.bind(this)});group_menu_items.push({separator:true},{name:t('Add Group'),className:'add_group',callback:function(){window.location.href='/groups'}});if(!this.group_selector){this.group_selector_link=new Element('a',{'href':'javascript://','id':'group_selector'});this.group_selector=new YammerUI.Menu(this.group_selector_link,group_menu_items,{offsetY:2,panelId:'group_menu'});}
this.set_message_form_label();},set_message_form_label:function(group_perm,select_name){var group_id;if(group_perm){group=home_tab_info["Group:"+group_perm];group_id=group.group_id;}else{select_name=messagelist.network_name;group_id='';}
if(group_id!=''||$H(home_tab_info).detect(function(pair){if(pair.value['feed_type']=="group")return true;})){$('message_form_label').update(t('share_something_with')+' ').insert(this.group_selector_link.update(select_name)).insert(':');}else{$('message_form_label').update(t("what_are_you_working_on"));}
$('message_form')["message_group_id"].value=group_id?group_id:'';},goto_page_one:function(){this.switch_feed({});},show_everyone_explanation:function(){if($('everyone_explanation')&&home_tab_info&&home_tab_info["following"]){if(this.selected_tab['feed_type']=='following'){$('everyone_explanation').show();}else{$('everyone_explanation').hide();}}},switch_feed:function(filter_options){this.switching_feeds=true;this.initialized=false;this.update_title_with_unread_count(0);this.stop_poller();this.show_spinner();this.hide_new_message_notice();this.init_options();if($('notice'))$('notice').hide();if($('error'))$('error').hide();this.remove_all_messages();if(Object.isUndefined(filter_options.feed_key)&&this.filter_options.feed_key)filter_options.feed_key=this.filter_options.feed_key;if(Object.isUndefined(filter_options.polling)&&this.filter_options.polling)filter_options.polling=this.filter_options.polling;if(Object.isUndefined(filter_options.threaded)&&this.filter_options.threaded)filter_options.threaded=this.filter_options.threaded;this.filter_options=filter_options;this.set_ui_state();this.refresh_message_list();},switch_feed_retry:function(){this.switch_feed(this.filter_options);},submit_message_form:function(form){if(this.posting)return;this.track_page_view("/post");this.stop_poller();var message=trim($F(form.id+"_message_body"));if(message!=''){var button=$(form.id+"_form_submit").addClassName('btn-disabled');button.down('em').update(button.getAttribute("feedback_value"));var body=form.down(".message_body");var button=form.down('.form_submit').addClassName('btn-disabled');this.posting=true;var options={};options["evalScripts"]=false;options["parameters"]=Form.serialize(form)+'&'+Object.toQueryString(this.filter_options);options["onComplete"]=function(request){this.message_form_success($(form.identify()));this.handle_response(request);}.bind(this);form.select("input[name='message[pending_attachment_ids][]']").invoke('remove');Workfeed.Ajax.ajax_js_request("/messages",options);return false;}else{return false;}},message_form_success:function(form){if(this.filter_options.threaded&&(!$F("replied_to_id"))){}
var body=form.down("textarea.message_body");var height=body.getAttribute?body.getAttribute("default_height"):"";body.style.height=height;body.value='';var button=form.down('a.form_submit').removeClassName('btn-disabled');button.down('em').update(button.getAttribute("default_value"));RedBox.close();this.posting=false;$(form.id+'_attachments').update();},remove_message:function(message_id){var options={};options["method"]="delete";options["parameters"]=Workfeed.Ajax.authenticity_token_query_parameter_for_page();Workfeed.Ajax.ajax_js_request("/messages/"+message_id,options);var thread_id=null;if($('message_'+message_id)){if(this.filter_options["threaded"]&&$('message_'+message_id).up("ul.thread_replies")){thread_id=$('message_'+message_id).up("ul.thread_replies").getAttribute("thread_id");}
Effect.BlindUp($('message_'+message_id),{duration:.5});setTimeout("$('message_"+message_id+"').remove();messagelist.update_thread("+thread_id+")",500);}
return false;},message_div:function(message_id){return $('message_'+message_id);},email_message:function(message_id){var options={};options["parameters"]=Workfeed.Ajax.authenticity_token_query_parameter_for_page();Workfeed.Ajax.ajax_js_request("/messages/"+message_id+"/email",options);return false;},build_message:function(message,options){timer.start('build_message');if(Object.isUndefined(options))options={};timer.start('build_message 1');var li=new Element('li',{'id':'message_'+message.id,'message_id':message.id,'group_id':message.group_id}).hide();var message_div=new Element('div',{'class':'message nonsemantic'});var thumb_link=new Element('a',{'href':Workfeed.Utils.make_relative_url(message.sender.web_url),'class':'thumbnail','title':'@'+message.sender.name});var thumb=new Element('img',{'src':message.sender.mugshot_url,'alt':'@'+message.sender.name});var utilities=new Element('div',{'class':'utilities'});var details=new Element('div',{'class':'messagetime'})
var buttons=new Element('div',{'class':'buttons'});var email_btn=new Element('a',{'class':'email','href':'javascript://'});var email_btn_img=new Element('img',{'src':'/images/envelope.png','title':t('email me this message')});var reply_link=new Element('a',{'href':'javascript://','class':'reply'})
var client_type_label=message.client_type;var client_link=new Element('a',{'href':''+message.client_url,'style':"color:#002bb8"}).update(client_type_label);var time_ago=this.build_message_time(message);var content=this.build_message_body(message);timer.stop('build_message 1');timer.start('build_message 2');if(url_params["message_id"]&&url_params["message_id"]==message.id){li.addClassName("highlight");}else if(url_params["replied_to_id"]&&url_params["replied_to_id"]==message.id){li.addClassName("highlight_secondary");}
if(message.attachments&&message.attachments[0]){var attachment_count=message.attachments.length;var attachment_div=new Element('div',{'class':'msg_attachments'})
attachment_div.update(attachment_count+' attachment'+((attachment_count==1)?': ':'s: '));var attachment_img_div=new Element('div',{'class':'msg_img_attachments'}).hide();var attachment_link=null;message.attachments.reverse().each(function(attachment,i){if(attachment.type=='image'){attachment_img_div.show();var attachment_img=new Element('img',{'src':attachment.image.thumbnail});var attachment_img_link=new Element('a',{'href':attachment.web_url}).update(attachment_img);attachment_img_div.insert(attachment_img_link);}else{if(attachment_link){attachment_div.insert(', ')}
attachment_link=new Element('a',{'href':attachment.web_url}).update(attachment.name);attachment_div.insert(attachment_link);}})
attachment_div.insert(attachment_img_div);content.insert(attachment_div);}
details.insert(time_ago);var group_stamp;if(message.group==null){group_stamp=new Element('a',{'class':"group_stamp",'style':"color:#002bb8",'href':"/home/updates",'title':this.network_name}).update(this.network_name);}else{group_stamp=new Element('a',{'class':"group_stamp",'style':"color:#002bb8",'href':message.group.web_url,'title':message.group.full_name}).update(message.group.full_name);}
time_ago.insert("&nbsp;in&nbsp;");time_ago.insert(group_stamp);if(message.client_type&&message.client_type!='Web'){time_ago.insert("&nbsp;-&nbsp;from&nbsp;").insert(client_link);}
buttons.insert(email_btn.insert(email_btn_img));utilities.insert(details).insert(buttons);content.insert(utilities);timer.stop('build_message 2');timer.start('build_message 3');if(this.display_options["avatars"]){thumb_link.insert(thumb);message_div.insert(thumb_link);}else{message_div.addClassName("no_user_icon");}
message_div.insert(content);if(this.filter_options.threaded){var message_userlink=new Element('div',{'class':'message_userlink'}).hide();message_userlink.insert(this.build_user_link(message.sender));li.insert(message_userlink);}
li.insert(message_div);if((message.sender_id==this.current_user_id)||(this.current_user_admin)){var delete_btn=new Element('a',{'class':'delete','href':'javascript://'});var delete_btn_img=new Element('img',{'src':'/images/trashcan.png','title':t('delete this message')});buttons.insert(delete_btn.insert(delete_btn_img));}
if(!this.filter_options.threaded&&message.others_in_thread_cnt>0){var discuss_btn=new Element('a',{'class':'discussion','href':'/threads/'+message.thread_id+'?message_id='+message.id});var discuss_btn_img=new Element('img',{'src':'/images/discussion.png','title':'view thread'});buttons.insert(discuss_btn.insert(discuss_btn_img));}
var actions=new Element('div',{'class':'action small'});reply_link.update(t('reply'));timer.stop('build_message 3');if(this.filter_options.threaded){timer.start('build_message 4');if(message.thread_starter&&message.others_in_thread_cnt>0){timer.start('build_message 5');var thread_div=new Element('div',{'class':'threaded_messages'});var disclosure=new Element('span',{"id":'disclosure_'+message.id,"class":"disclosure closed"});var thread_arrow_link=new Element('a',{'class':'responses','href':'javascript://'});var thread_arraw_span=new Element('span',{"id":'thread_'+message.id+'_cnt'});var responders_span=new Element('span',{"id":'responders_list_'+message.id});if(message.references.messagethreads[message.thread_id]){var reply_time_txt='';if(message.references.messagethreads[message.thread_id].stats.latest_reply_at){var latest_reply_time=new Date(message.references.messagethreads[message.thread_id].stats.latest_reply_at);var reply_time_txt=this.format_message_time(latest_reply_time);if(message.others_in_thread_cnt>1)reply_time_txt=t("latest_reply_time",{"time":reply_time_txt});}
var latest_reply_time_em=new Element('em',{'class':'small quiet nobreak'}).update(reply_time_txt);responders_span.insert(latest_reply_time_em);}
var replies_ul=new Element('ul',{'id':'message_'+message.id+'_replies','class':'thread_replies','thread_id':message.thread_id}).hide();thread_arraw_span.update(t("num_replies",{count:message.others_in_thread_cnt}));if(message.others_in_thread_cnt>this.messages_per_page){var not_shown_span=new Element('div',{'id':'now_show_msgs_'+message.id,'class':'messages_not_shown'}).hide();var more_thread_link=new Element('a',{'class':'view_thread','href':'/threads/'+message.thread_id});more_thread_link.update("&nbsp;"+t("View entire thread"));not_shown_span.update(t("messages_not_shown",{"messages":message.others_in_thread_cnt-this.messages_per_page}));not_shown_span.insert(more_thread_link);replies_ul.insert(not_shown_span);}
disclosure.insert(thread_arrow_link.insert(thread_arraw_span));thread_div.insert(disclosure.insert('&nbsp;'));thread_div.insert(responders_span);thread_div.insert(replies_ul);content.insert(thread_div);utilities.insert(actions.insert(reply_link));timer.stop('build_message 5');}else if(!message.thread_starter){var reply_link_img=new Element('img',{'src':'/images/curved_arrow.png','title':'reply'});reply_link.addClassName('reply').update().insert(reply_link_img);buttons.insert(reply_link);}else{utilities.insert(actions.insert(reply_link));}
timer.stop('build_message 4');}else{utilities.insert(actions.insert(reply_link));}
if(!this.initialized||options.hide_new_messages==false){li.show();}
timer.stop('build_message');return li;},user_tooltip:function(user){if(!user)return'';if(this.display_options.full_names){return"@"+user.name;}else{return user.full_name;}},build_user_link:function(user){var sender=new Element('a',{'href':Workfeed.Utils.make_relative_url(user.web_url),'title':this.user_tooltip(user)});sender.update(this.user_name_or_full_name(user));return sender;},user_name_or_full_name:function(user){if(this.display_options["full_names"]&&user.full_name&&(user.full_name!='')){return user.full_name;}else{return user.name;}},build_message_body:function(message,body){if(Object.isUndefined(body))body=message.body.web;if(message.group&&message.group.privacy=='private'){var content=new Element('div',{'class':'content private','title':t('private message')});}else{var content=new Element('div',{'class':'content'});}
var byline=new Element('span',{'class':'byline'});if(message.group&&message.group.privacy=='private'){var lock=new Element('img',{'src':'/images/private_icn.gif','class':'ornament'});byline.insert(lock);}
byline.insert(this.build_user_link(message.sender));if(message.replied_to){var inreplytotile=message.replied_to.body.plain
if(message.replied_to.replied_to&&message.replied_to.replied_to.sender){inreplytotile=this.user_name_or_full_name(message.replied_to.sender)+"&nbsp;"+t("in reply to")+"&nbsp; "+this.user_name_or_full_name(message.replied_to.replied_to.sender)+": "+inreplytotile;}else if(message.replied_to.sender){inreplytotile=this.user_name_or_full_name(message.replied_to.sender)+": "+inreplytotile;}
var inreplyto=new Element('a',{'class':"in_reply_to",'href':message.thread_url}).update(t("in reply to"));var recipient=new Element('a',{'href':Workfeed.Utils.make_relative_url(message.replied_to.sender.web_url),'title':this.user_tooltip(message.replied_to.sender)});recipient.update(this.user_name_or_full_name(message.replied_to.sender));byline.insert('&nbsp;').insert(inreplyto).insert('&nbsp;').insert(recipient);this.build_in_reply_to_tip(inreplyto,inreplytotile)}
if(!message.system_message)byline.insert(":");byline.insert('&nbsp;');content.insert(byline).insert(body);return content;},build_in_reply_to_tip:function(link,text){new YammerUI.ToolTip(link,{content:text,offsetY:-7,offsetX:-20,panelClass:'in_reply_to_tip',hooks:["MOUSE","BL"],followMouse:true,showEffect:null,hideEffect:null})},build_message_time:function(message){return new Element('em',{'class':'small quiet nobreak'}).insert(new Element('a',{'href':Workfeed.Utils.make_relative_url(message.web_url),'class':'m_dtime','title':this.format_message_time_title(message.jstime),'etime':message.jstime}).update(this.format_message_time(message.jstime)));},update_message_counts:function(message_ids){if(message_ids&&message_ids.length>0){if(this.initialized&&(this.filter_options.threaded||this.blurred)){this.unread_message_ids=this.unread_message_ids.concat(message_ids);this.unread_message_ids=this.unread_message_ids.uniq();this.unread_message_count=this.unread_message_ids.length;if(this.blurred)this.update_title_with_unread_count(this.unread_message_count);}}},show_new_message_notice:function(){if($('new_threads_notice')&&this.unread_message_count>0){$('new_threads_notice').update(this.new_threads_notice.evaluate({new_message_notice:'<img src="/images/refresh.png" title="refresh this feed" />'+t('you_in_thread_view')+"&nbsp;"+t("thread_view_refresh",{"count":this.unread_message_count})}));if(!$('alert_wrapper').visible())
Effect.Appear($('alert_wrapper'),{delay:0,duration:0.3});}},hide_new_message_notice:function(){if($('alert_wrapper'))$('alert_wrapper').hide();},update_thread:function(thread_id){if(!thread_id)return;if($('message_'+thread_id)&&$('thread_'+thread_id+'_cnt')&&$('message_'+thread_id+'_replies')){var thread_cnt=$('message_'+thread_id+'_replies').select('li').length;if(thread_cnt<1){$('disclosure_'+thread_id).hide();}else{if($('thread_'+thread_id+'_cnt')){$('thread_'+thread_id+'_cnt').update(t("num_replies",{"count":thread_cnt}));}
if(!$('disclosure_'+thread_id).visible()){$('disclosure_'+thread_id).show();}}}},toggle_threaded_thread:function(message_id){if($('message_'+message_id+'_replies').visible()){$('message_'+message_id+'_replies').blindUp({duration:0.25});$('disclosure_'+message_id).removeClassName('open');$('disclosure_'+message_id).addClassName('closed');Effect.Appear($('responders_list_'+message_id),{delay:0,duration:0});$('responders_list_'+message_id).show();}else{$('disclosure_'+message_id).addClassName('open');$('disclosure_'+message_id).show();$('message_'+message_id+'_replies').hide();$('thread_'+message_id+'_cnt').style.fontWeight="";$('thread_'+message_id+'_cnt').style.backgroundColor="";$('responders_list_'+message_id).hide();$('disclosure_'+message_id).removeClassName('closed');$('message_'+message_id+'_replies').blindDown({duration:0.5});}
if(!this.fetched_threads[message_id]){this.fetch_replies(message_id);}},addObservers:function(){Event.observe(window,'blur',this.onBlur.bind(this));Event.observe(window,'focus',this.onFocus.bind(this));},onBlur:function(event){this.blurred=true;},onFocus:function(event){this.blurred=false;this.highlight_messages(this.unread_message_ids);if(!this.filter_options.threaded){this.unread_message_count=0;this.unread_message_ids=[];this.update_title_with_unread_count(0);}},prune_messages:function(){$$('#messages>li').slice(this.messages_per_page).invoke('remove');var last_message=$$('#messages>li').last();if(last_message)this.older_than=last_message.getAttribute('message_id');},highlight_messages:function(message_ids){message_ids.each(function(message_id){this.highlight_message(message_id,0);}.bind(this));},highlight_message:function(message_id,delay_val){if($('message_'+message_id)){$('message_'+message_id).morph('background-color:#FEF7C3',{delay:delay_val,duration:1});$('message_'+message_id).morph('background-color:#ffffff',{delay:delay_val+1});}},blind_messages:function(message_ids){delay_val=0;message_ids.reverse().each(function(message_id){if($('message_'+message_id)){Effect.Appear($('message_'+message_id),{delay:delay_val,duration:1});Effect.BlindDown($('message_'+message_id),{delay:delay_val,duration:1});this.highlight_message(message_id,delay_val);delay_val+=1;}}.bind(this));},show_updates_feed_type_options:function(link){link=$(link);var offset=link.positionedOffset();var optionsdiv=$('updates_feed_type_options');optionsdiv.setStyle({sleft:offset[0]+"px",top:"100%"});optionsdiv.toggle();if(!this.add_update_options_observer){Event.observe(document,"mousedown",function(event){var x=Event.pointerX(event);var y=Event.pointerY(event);if(!Position.within(optionsdiv,x,y)&&Event.element(event)!=link)optionsdiv.hide();});}},show_new_message_form:function(permalink){var ta=$('reply_form').down('textarea');setTimeout(function(){ta.focus();ta.value=permalink;},200);},format_message_time:function(time){if(parseInt(time)){time=new Date(parseInt(time));}
if(this.display_options["absolute_time"]){return format_time(time);}else{return this.time_ago_in_words(time,1);}},format_message_time_title:function(time){if(parseInt(time)){time=new Date(parseInt(time));}
if(this.display_options["absolute_time"]){return this.time_ago_in_words(time,1)+" ago";}else{return format_time(time);}},time_ago_in_words:function(from_time,include_seconds){return distance_of_time_in_words(from_time,this.curtime,include_seconds);},update_message_times:function(){timer.start('update_message_times');$$('#messages li a.m_dtime').each(function(mtime){time=mtime.getAttribute('etime');mtime.update(this.format_message_time(time));mtime.writeAttribute('title',this.format_message_time_title(time));}.bind(this))
timer.stop('update_message_times');},update_title_with_unread_count:function(count){if(count>0){var match=document.title.match(Workfeed.unread_message_regex);if(match){document.title=document.title.replace(Workfeed.unread_message_regex,"("+count+") ");}else{document.title="("+count+") "+document.title;}}else{document.title=document.title.replace(Workfeed.unread_message_regex,"");}},track_page_view:function(page){if(window.pageTracker)window.pageTracker._trackPageview(page);},upload_file:function(form){$(form).down('.input_container').addClassName('loading');var uploads=$(form).select("input[name='message[pending_attachment_ids][]']").length;if(this.get_upload_count(form)<this.max_uploads){$(form).submit();this.posting=true;}},add_uploaded_file:function(form_id,file_id,file_name,file_url){var file_container=new Element('li',{'id':'attach_link_'+file_id});var form_field=new Element('input',{'type':'hidden','id':'attachment_'+file_id,'name':'message[pending_attachment_ids][]','value':file_id})
var file_link=new Element('a',{'href':file_url}).update(file_name);var remove_img=new Element('img',{'src':'/images/x_grey.png'});var remove_link=new Element('a',{'href':'javascript://'}).insert(remove_img);remove_link.observe('click',this.remove_uploaded_file.bind(this,file_id,form_id))
$(form_id).insert(form_field);file_container.insert(file_link).insert(remove_link);$(form_id+'_attachments').insert(file_container).show();$(form_id+'_attachments_input_container').removeClassName('loading');this.posting=false;if(this.get_upload_count(form_id)>=this.max_uploads){$(form_id+'_attachments_input_container').hide();}},remove_uploaded_file:function(file_id,form_id){$('attach_link_'+file_id).remove();$('attachment_'+file_id).remove();var upload_count=this.get_upload_count(form_id);if(upload_count<this.max_uploads){$(form_id+'_attachments_input_container').show();}
if(upload_count==0){$(form_id+'_attachments').hide();}},get_upload_count:function(form_id){return $(form_id).select("input[name='message[pending_attachment_ids][]']").length;},last_method:function(){}});Workfeed.Feed=Class.create({initialize:function(feed){this.references=feed.references;this.messages=[];if(feed.references.groups){for(group_id in feed.references.groups){this.references.groups[group_id].name=this.references.groups[group_id].name.escapeHTML();this.references.groups[group_id].full_name=this.references.groups[group_id].full_name.escapeHTML();}}
if(feed.references&&feed.references.messages){for(message_id in feed.references.messages){this.references.messages[message_id]=new Workfeed.Message(feed.references.messages[message_id],feed.references);}}
if(feed.messages){for(i=0;i<feed.messages.size();i++){this.messages.push(new Workfeed.Message(feed.messages[i],feed.references));}}},last_method:function(){}});Workfeed.PlaceholderRegex=/\[\[([^\[\]]*?)\]\]/gm;Workfeed.LinkRegex=/((?:http(?:s?)\:\/\/|www\.[^\.])\S+[A-z0-9\/])/g;Workfeed.PlaceholderMarkers={"user":"@","tag":"#","group":"@"};Workfeed.Message=Class.create({initialize:function(options,references){Object.extend(this,options);try{this.sender=references[this.sender_type+"s"][this.sender_id];}catch(e){console.log("Couldn't find sender for mid:"+this.id+" sender_type:"+this.sender_type+" "+this.sender_id+" "+Object.toJSON(this)+e)
this.sender={}}
this.references=references;this.jstime=new Date(options.created_at).getTime();if(this.thread_id!=this.id||references.messagethreads[this.thread_id]){this.in_thread=true;}
if(this.in_thread){if(references.messages[this.replied_to_id]){this.replied_to=references.messages[this.replied_to_id];}
if(references.messagethreads[this.thread_id]){this.thread_url=Workfeed.Utils.make_relative_url(references.messagethreads[this.thread_id].web_url)+"?message_id="+this.id+"&replied_to_id="+this.replied_to_id;}}
if(this.id==this.thread_id)this.thread_starter=true;if(this.in_thread&&references.messagethreads[this.thread_id]){this.others_in_thread_cnt=references.messagethreads[this.thread_id].stats.updates-1;}
if(this.group_id){this.group=references.groups[this.group_id];}
this.body.plain=this.body.plain.escapeHTML();if(this.body.parsed){this.body.web=this.parse_body();}},parse_body:function(options){if(Object.isUndefined(options))options={};if(Object.isUndefined(options.maxlength))options.maxlength=400;if(Object.isUndefined(options.splitpoint))options.splitpoint=350;if(Object.isUndefined(options.truncate_links))options.truncate_links=true;if(Object.isUndefined(options.truncate_text))options.truncate_text=false;if(Object.isUndefined(options.split_text))options.split_text=true;body=this.body.parsed.escapeHTML();if(options.truncate_links){body=Workfeed.Utils.truncate_links(body);}else{body=Workfeed.Utils.linkify_links(body);}
body=body.replace(Workfeed.PlaceholderRegex,this.lookup_token.bind(this));if(options.truncate_text)body=Workfeed.Utils.truncate_text(body,options.maxlength);if(options.split_text)body=Workfeed.Utils.split_text(body,options.maxlength,options.splitpoint,this.id);return body},lookup_token:function(str,token){var token_parts=token.split(":");try{var reference=this.references[token_parts[0]+"s"][token_parts[1]];}catch(e){console.log("Couldn't find references "+str+" "+token);}
if(reference){var display_name=reference.name;var hover_name=reference.full_name;if(reference.stats&&reference.stats.updates){if(reference.stats.updates=="1"){hover_name=reference.stats.updates+" message";}else{hover_name=reference.stats.updates+" messages";}}
return Workfeed.PlaceholderMarkers[token_parts[0]]+'<a href="'+Workfeed.Utils.make_relative_url(reference.web_url)+'" title="'+hover_name+'">'+display_name+'</a>';}else{return"n/a";}},last_method:function(){}});Workfeed.Utils={make_relative_url:function(url){if((url.indexOf('/')==0)||(url.indexOf('/')==1))return url;relative_url=url.substr(8);return relative_url.substr(relative_url.indexOf('/'));},truncate_links:function(text){return text.replace(Workfeed.LinkRegex,Workfeed.Utils.truncate_link);},linkify_links:function(text){return text.replace(Workfeed.LinkRegex,Workfeed.Utils.linkify_link);},truncate_link:function(word){if(!/http(?:s?)\:\/\//.test(word)){link="http://"+word;}else{link=word;}
var after_html='';var after_html_ary=word.match(/([^\w|\/]+$)/);if(after_html_ary)after_html=after_html_ary[0];word=word.replace(/([^\w|\/]+$)/,'');(word.length>27)?(ellipsis="..."):(ellipsis="")
return Workfeed.Utils.linkify_link(word.substr(0,27)+ellipsis,link)+after_html;},linkify_link:function(word,link){if(Object.isUndefined(link))link=word
if(!/http(?:s?)\:\/\//.test(link)){link="http://"+link;}
var after_html='';var after_html_ary=word.match(/([^\w|\/]+$)/);if(after_html_ary)after_html=after_html_ary[0];word=word.replace(/([^\w|\/]+$)/,'');return"<a href=\""+link+"\" title=\""+link+"\" target=\"_blank\">"+word.substr(0,27)+"</a>"+after_html;},truncate_text:function(text,length){sp=Workfeed.Utils.determine_splitpoint(text,length);splitpoint=sp.splitpoint;textbits=sp.textbits;htmlbits=sp.htmlbits;if(splitpoint==0)return text;text=Workfeed.Utils.reinsert_html(textbits.join(' ').substr(0,splitpoint),htmlbits);return text+"...";},split_text:function(text,minlength,splitpoint,body_id){sp=Workfeed.Utils.determine_splitpoint(text,splitpoint,minlength);splitpoint=sp.splitpoint;textbits=sp.textbits;htmlbits=sp.htmlbits;if(splitpoint==0)return text;text=textbits.join(' ');presplit=text.substr(0,splitpoint);therest=text.substr(splitpoint,text.length).replace(/^\s+/,'');offset=presplit.split(' ').length;presplit=Workfeed.Utils.reinsert_html(presplit,htmlbits);therest=Workfeed.Utils.reinsert_html(therest,htmlbits,offset);return presplit+" <a onclick=\"showFullBody('"+body_id+"'); return false;\" href=\"#\"><span id=\"ellipsis_"+body_id+"\" class='small nobreak'>more &raquo;</span></a><span id=\"split_"+body_id+"\" style=\"display: none;\">"+therest+"&nbsp;<a onclick=\"hideFullBody('"+body_id+"'); return false;\" href=\"#\"><span class='small nobreak'>&laquo; less</span></a></span>";},reinsert_html:function(text,htmlbits,offset){if(Object.isUndefined(offset))offset=0;textbits=text.split(' ');textbits.each(function(e,i){if(htmlbits[i+offset])textbits[i]=htmlbits[i+offset];});return textbits.join(' ');},determine_splitpoint:function(text,splitpoint,minlength){if(Object.isUndefined(minlength))minlength=splitpoint;textbits=new Array();links=new Array();htmlbits=new Array();thisword="";in_link=false;for(var i=0;i<text.length;i++){thischar=text.charAt(i);if((thischar=="<")&&(text.substr(i,7)=="<a href")){in_link=true;}
if((thischar==" ")&&(in_link==false)){if(thisword!=""){textbits.push(thisword);thisword="";}}else{if((in_link)&&(thischar==">")&&(text.substr(i-3,4)=="</a>")){thisword+=thischar;textbits.push(thisword);thisword="";links.push(textbits.length-1);in_link=false;}else{thisword+=thischar;if(in_link)links.push(textbits.length-1);}}}
if(thisword!="")textbits.push(thisword);textbits.each(function(e,i){if(links.include(i)){htmlbits[i]=e;thematch=e.match(/<[^>]+>([^<]+)/);if(thematch!=null)textbits[i]=thematch[1];}});plaintext=textbits.join(' ')
if(plaintext.length<minlength)return{splitpoint:0,textbits:textbits,htmlbits:htmlbits};for(splitpoint-=1;(plaintext.charAt(splitpoint)!=' ')&&(splitpoint>=0);splitpoint--){}
return{splitpoint:splitpoint,textbits:textbits,htmlbits:htmlbits};},last_method:function(){}};var TextAreaResizer=Class.create();TextAreaResizer.prototype={initialize:function(textarea,handle,options){this.textarea=$(textarea);this.handle=$(handle);this.ogHeight=0;this.ogStartPos=0;this.options=options||{};this.minHeight=this.options.minHeight||15;this.registerEvents();},registerEvents:function(){Event.observe(this.handle,'mousedown',this.dragStart.bind(this));},dragStart:function(evt){this.ogHeight=this.textarea.getHeight();this.ogStartPos=Event.pointerY(evt);this.dragMove=this.dragMove.bind(this);this.dragStop=this.dragStop.bind(this);Event.observe(document,'mousemove',this.dragMove)
Event.observe(document,'mouseup',this.dragStop)},dragMove:function(evt){var newHeight=this.ogHeight+Event.pointerY(evt)-this.ogStartPos;if(newHeight>this.minHeight){this.textarea.setStyle({height:newHeight+"px"})}
this.clearSelection();},dragStop:function(evt){Event.stopObserving(document,'mousemove',this.dragMove)
Event.stopObserving(document,'mouseup',this.dragStop)},clearSelection:function(){var sel;if(document.selection&&document.selection.empty){document.selection.empty();}else if(window.getSelection){sel=window.getSelection();if(sel&&sel.removeAllRanges)sel.removeAllRanges();}}}
