/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  July 21st 2009 9:47:54 AM PDT                                */
/*      Machine:  10.16.139.109                                                */
/*       Source:  Global Cache                                                 */
/*     Location:  js/2qv4z8ey5yskcw4k.pkg.js h:eexojitc                        */
/*       Locale:  en_US                                                        */
/*         Path:  js/2qv4z8ey5yskcw4k.pkg.js                                   */

Arbiter.inform("template\/registerTemplate", {"name":"\/templates\/UIPager.tmpl","template":"\n<span class=\"UIPager\" bindPoint =\"root\">\n  <span class=\"UIPager_PageNum\" bindPoint=\"pageNumber\"><\/span>\n  <span class=\"UIPager_ButtonWrapper\" bindPoint=\"backWrapper\">\n    <a class=\"UIPager_Button UIPager_ButtonBack\" bindPoint=\"backRoot\" href=\"#\"><\/a>\n  <\/span>\n  <span class=\"UIPager_ButtonWrapper\" bindPoint=\"forwardWrapper\">\n    <a class=\"UIPager_Button UIPager_ButtonForward\" bindPoint=\"forwardRoot\" href=\"#\"><\/a>\n  <\/span>\n<\/span>\n"}, Arbiter.BEHAVIOR_PERSISTENT);

function UIPager(total,maxPerPage,offset,callback){copy_properties(this,{_rm:new RenderManager(this),_callback:callback||bagofholding,_backHandler:null,_forwardHandler:null,_maxPerPage:maxPerPage,_total:total,_offset:offset,_isDisabled:false,root:null,backRoot:null,forwardRoot:null,pageNumber:null,backWrapper:null,fowardWrapper:null});this.parent.construct(this,URI('/templates/UIPager.tmpl'));this._summaryTextHandler=this._getSummaryText.bind(this);this._setupHandlers();return this;}
UIPager.extend('TemplateObject');UIPager.prototype._setupHandlers=function(){this._backHandler=Event.listen(this.backRoot,'click',this._handleClick.bind(this,'back'));this._forwardHandler=Event.listen(this.forwardRoot,'click',this._handleClick.bind(this,'forward'));}
UIPager.prototype._handleClick=function(direction){var wrapper;var dir;if(direction=='forward'){wrapper=this.forwardWrapper;dir=1;}else{wrapper=this.backWrapper;dir=-1;}
if(!CSS.hasClass(wrapper,'UIPager_ButtonDisabled')){this._offset=this._offset+(dir*this._maxPerPage);this._callback(this._offset,dir);this._rm.dirty();}
return false;}
UIPager.prototype._getSummaryText=function(offset,total,per_page){return _tx("{current} of {total}",{'current':this._getCurrentPage(),'total':this._getPageCount()});}
UIPager.prototype.setMaxPerPage=function(maxPerPage){this._maxPerPage=Math.max(maxPerPage,0);this._rm.dirty();return this;}
UIPager.prototype.setTotal=function(total){this._total=Math.max(total,0);this._rm.dirty();return this;}
UIPager.prototype.setOffset=function(offset){this._offset=Math.max(offset,0);this._rm.dirty();return this;}
UIPager.prototype.setPage=function(page){this._offset=Math.max(page-1,0)*this._maxPerPage;this._rm.dirty();return this;}
UIPager.prototype.setDisabled=function(disabled){this._isDisabled=disabled;this._rm.dirty();return this;}
UIPager.prototype._getCurrentPage=function(){return this._offset/this._maxPerPage+1;}
UIPager.prototype._getPageCount=function(){return Math.ceil(this._total/this._maxPerPage);}
UIPager.prototype.setSummaryTextHandler=function(fn){this._summaryTextHandler=fn;this._rm.dirty();return this;}
UIPager.prototype._setDisabled=function(button,disabled){var buttonWrapper;if(button=="back"){buttonWrapper=this.backWrapper;}else if(button=="forward"){buttonWrapper=this.forwardWrapper;}
CSS.conditionClass(buttonWrapper,'UIPager_ButtonDisabled',disabled);return this;}
UIPager.prototype.paint=function(){if(this._offset==0||this._isDisabled){this._setDisabled("back",true);}else{this._setDisabled("back",false);}
if((this._offset+this._maxPerPage)>=this._total||this._isDisabled){this._setDisabled("forward",true);}else{this._setDisabled("forward",false);}
DOM.setContent(this.pageNumber,this._summaryTextHandler(this._offset,this._total,this._maxPerPage));}
UIPager.prototype.resetPager=function(total,maxPerPage,offset,callback){this.setOffset(offset);this.setTotal(total);this.setMaxPerPage(maxPerPage);if(callback){this._callback=callback;}
this._rm.dirty();}
UIPager.prototype.getRoot=function(){return this.root;}
UIPager.prototype.setHidden=function(hidden){CSS.conditionClass(this.root,'hidden_elem',hidden);return this;}
UIPager.prototype.getHidden=function(){return CSS.hasClass(this.root,'hidden_elem');}

function FriendsPage(main_nav,list_nav,toolbar_top,toolbar_bottom,pagelet,friend_selector_param,filter_keys){this._cache={};this._friendCache={};this._listDownloadComplete=false;this._phonebookDownloadComplete=false;this._RecentlyUpdatedDownloadComplete=false;this._currentView=null;this._pagelet=pagelet;this._currentNetworkFilter=false;this._filterKeys=filter_keys;this._filterKeys.default_view=filter_keys.all_connections;this._mainNav=main_nav;this._listNav=list_nav;this._listNav.setCreateLinkHandler(this._showMFS.bind(this,true));this._networkFiltersTypeMap={};this._networkFilters={};this._friendContainer=$('FriendsPage_Container');this._itemsPerPage=50;this._searchResultsPerPage=25;this._offsetMap={};if(this._getNavSelectedItem()){var data=this._getNavSelectedItem().data;var query=URI().getQueryData();if(query.filter_network){data.filter_network=query.filter_network;}}else{var data={filter:this._filterKeys.find_friends};var query=data;}
if(!query.offset){query.offset=0;}
data.offset=query.offset;PageTransitions.registerHandler(this._pageTransitionHandler.bind(this));var pager_function=function(offset){var uri=URI.getRequestURI();var data={filter:this._currentView,offset:offset};if(this._currentNetworkFilter!==false){data.filter_network=this._currentNetworkFilter;}
uri.setQueryData(data);uri.go();}.bind(this);this._pagerTop=new UIPager(0,this._itemsPerPage,data.offset,pager_function);this._pagerBottom=new UIPager(0,this._itemsPerPage,data.offset,pager_function);this._pagerTop.setSummaryTextHandler(this._getPagerSummaryText.bind(this));this._pagerBottom.setSummaryTextHandler(this._getPagerSummaryText.bind(this));this._toolbarTop=toolbar_top;this._toolbarBottom=toolbar_bottom;this._createListButton=new UIActionButton(_tx("Create New List"));this._createListButton.setOnclick(this._createListButtonClick.bind(this));this._toolbarTop.addButton(this._createListButton,'left');this._editListButton=new UIActionButton(_tx("Edit List"));this._editListButton.setOnclick(this._editListButtonClick.bind(this));this._toolbarTop.addButton(this._editListButton,'left');this._toolbarTop.addContent(this._pagerTop.getRoot(),'right');this._toolbarBottom.addContent(this._pagerBottom.getRoot(),'right');this._deleteListButton=new UIActionButton(_tx("Delete List"));this._deleteListButton.setOnclick(this._deleteListButtonClick.bind(this));this._toolbarTop.addButton(this._deleteListButton,'left');this._searchInput=$('FriendsPage_Search');this._statusContainer=$('FriendsPage_StatusContainer');this._statusMessage=this._statusContainer.find('h2.FriendsPage_SimpleStatus');this._setNavLoading(true);Arbiter.subscribe(FriendsPage.ARBITER_NETWORK_FILTERS_DONE,this._setShowNetworkFilters.bind(this,true));TemplateRegistry.registerServerSideTemplate('/templates/UIObjectListing.tmpl',null,true,false);new AsyncRequest().setMethod('GET').setReadOnly(true).setURI('/ajax/typeahead_search.php?'+friend_selector_param).setErrorHandler(function(){}).setTransportErrorHandler(function(){}).setHandler(function(data,response){this._setNavLoading(false);this._typeaheadFriends=[];var friends=response.payload.entries;var valid_types={};valid_types[search_friend_source.TYPES.USER]=1;valid_types[search_friend_source.TYPES.PAGE]=1;valid_types[search_friend_source.TYPES.CONNECTION]=1;for(var i=0;i<friends.length;i++){if(!valid_types[friends[i].ty]){continue;}
this._typeaheadFriends.push(friends[i]);var friend={title:friends[i].t,type:friends[i].ty,subtitle:friends[i].n,id:friends[i].i,pic:friends[i].it,pending:friends[i].pnd,href:'/profile.php?id='+friends[i].i};this._friendCache[friend.id]=friend;}
this._cache[this._filterKeys.default_view]={};this._cache[this._filterKeys.default_view].members=[];this._cache[this._filterKeys.default_view].filter=this._filterKeys.default_view;this._cache[this._filterKeys.default_view].type=this._filterKeys.default_view;for(var k in this._friendCache){this._cache[this._filterKeys.default_view].members.push(this._friendCache[k].id);}
this._setupSearch();var item=this._getNavItem(data.filter);if(!(item.data&&item.data.is_pagelet)){this._getFriends(data,false);}}.bind(this,data)).disableNectar().send();this._getFriendLists();Arbiter.subscribe(Arbiter.LIST_EDITOR_LISTS_CHANGED,this._listEditorSave.bind(this),Arbiter.SUBSCRIBE_NEW);}
copy_properties(FriendsPage,{ARBITER_NETWORK_FILTERS_DONE:'FriendsPage/network_filters_done'});FriendsPage.prototype._pageTransitionHandler=function(uri){if(uri.getPath()=='/friends/index.php'||uri.getPath()=='/friends/'||uri.getPath()=='/people/'||uri.getPath()=='/people/index.php'||uri.getPath()=='/friends/new/'||uri.getPath()=='/friends/new/index.php'){var data=uri.getQueryData();if(!data.offset){data.offset=0;}
this._selectNavItem(data.filter);this._getFriends(data,true);return true;}
return false;}
FriendsPage.prototype._getNavItem=function(cache_key){var items=this._mainNav.getItems().concat(this._listNav.getItems());for(var i=0;i<items.length;i++){if(items[i].data&&cache_key==items[i].data.filter){return items[i];}}
return false;}
FriendsPage.prototype._selectNavItem=function(cache_key){var item=this._getNavItem(cache_key);if(item){if(this._mainNav.getItems().contains(item)){this._mainNav.selectItem(item);this._listNav.deselectAll();}else if(this._listNav.getItems().contains(item)){this._listNav.selectItem(item);this._mainNav.deselectAll();}}}
FriendsPage.prototype._getNavSelectedItem=function(){return this._mainNav.getSelectedItem()||this._listNav.getSelectedItem();}
FriendsPage.prototype._setNavLoading=function(loading){this._mainNav.setLoading(loading);this._listNav.setLoading(loading);}
FriendsPage.prototype._getFriendLists=function(){if(this._listDownloadComplete){return;}
var async=new AsyncRequest().setURI('/friends/ajax/superfriends.php').setReadOnly(true).setOption('retries',0).setMethod('GET').setData({all_lists:true}).setHandler(this._getFriendListsHandler.bind(this)).setFinallyHandler(bagofholding).send();}
FriendsPage.prototype._getFriendListsHandler=function(response){var collections=response.payload.collections;for(var i=0;i<collections.length;i++){var cache_key=collections[i].filter;this._cache[cache_key]=collections[i];}
this._listDownloadComplete=true;this._updateAllFriendListings();}
FriendsPage.prototype._getNetworkFilters=function(){if(this._networkFiltersDownloadComplete||this._networkFiltersLoading){return;}
this._networkFiltersLoading=true;var async=new AsyncRequest().setURI('/friends/ajax/superfriends_filters.php').setReadOnly(true).setOption('retries',0).setMethod('GET').setHandler(this._getNetworkFiltersHandler.bind(this)).send();}
FriendsPage.prototype._getNetworkFiltersHandler=function(response){var payload=response.payload;this._networkNames=payload.network_names;this._networkFilters=payload.networks;this._networkTypes=payload.network_types;for(var k in this._networkFilters){for(var nk in this._networkFilters[k]){this._networkFiltersTypeMap[nk]=k;}}
this._networkFiltersLoading=false;this._networkFiltersDownloadComplete=true;Arbiter.inform(FriendsPage.ARBITER_NETWORK_FILTERS_DONE,{});}
FriendsPage.prototype._setShowNetworkFilters=function(show_network_filters){if(!show_network_filters){this._toolbarTop.setShowSecondaryContent(false);return;}
if((this._currentView!=this._filterKeys.browse)||!this._networkFiltersDownloadComplete){return;}
if(!this._toolbarFilters){if(hasArrayNature(this._networkFilters)&&this._networkFilters.length==0){return;}
this._toolbarFilters=$N('div',{className:'FriendsPage_ToolbarFilters'});var label=$N('span',{className:'FriendsPage_ToolbarFiltersLabel'});label.setContent(_tx("Browse by:"));this._toolbarFilters.appendContent(label);this._primaryNetworkFilterSelect=$N('select',{className:'FriendsPage_ToolbarFiltersPrimarySelect'});this._primaryNetworkFilterSelect.listen('change',function(e){this._setNetworkFilters(get_form_select_value(this._primaryNetworkFilterSelect),false,true);}.bind(this));this._primaryNetworkFilterSelect.options[0]=new Option(_tx("Choose an option..."),'');var i=1;for(var k in this._networkTypes){this._primaryNetworkFilterSelect.options[i]=new Option(this._networkTypes[k],k);i++;}
this._secondaryNetworkFilterSelect=$N('select');this._secondaryNetworkFilterSelect.addClass('hidden_elem');this._secondaryNetworkFilterSelect.listen('change',function(e){this._setNetworkFilters(get_form_select_value(this._primaryNetworkFilterSelect),get_form_select_value(this._secondaryNetworkFilterSelect),true);}.bind(this));this._toolbarFilters.appendContent(this._primaryNetworkFilterSelect);this._toolbarFilters.appendContent(this._secondaryNetworkFilterSelect);this._toolbarTop.addSecondaryContent(this._toolbarFilters);}
this._toolbarTop.setShowSecondaryContent(true);}
FriendsPage.prototype._setNetworkFilters=function(primary_value,secondary_value,redirect){if(!this._toolbarFilters){return;}
if(primary_value===false){this._primaryNetworkFilterSelect.selectedIndex=0;this._secondaryNetworkFilterSelect.addClass('hidden_elem');}else{this._secondaryNetworkFilterSelect.removeClass('hidden_elem');set_form_select_value(this._primaryNetworkFilterSelect,primary_value);this._secondaryNetworkFilterSelect.options.length=0;this._secondaryNetworkFilterSelect.options[0]=new Option(_tx("Choose an option..."),'');var i=1;for(var k in this._networkFilters[primary_value]){this._secondaryNetworkFilterSelect.options[i]=new Option(this._networkNames[k],k);i++;}
if(secondary_value===false){this._secondaryNetworkFilterSelect.selectedIndex=0;}else{set_form_select_value(this._secondaryNetworkFilterSelect,secondary_value);if(redirect){var uri=URI.getRequestURI();uri.setQueryData({filter:this._filterKeys.browse,filter_network:secondary_value,offset:0});uri.go();}}}}
FriendsPage.prototype._getPhonebook=function(){if(this._phonebookDownloadComplete||this._phonebookLoading){return;}
this._phonebookLoading=true;this._setNavLoading(true);var async=new AsyncRequest().setURI('/friends/ajax/superfriends_phonebook.php').setReadOnly(true).setOption('retries',0).setMethod('GET').setHandler(this._getPhonebookHandler.bind(this)).send();}
FriendsPage.prototype._getPhonebookHandler=function(response){this._phonebookLoading=false;this._phonebookDownloadComplete=true;var payload=response.payload;var members=keys(payload.phone);this._cache[this._filterKeys.phonebook]={members:members,key:this._filterKeys.phonebook,filter:this._filterKeys.phonebook};this._phonebook=payload.phone;}
FriendsPage.prototype._getRecentlyUpdated=function(){if(this._recentlyUpdatedDownloadComplete||this._recentlyUpdatedLoading){return;}
this._recentlyUpdatedLoading=true;this._setNavLoading(true);var async=new AsyncRequest().setURI('/friends/ajax/superfriends_recently_updated.php').setReadOnly(true).setOption('retries',0).setMethod('GET').setHandler(this._getRecentlyUpdatedHandler.bind(this)).send();}
FriendsPage.prototype._getRecentlyUpdatedHandler=function(response){this._recentlyUpdatedDownloadComplete=true;this._recentlyUpdatedLoading=false;this._cache[this._filterKeys.recently_updated]={members:response.payload.members,key:this._filterKeys.recently_updated,filter:this._filterKeys.recently_updated};this._recentlyUpdated=response.payload.recently_updated;}
FriendsPage.prototype._getFriendListsSorted=function(){var editable_lists=[];for(var k in this._cache){if(this._cache[k].editable){editable_lists.push(this._cache[k]);}}
return editable_lists.sort(function(a,b){return(a.name==b.name)?0:(a.name<b.name?-1:1);});}
FriendsPage.prototype._getListsForFriend=function(uid){var lists_for_friend={};var lists=this._getFriendListsSorted();for(var i=0;i<lists.length;i++){for(var ii=0;ii<lists[i].members.length;ii++){if(lists[i].members[ii]==uid){lists_for_friend[lists[i].filter]=true;ii=lists[i].members.length;}}}
return lists_for_friend;}
FriendsPage.prototype._setupSearch=function(){this._searchSource=new static_source();this._searchSource.values=this._typeaheadFriends;this._searchSource.build_index();this._searchInput.listen('keyup',function(e){this._selectNavItem(this._filterKeys.default_view);this._currentView=this._filterKeys.default_view;this._nextView=this._currentView;if(!this._searchInput.value||this._searchInput.value.length==0){this._paintFriends(this._cache[this._filterKeys.default_view],false,0);return;}
var results=this._searchSource.search_value(this._searchInput.value);var new_results=[];for(var i=0;i<results.length;i++){new_results.push(results[i].i);}
var data={members:new_results,editable:false,search:true};this._paintFriends(data,false,0,this._searchInput.value);}.bind(this));}
FriendsPage.prototype._editFriendsAsync=function(uids,list,action,name){var postData={members:uids,list_id:list,action:action,name:name};new AsyncRequest().setURI('/friends/ajax/superfriends_add.php').setData(postData).send();}
FriendsPage.prototype._addFriend=function(uids,list_filter_value){var to_add=[];for(var i=0;i<uids.length;i++){var dupe_friend=this._existsInList(uids[i],list_filter_value);if(this._friendCache[uids[i]]&&!dupe_friend){this._cache[list_filter_value].members.push(uids[i]);this._updateFriendListing(uids[i]);to_add.push(uids[i]);}}
if(to_add.length>0){this._editFriendsAsync(to_add,this._cache[list_filter_value].value,'add');}}
FriendsPage.prototype._removeFriend=function(uid,list_filter_value){if(this._existsInList(uid,list_filter_value)){this._editFriendsAsync([uid],this._cache[list_filter_value].value,'remove');var list=this._cache[list_filter_value];for(var i=0;i<list.members.length;i++){if(list.members[i]==uid){list.members.splice(i,1);break;}}
if(this._displayedObjectsMap[uid]&&this._currentView==list_filter_value){this._displayedObjectsMap[uid].getActionControl().hideMenu();DOM.remove(this._displayedObjectsMap[uid].root);for(var i=0;i<this._displayedObjects.length;i++){if(this._displayedObjects[i].root===this._displayedObjectsMap[uid].root){this._displayedObjects.splice(i,1);break;}}
delete this._displayedObjectsMap[uid];var query=URI().getQueryData();var offset=query.offset?query.offset:0;var pager_total=this._cache[list_filter_value].members.length;this._pagerTop.resetPager(pager_total,this._itemsPerPage,offset);this._pagerBottom.resetPager(pager_total,this._itemsPerPage,offset);}else{this._updateFriendListing(uid);}}}
FriendsPage.prototype._existsInList=function(uid,list_filter_value){var exists=false;var list=this._cache[list_filter_value].members;for(var i=0;i<list.length;i++){if(list[i]==uid){exists=true;break;}}
return exists;}
FriendsPage.prototype._pageletHandler=function(transition){$('FriendsPage_ListingViewContainer').addClass('hidden_elem');$('FriendsPage_PageletContainer').removeClass('hidden_elem');this._setNavLoading(false);if(transition){PageTransitions.transitionComplete();}}
FriendsPage.prototype._getFriends=function(data,transition){var cache_key=data.filter;this._hideStatusMessage();var nav_item=this._getNavItem(cache_key);if(nav_item.data.is_pagelet){this._setNavLoading(true);this._pagelet.setHandler(this._pageletHandler.bind(this,transition));this._pagelet.go(nav_item.data.pagelet_path);return;}
if(cache_key==this._filterKeys.browse){this._getNetworkFilters();}
if(cache_key==this._filterKeys.phonebook){this._getPhonebook();}
if(cache_key==this._filterKeys.recently_updated){this._getRecentlyUpdated();}
if(this._cache[cache_key]&&!data.filter_network){this._currentView=cache_key;this._currentNetworkFilter=false;this._nextView=cache_key;this._setNavLoading(false);this._paintFriends(this._cache[cache_key],transition,data.offset);}else if(cache_key==this._filterKeys.browse){if(!this._networkFiltersDownloadComplete){this._setNavLoading(true);setTimeout(this._getFriends.bind(this,data,transition),100);return;}
this._setNavLoading(false);this._currentView=cache_key;this._nextView=cache_key;if(data.filter_network){this._currentNetworkFilter=data.filter_network;var network_type=this._networkFiltersTypeMap[data.filter_network];data.members=this._networkFilters[network_type][data.filter_network];}else{data.members=[];this._setNetworkFilters(false,false);}
this._paintFriends(data,transition,data.offset);}else{this._nextView=cache_key;if((!this._listDownloadComplete&&data.type==this._filterKeys.list)||(!this._phonebookDownloadComplete&&cache_key==this._filterKeys.phonebook)||(!this._recentlyUpdatedDownloadComplete&&cache_key==this._filterKeys.recently_updated)){setTimeout(this._getFriends.bind(this,data,transition),100);return;}
this._setNavLoading(true);var async=new AsyncRequest().setURI('/friends/ajax/superfriends.php').setReadOnly(true).setOption('retries',0).setMethod('GET').setData(data).setHandler(this._getFriendsHandler.bind(this,transition,data.offset)).setErrorHandler(bagofholding).setTransportErrorHandler(bagofholding).setFinallyHandler(bagofholding).send();}}
FriendsPage.prototype._getFriendsHandler=function(transition,offset,response){this._setNavLoading(false);var payload=response.payload;var collections=payload.collections;for(var i=0;i<collections.length;i++){var cache_key=collections[i].filter;this._cache[cache_key]=collections[i];for(var id in collections[i].member_data){this._friendCache[id]=collections[i].member_data[id];}}
if(payload.current_view){if(this._nextView==payload.current_view){this._currentView=payload.current_view;this._currentNetworkFilter=false;this._paintFriends(this._cache[payload.current_view],transition,offset);}else{}}}
FriendsPage.prototype._paintFriends=function(payload,transition,offset,highlight){var max=highlight?this._searchResultsPerPage:this._itemsPerPage;offset=parseInt(offset);if(payload.paginated&&!payload.start){var last=max+offset;if(last>payload.count){last=payload.count;}
if(last>payload.members.length){var value={'start':this._offsetMap[offset]||offset,'limit':max};this._setNavLoading(true);new AsyncRequest().setMethod('GET').setReadOnly(true).setURI('/friends/ajax/superfriends.php').setData({'filter':payload.filter,'value':value}).setHandler(function(response){var collection=response.payload.collections.pop();if(collection.last_used){this._offsetMap[offset+max]=collection.last_used+1;}
for(var id in collection.member_data){this._friendCache[id]=collection.member_data[id];}
this._paintFriends(collection,transition,offset,highlight);this._setNavLoading(false);}.bind(this)).send();return;}}
$('FriendsPage_PageletContainer').addClass('hidden_elem');var total=payload.count;if(total===undefined){total=highlight?max:payload.members.length;}
var pager_total=highlight?0:total;var pager_max=highlight?0:max;CSS.conditionClass($('FriendsPage_BottomToolbar'),'hidden_elem',pager_total<=pager_max);this._pagerTop.resetPager(pager_total,pager_max,offset);this._pagerBottom.resetPager(pager_total,pager_max,offset);if(payload.filter_network){var primary=this._networkFiltersTypeMap[payload.filter_network];var secondary=payload.filter_network;}else{var primary=false;var secondary=false;}
this._setShowNetworkFilters(payload.filter==this._filterKeys.browse);if(payload.filter==this._filterKeys.browse){this._setNetworkFilters(primary,secondary,false);}
if(payload.members.length==0){$('FriendsPage_ListingViewContainer').removeClass('hidden_elem');$('FriendsPage_ContentContainer').addClass('hidden_elem');$('FriendsPage_BlankStateContainer').removeClass('hidden_elem');$('FriendsPage_BlankStateContainer').setContent(this._getBlankStateContent(payload.filter,highlight));}else{$('FriendsPage_BlankStateContainer').addClass('hidden_elem');$('FriendsPage_ContentContainer').removeClass('hidden_elem');$('FriendsPage_ListingViewContainer').removeClass('hidden_elem');var people=payload.members;var to_paint=[];for(var i=0;i<people.length;i++){if(!this._friendCache[people[i]]){continue;}
var new_object={};copy_properties(new_object,this._friendCache[people[i]]);to_paint.push(new_object);}
if(!highlight&&payload.filter!=this._filterKeys.recently_added&&payload.filter!=this._filterKeys.incoming_fans&&payload.filter!=this._filterKeys.recently_updated){to_paint=to_paint.sort(function(a,b){return(a.title==b.title)?0:(a.title<b.title?-1:1);});}
if(!payload.start){to_paint=to_paint.slice(offset,offset+max);}
var rows=[];this._displayedObjects=[];this._displayedObjectsMap={};for(var i=0;i<to_paint.length;i++){if(highlight){to_paint[i].title=HTML(typeahead_source.highlight_found(to_paint[i].title,highlight));}
var lists=keys(this._getListsForFriend(to_paint[i].id));if(to_paint[i].pending){to_paint[i].subtext=_tx("Friend Request Pending");}else{to_paint[i].subtext=this._getListsForFriendSubtext(lists);}
var row=new UIObjectListing(to_paint[i]);if(highlight){row.setBoldTitle(false);}
if((to_paint[i].type==search_friend_source.TYPES.USER)||(to_paint[i].type==search_friend_source.TYPES.CONNECTION)||(to_paint[i].type==search_friend_source.TYPES.PAGE)){if(payload.filter==this._filterKeys.phonebook){var phone_div=null;var cell_div=null;var phonebook_div=$N('div',{className:'FriendsPage_PhonebookRight'});if(this._phonebook[to_paint[i].id].cell){var cell_div=$N('div',{className:'FriendsPage_PhonebookCell'});var cell_label=$N('span',{className:'FriendsPage_PhonebookLabel'},_tx("MOBILE"));cell_div.setContent([cell_label,this._phonebook[to_paint[i].id].cell]);phonebook_div.appendContent(cell_div);}
if(this._phonebook[to_paint[i].id].phone){var phone_div=$N('div',{className:'FriendsPage_PhonebookLand'});var phone_label=$N('span',{className:'FriendsPage_PhonebookLabel'},_tx("LAND"));phone_div.setContent([phone_label,this._phonebook[to_paint[i].id].phone]);phonebook_div.appendContent(phone_div);}
if(phone_div&&cell_div){phonebook_div.addClass('FriendsPage_PhonebookBoth');}
row.setRightContent(phonebook_div);}else if(payload.filter==this._filterKeys.recently_updated){var recent_info=this._recentlyUpdated[to_paint[i].id];var recent_div=$N('div',{className:'FriendsPage_RecentlyUpdated'});var content_div=$N('div',{className:'FriendsPage_RecentlyUpdatedContent'},HTML(recent_info.diff));var time_div=$N('div',{className:'FriendsPage_RecentlyUpdatedTime'},HTML(recent_info.updated_time_relative));recent_div.setContent([content_div,time_div]);row.setRightContent(recent_div);}else{var menu=new UIActionMenu(this._getFriendListMenuTitle(lists.length));menu.setAlignRight(true);menu.setContentCallback(this._getFriendListMenu.bind(this,to_paint[i].id,menu));menu.setSuppressButton(true);row.setActionControl(menu);if(payload.search||payload.filter==this._filterKeys.all_friends||payload.filter==this._filterKeys.all_connections||payload.filter==this._filterKeys.outgoing_fans||payload.filter==this._filterKeys.recently_added){var tooltip=null;var remove_fn=null;if(to_paint[i].type==search_friend_source.TYPES.PAGE||to_paint[i].type==search_friend_source.TYPES.CONNECTION||to_paint[i].type==search_friend_source.TYPES.USER){tooltip=to_paint[i].pending?_tx("Remove Request"):_tx("Remove Connection");remove_fn=this._showRemoveConnectionDialog.bind(this,to_paint[i].id,to_paint[i].pending);}
if(remove_fn!=null){row.setRemoveControl(true,remove_fn,tooltip);}}}}else if(payload.filter==this._filterKeys.incoming_fans){row.setRemoveControl(true,this._showRemoveConnectionDialog.bind(this,to_paint[i].id,false,true,to_paint[i].title),_tx("Remove Fan"));}
row.paint();rows.push(row.root);this._displayedObjects.push(row);this._displayedObjectsMap[to_paint[i].id]=row;}
delete to_paint;this._friendContainer.setContent(rows);}
this._selectNavItem(payload.filter);this._setEditable(payload.editable,payload.deletable);DOMScroll.scrollTo(new Vector2(0,0,'document'),false);if(transition){PageTransitions.transitionComplete();}}
FriendsPage.prototype._getListsForFriendSubtext=function(lists){var list_names=[];for(var ii=0;ii<lists.length;ii++){if(this._cache[lists[ii]]){list_names.push(this._cache[lists[ii]].name);}}
return list_names.join(', ');}
FriendsPage.prototype._getFriendListMenu=function(uid,menu){var lists=this._getFriendListsSorted();var nodes=[];if(lists.length>0){var list=new UISelectList();var selected_lists=this._getListsForFriend(uid);for(var i=0;i<lists.length;i++){var selected=selected_lists[lists[i].filter]?true:false;list.addItem(lists[i].name,selected,lists[i].filter);}
list.setCallback(function(uid,menu,checked,filter){if(checked){this._addFriend([uid],filter);}else{this._removeFriend(uid,filter);}
menu.hideMenu();}.bind(this,uid,menu));nodes.push(list.getElement());}else{var blank_state=$N('div',{className:'FriendsPage_MenuBlankState'});blank_state.setContent(_tx("You have no lists."));nodes.push(blank_state);}
var input_div=$N('div',{className:'FriendsPage_NewList'});var input=$N('input',{type:'text',className:'FriendsPage_NewListInput inputtext'});input_div.setContent(input);nodes.push(input_div);new TextInputControl(input).setPlaceholderText(_tx("Create New List"));input.listen('focus',this._genNewListId.bind(this));input.listen('keypress',function(menu,input,uid,e){if(event_get_keypress_keycode(e)==KEYS.RETURN){var name=input.getControl().getValue();this._menuCreateList(menu,name,uid);return false;}}.bind(this,menu,input,uid));var container=$N('div',{className:'FriendsPage_MenuContainer'});container.setContent(nodes);return container;}
FriendsPage.prototype._menuCreateList=function(menu,list_name,uid){if(!this._newListId&&this._generatingNewListId){this._setNavLoading(true);setTimeout(this._menuCreateList.bind(this,menu,list_name,uid),100);}else if(this._newListId&&!this._generatingNewListId){this._setNavLoading(false);this._createNewList(this._newListId,list_name,[uid],false,true);this._newListId=false;menu.hideMenu();}else{}}
FriendsPage.prototype._genNewListId=function(){if(!this._newListId&&!this._generatingNewListId){this._generatingNewListId=true;new AsyncRequest().setURI('/friends/ajax/superfriends_newlist.php').setHandler(function(response){this._newListId=response.payload.fbid;this._generatingNewListId=false;}.bind(this)).send();}}
FriendsPage.prototype._getFriendListMenuTitle=function(num_lists){if(num_lists<1){return _tx("Add to list");}else if(num_lists==1){return _tx("1 list");}else{return _tx("{number_of_lists} lists",{number_of_lists:num_lists});}}
FriendsPage.prototype._updateFriendListing=function(uid){if(this._displayedObjectsMap[uid]){var row=this._displayedObjectsMap[uid];var menu=row.getActionControl();var lists=keys(this._getListsForFriend(uid));row.getActionControl().setTitle(this._getFriendListMenuTitle(lists.length));row.setSubtext(this._getListsForFriendSubtext(lists));}}
FriendsPage.prototype._updateAllFriendListings=function(){if(this._displayedObjectsMap){for(var k in this._displayedObjectsMap){this._updateFriendListing(k);}}}
FriendsPage.prototype._setEditable=function(editable,deletable){this._editListButton.setDisabled(!editable);this._deleteListButton.setDisabled(!deletable);}
FriendsPage.prototype._showStatusMessage=function(text){DOM.setContent(this._statusMessage,text);this._statusContainer.removeClass('hidden_elem');}
FriendsPage.prototype._hideStatusMessage=function(){this._statusContainer.addClass('hidden_elem');}
FriendsPage.prototype._createListButtonClick=function(){if(this._cache[this._filterKeys.default_view].members.length==0){new Dialog().setTitle(_tx("Create New List")).setBody(_tx("Lists help you organize your Facebook friends. Once you find some friends, you can come back here to create a list.")).setButtons(Dialog.CLOSE).show();return false;}
this._showMFS(true);return false;}
FriendsPage.prototype._getBlankStateContent=function(cache_key,search_term){var div=$N('div',{className:'FriendsPage_BlankStateContainer'});var message=$N('div',{className:'FriendsPage_BlankStateMessage'});var link=$N('a',{className:'FriendsPage_BlankStateLink'});div.setContent([message,link]);if(this._cache[cache_key]){var type=this._cache[cache_key].type;if(type==this._filterKeys.list){message.setContent(_tx("You have no friends in this list."));link.setContent(_tx("Add friends to list..."));link.setAttribute('href','#');link.listen('click',function(cache_key){this._showMFS(false,cache_key);return false;}.bind(this,cache_key));}else if(type==this._filterKeys.all_friends){message.setContent(_tx("You do not have any friends. Once you find some friends, they will appear here."));link.setContent(_tx("Find friends..."));var uri=URI.getRequestURI();uri.setQueryData({filter:this._filterKeys.find_friends});link.href=uri.toString();}else if(type==this._filterKeys.network){var network_name=this._cache[cache_key].name;message.setContent(_tx("You have no friends in this network. When you add a friend that is in the {name_of_network} network, they will appear in this filter.",{name_of_network:network_name}));link.setContent(_tx("Find friends in the {name_of_network} network...",{name_of_network:network_name}));var uri=new URI('/srch.php');uri.setQueryData({n:this._cache[cache_key].value});link.href=uri.toString();}else if(type==this._filterKeys.recently_added){message.setContent(_tx("This filter shows people that you have recently added as friends. When you add new friends, they will appear here for two weeks."));link.setContent(_tx("Find friends..."));var uri=URI.getRequestURI();uri.setQueryData({filter:this._filterKeys.find_friends});link.href=uri.toString();}else if(type==this._filterKeys.recently_updated){message.setContent(_tx("You have no friends with recently updated profiles."));link.setContent(_tx("Find friends..."));var uri=URI.getRequestURI();uri.setQueryData({filter:this._filterKeys.find_friends});link.href=uri.toString();}else if(type==this._filterKeys.mobile_subscriptions){message.setContent(_tx("You are not subscribed to anyone via SMS."));link.setContent(_tx("Add friends to list..."));link.setAttribute('href','#');link.listen('click',function(cache_key){this._showMFS(false,cache_key);return false;}.bind(this,cache_key));}}else if(search_term){message.setContent(_tx("You have no friends whose name contains \"{search_term}\".",{search_term:search_term}));link.setContent(_tx("Search Facebook for \"{search_term}\"...",{search_term:search_term}));var uri=new URI('/s.php');uri.setQueryData({q:search_term,n:-1,o:4,k:100000020});link.href=uri.toString();}else if(this._getNavItem(cache_key).data.type==this._filterKeys.browse){var all_friends_cache=this._cache[this._filterKeys.all_friends];if(all_friends_cache&&all_friends_cache.members.length==0){message.setContent(_tx("You do not have any friends. Once you find some friends, you can return here to browse them by different criteria."));link.setContent(_tx("Find friends..."));var uri=URI.getRequestURI();uri.setQueryData({filter:this._filterKeys.find_friends});link.href=uri.toString();}else if(this._networkFilters&&hasArrayNature(this._networkFilters)){message.setContent(_tx("None of your friends are in any networks."));link.addClass('hidden_elem');}else{message.setContent(_tx("Use the dropdown menu above to browse your friends by network."));link.addClass('hidden_elem');}}
return div;}
FriendsPage.prototype._getPagerSummaryText=function(offset,total,per_page){if(total==0){return'';}
if(total<=per_page){if(total==1){return _tx("1 Connection");}else{return _tx("{num_connections} Connections",{num_connections:total});}}else{if(offset+per_page<total){var second=((offset/per_page+1)*per_page);}else{var second=total;}
var string=_tx("{starting_offset}-{ending_offset} of {number_of_friends} connections",{starting_offset:(offset+1),ending_offset:second,number_of_friends:total});return string;}}
FriendsPage.prototype._editListButtonClick=function(){var list_type=this._cache[this._currentView].type;if(list_type==this._filterKeys.list||list_type==this._filterKeys.mobile_subscriptions){this._showMFS(false,this._currentView);}else if(list_type==this._filterKeys.news_feed){var onModified=function(){delete this._cache[this._filterKeys.news_feed];data=URI().getQueryData();if(!data.offset){data.offset=0;}
this._getFriends(data,false);}.bind(this);NewsFeedEditor.show(this._filterKeys.news_feed,onModified);}
return false;}
FriendsPage.prototype._deleteListButtonClick=function(){var delete_button=Dialog.newButton('delete',_tx("Delete List"));var dialog=new Dialog().setTitle(_tx("Delete List?")).setBody(_tx("Are you sure you want to delete this list? This cannot be undone.")).setButtons([delete_button,Dialog.CANCEL]);dialog.setHandler(function(current_view,button){var current=this._cache[current_view];var item=this._getNavItem(current.filter);if(item){this._listNav.removeItem(item);this._editFriendsAsync([],current.value,'delete');delete this._cache[current_view];URI.getRequestURI().setQueryData({filter:this._filterKeys.all_friends,offset:0}).go();}}.bind(this,this._currentView));dialog.show();return false;}
FriendsPage.prototype._removeConnectionFromUI=function(id,view){var members=this._cache[view].members;for(var i=0;i<members.length;i++){if(members[i]==id){members.splice(i,1);break;}}
if(this._displayedObjectsMap[id]){var action_control=this._displayedObjectsMap[id].getActionControl();if(action_control){action_control.hideMenu();}
DOM.remove(this._displayedObjectsMap[id].root);for(var i=0;i<this._displayedObjects.length;i++){if(this._displayedObjects[i].root===this._displayedObjectsMap[id].root){this._displayedObjects.splice(i,1);break;}}
delete this._displayedObjectsMap[id];}
delete this._friendCache[id];if(members.length==0){this._paintFriends(this._cache[view],false,0);}}
FriendsPage.prototype._showRemoveConnectionDialog=function(id,pending,isFan,name){var delete_button=Dialog.newButton('remove',_tx("Remove"));var dialog=new Dialog().setButtons([delete_button,Dialog.CANCEL]);var tx_data={profile:name||this._friendCache[id].title};if(isFan){dialog.setBody(_tx("Are you sure you want to remove {profile} from your list of fans?",tx_data));dialog.setTitle(_tx("Remove {profile} from My Fans?",tx_data));}else if(pending){dialog.setBody(_tx("Are you sure you want to remove your request to connect to {profile}?",tx_data));dialog.setTitle(_tx("Remove request to connect to {profile}?",tx_data));}else{dialog.setBody(_tx("Are you sure you want to remove your connection to {profile}?",tx_data));dialog.setTitle(_tx("Remove connection to {profile}?",tx_data));}
dialog.setHandler(function(id,button){new AsyncRequest().setURI('/friends/ajax/remove_friend.php').setData({friend:id,type:isFan?'fan':'friend'}).send();this._removeConnectionFromUI(id,this._filterKeys.default_view);}.bind(this,id));dialog.show();}
FriendsPage.prototype._showMFS=function(new_list,cache_key){if(!new_list){var list_id=this._cache[cache_key].value;}else{var list_id=null;}
Dialog.bootstrap(DialogBootstrapEndpoints.LIST_EDITOR,{new_list:new_list,list_id:list_id});return false;}
FriendsPage.prototype._listEditorSave=function(message,data){if(message==Arbiter.LIST_EDITOR_LISTS_CHANGED){if(data.is_new_list){this._createNewList(data.list_info.list_id,data.list_info.name,data.list_info.members,false,false);}else{var list_id=data.list_info.list_id;var cache_key=this._filterKeys.list+'_'+list_id;if(list_id==this._filterKeys.mobile_list_id){cache_key=this._filterKeys.mobile_subscriptions;}else{var list_name=data.list_info.name;this._listNav.setItemTitle(this._getNavItem(cache_key),list_name);this._cache[cache_key].name=list_name;}
this._cache[cache_key].members=data.list_info.members;this._getFriends({filter:cache_key,offset:0},false);this._selectNavItem(cache_key);}}}
FriendsPage.prototype._createNewList=function(list_id,list_name,members,redirect,backend_save){if(backend_save){this._editFriendsAsync(members,list_id,'create',list_name);}
var cache_key=this._filterKeys.list+'_'+list_id;this._cache[cache_key]={members:members,value:list_id,type:this._filterKeys.list,editable:true,name:list_name,filter:cache_key};var data={filter:cache_key,type:this._filterKeys.list,value:list_id,editable:true};var href=URI.getRequestURI();href.setQueryData({filter:cache_key});var items=this._listNav.getItems();var position=1;for(var i=0;i<items.length;i++){if(items[i].data.type==this._filterKeys.list){position=i;break;}}
this._listNav.addItem(list_name,href.toString(),position,'/images/friend_lists/friend_list_icon_with_hover.gif',data);if(redirect){href.go();}else{for(var i=0;i<members.length;i++){this._updateFriendListing(members[i]);}}}

function UIToolbarWell(elem){this._root=elem;this._leftSide=this._root.find('span.UIToolbarWell_Left');this._rightSide=this._root.find('span.UIToolbarWell_Right');this._secondaryContentContainer=this._root.find('div.UIToolbarWell_SecondaryContent');return this;}
UIToolbarWell.prototype.addContent=function(content,align){if(align=='left'){this._leftSide.appendContent(content);}else if(align=='right'){this._rightSide.appendContent(content);}}
UIToolbarWell.prototype.addButton=function(button,align){button.setSuppressMargin(true);var span=$N('span',{className:'UIToolbarWell_Button'},button.getNodes());this.addContent(span,align);return this;}
UIToolbarWell.prototype.reset=function(){DOM.empty(this._leftSide);DOM.empty(this._rightSide);return this;}
UIToolbarWell.prototype.addSecondaryContent=function(content){this._secondaryContentContainer.appendContent(content);this.setShowSecondaryContent(true);}
UIToolbarWell.prototype.setShowSecondaryContent=function(show_secondary_content){CSS.conditionClass(this._secondaryContentContainer,'hidden_elem',!show_secondary_content);}

if (window.Bootloader) { Bootloader.done(["js\/2qv4z8ey5yskcw4k.pkg.js"]); }
