/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  February 10th 2010 12:25:07 AM PST                           */
/*      Machine:  10.16.140.107                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/apps/appdirectory.js h:360bm3bs                           */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/apps/appdirectory.js                                      */

if (window.CavalryLogger) { CavalryLogger.start_js(["js\/apps\/appdirectory.js"]); }

var AppDirectoryController=function(_L0,_L1){this.parent.construct(this,_L0);this.baseUrl=_L1.base_url;this.selectedCategory=_L1.selected_category;this.selectedApplicationType=_L1.selected_app_type;this.selectedOrder=_L1.selected_ordering;this.showAllInCategory=_L1.show_all_in_category;this.attachSubcategorySelector();PageTransitions.registerHandler(this.updateAppDirectory.bind(this));};AppDirectoryController.extend('UINestedFilterList');copy_properties(AppDirectoryController,{LARGER_LOADER_IMAGE:'http://static.ak.fbcdn.net/images/loaders/indicator_blue_large.gif',SMALLER_LOADER_IMAGE:'http://static.ak.fbcdn.net/images/loaders/indicator_white_small.gif',showLoaderImage:function(id,_L1){var _L2=$N('div',{'className':'app_dir_content_loading'},$N('img',{'src':_L1}));DOM.setContent($(id),_L2);},_deferredImageMap:{},addToDeferredImageMap:function(map){copy_properties(AppDirectoryController._deferredImageMap,map);},loadImage:function(_L0){var _L1=AppDirectoryController._deferredImageMap[_L0.id];var img=$N('img',{src:_L1.src,width:_L1.width,'className':'app_dir_image'});DOM.replace(_L0,img);}});copy_properties(AppDirectoryController.prototype,{attachSubcategorySelector:function(){if(ge('app_dir_subcategory_selector')){this.subcategorySelector=$('app_dir_subcategory_selector');this.subcategorySelector.listen('change',this.fetchSubcategoryPage.bind(this));this.subcategorySelector.blur();}},updateAppDirectory:function(uri){if(uri.getPath()==this.baseUrl){var _L1=uri.getQueryData().app_type||"0";var _L2=uri.getQueryData().category||"0";var _L3=uri.getQueryData().seeall=="true"||false;if(_L3){this.fetchAllApplicationsWithinCategory(_L1,_L2);}else this.fetchNewTypeAndCategoryPage(_L1,_L2);return true;}return false;},fetchSubcategoryPage:function(_L0){var _L1=_L0.getTarget();_L1.blur();var uri=URI(this.baseUrl).addQueryData({app_type:this.selectedApplicationType,category:_L1.value,seeall:this.showAllInCategory});uri.go();},fetchNewTypeAndCategoryPage:function(_L0,_L1){var _L2='app_dir_dashboard_header';var _L3='app_dir_main';AppDirectoryController.showLoaderImage(_L3,AppDirectoryController.LARGER_LOADER_IMAGE);var uri=new URI('/ajax/apps/fetchAppDirectoryCategory.php');var _L5={app_type:_L0,category:_L1};new AsyncRequest().setURI(uri.toString()).setHandler(this.showCategorySummary.bind(this,_L2,_L3)).setData(_L5).setReadOnly(true).send();},fetchAllApplicationsWithinCategory:function(_L0,_L1){var _L2='app_dir_dashboard_header';var _L3='app_dir_main';AppDirectoryController.showLoaderImage(_L3,AppDirectoryController.LARGER_LOADER_IMAGE);var uri=new URI('/ajax/apps/fetchApplicationsWithinCategory.php');var _L5={type:_L0,category:_L1,see_all:true};new AsyncRequest().setURI(uri.toString()).setHandler(this.showFullCategoryListing.bind(this,_L2,_L3)).setData(_L5).setReadOnly(true).send();},showCategorySummary:function(_L0,_L1,_L2){var _L3=_L2.getPayload();DOM.setContent($(_L1),HTML(_L3.category_area_html));DOM.replace($(_L0),HTML(_L3.header_html));this.attachSubcategorySelector();this.selectedApplicationType=_L3.app_type;this.selectedCategory=_L3.category;this.showAllInCategory=false;var _L4=new URI(this.baseUrl);_L4.addQueryData({type:_L3.app_type,category:_L3.category});ads_refresh('',_L4.toString());PageTransitions.transitionComplete();},showFullCategoryListing:function(_L0,_L1,_L2){var _L3=_L2.getPayload();DOM.replace($(_L0),HTML(_L3.header_html));DOM.setContent($(_L1),HTML(_L3.full_listing_html));this.attachSubcategorySelector();this.selectedApplicationType=_L3.app_type;this.selectedCategory=_L3.category;this.showAllInCategory=true;PageTransitions.transitionComplete();}});var AppDirectorySwisher=function(_L0,_L1,_L2){copy_properties(this,{currPage:_L1,offset:_L1-1,numPages:_L2,pager:new UIPager(_L2,1,_L1-1,this.swish.bind(this)),pagesContainer:DOM.find(_L0,'div.app_dir_pages_container'),swisher:DOM.find(_L0,'span.app_dir_swisher')});this.swisher.appendChild(this.pager.getRoot());this.pager.setSummaryTextHandler(this.getSummaryText.bind(this));this.pageWidth=this.pagesContainer.offsetWidth;};AppDirectorySwisher.SWISH_TIME=500;copy_properties(AppDirectorySwisher.prototype,{swish:function(_L0){if(_L0<this.offset){this.swishLeft();}else this.swishRight();this.offset=_L0;},swishLeft:function(){if(this.currPage==1)return;this.stillSwishing=true;this.currPage--;var _L0=this.pageWidth*(this.currPage-1);animation(this.pagesContainer).to('scrollLeft',_L0).duration(AppDirectorySwisher.SWISH_TIME).ease(animation.ease.both).go();},swishRight:function(){if(this.currPage==this.numPages)return;this.stillSwishing=true;this.currPage++;var _L0=this.pageWidth*(this.currPage-1);animation(this.pagesContainer).to('scrollLeft',_L0).ease(animation.ease.both).duration(AppDirectorySwisher.SWISH_TIME).ondone(this.preloadImagesInAnticipation.bind(this,this.currPage,this.currPage+1)).go();},preloadImagesInAnticipation:function(_L0,_L1){if(_L1>=this.pagesContainer.childNodes.length)_L1=this.pagesContainer.childNodes.length-1;for(var i=_L0;i<=_L1;i++){var _L3=this.pagesContainer.childNodes[i];var _L4=DOM.scry(_L3,'span.app_dir_img_placeholder_span');_L4.forEach(function(_L5){CSS.removeClass(_L5,'app_dir_img_placeholder_span');AppDirectoryController.loadImage(_L5);});}},getSummaryText:function(_L0,_L1,_L2){return _tx("Page {current} of {total}",{'current':this.currPage,'total':this.numPages});}});var FullApplicationListingFilterSet=function(_L0,_L1,_L2,_L3,_L4,_L5){copy_properties(this,{controller:_L0,type:_L1,category:_L2,order:_L3,seeAll:_L4,gettingContent:false});var _L6=DOM.scry(_L0,'li.app_dir_filter a');for(var i=0;i<_L5.length;i++)_L6[i].listen('click',this.loadListing.bind(this,_L1,_L2,_L4,_L5[i]['id']));};copy_properties(FullApplicationListingFilterSet.prototype,{loadListing:function(_L0,_L1,_L2,_L3,_L4){_L4.kill();if(this.order!=_L3){this.hideApplicationListingArea();var _L5={'type':_L0,'category':_L1,'order':_L3,'see_all':_L2};new AsyncRequest().setURI('/ajax/apps/fetchApplicationsWithinCategory.php').setData(_L5).setReadOnly(true).setHandler(this.updateApplicationListingArea.bind(this)).send();}return false;},hideApplicationListingArea:function(){if(this.gettingContent)return;this.gettingContent=true;var _L0=$N('div',{'className':'app_dir_content_loading'},$N('img',{'src':AppDirectoryController.SMALLER_LOADER_IMAGE}));var _L1=DOM.scry(this.controller,'span.app_dir_swisher');_L1.forEach(function(_L4){CSS.addClass(_L4,'hidden_elem');});var _L2=DOM.find(this.controller,'div.app_dir_pages_container');CSS.addClass(_L2,'hidden_elem');var _L3=DOM.find(this.controller,'div.app_dir_header');DOM.insertAfter(_L3,_L0);},updateApplicationListingArea:function(_L0){var _L1=_L0.getPayload();DOM.replace(this.controller,HTML(_L1.full_listing_html));this.order=_L1.order;this.seeAll=_L1.see_all;var _L2=new URI(this.baseUrl);_L2.addQueryData({type:this.type,category:this.category,order:this.order,seeall:this.seeAll});this.gettingContent=false;}});var AppDirectoryActivityStream={fetchOnPageLoad:function(_L0,_L1){var _L2=$(_L0);var _L3=$N('div',{'className':'app_dir_content_loading'},$N('img',{'src':AppDirectoryController.SMALLER_LOADER_IMAGE}));DOM.setContent(_L2,_L3);var _L4={type:_L1};new AsyncRequest().setURI('/ajax/apps/fetchRecentFriendActivity.php').setData(_L4).setHandler(function(_L5){var _L6=_L5.getPayload();if(ge(_L0))DOM.replace(_L2,HTML(_L6.html));}).send();}};var AppDirectorySearchInputController=function(_L0){this.searchForm=$(_L0);this.searchInput=DOM.find(this.searchForm,'input.inputsearch');this.searchForm.listen('submit',this.fetchSearchResults.bind(this));};copy_properties(AppDirectorySearchInputController.prototype,{fetchSearchResults:function(_L0){_L0.kill();var _L1='app_dir_dashboard_header';var _L2='app_dir_main';var _L3=this.searchInput.value.trim();if(_L3.length>0){AppDirectoryController.showLoaderImage('app_dir_main',AppDirectoryController.LARGER_LOADER_IMAGE);var _L4={'query':_L3};new AsyncRequest().setURI('/ajax/apps/fetchApplicationsMatchingQuery.php').setData(_L4).setReadOnly(true).setHandler(this.updateAppDirectoryWithSearchResults.bind(this,_L1,_L2)).send();}return false;},updateAppDirectoryWithSearchResults:function(_L0,_L1,_L2){var _L3=_L2.getPayload();DOM.replace($(_L0),HTML(_L3.header_html));DOM.setContent($(_L1),HTML(_L3.search_results_html));}});var AppDirectoryDeactivationController=function(_L0,_L1,_L2){this.controller=_L0;var _L3=DOM.find(this.controller,'a.app_dir_deactivate_link');_L3.listen('click',this.deactivatePrototype.bind(this,_L1,_L2));};copy_properties(AppDirectoryDeactivationController.prototype,{deactivatePrototype:function(_L0,_L1,_L2){CSS.addClass(DOM.find(this.controller,'span.app_dir_activation'),'hidden_elem');CSS.removeClass(DOM.find(this.controller,'span.app_dir_deactivated'),'hidden_elem');var _L3={app_id:_L0,user_id:_L1};new AsyncRequest().setURI('/ajax/apps/deactivatePrototype.php').setData(_L3).setReadOnly(true).setHandler(this.revertOnFailure.bind(this)).send();},revertOnFailure:function(_L0){var _L1=_L0.getPayload();if(!_L1.success){CSS.removeClass(DOM.find(this.controller,'span.app_dir_activation'),'hidden_elem');CSS.addClass(DOM.find(this.controller,'span.app_dir_deactivated'),'hidden_elem');}}});

if (window.Bootloader) { Bootloader.done(["js\/apps\/appdirectory.js"]); }