/*
HTTP Host: static.ak.fbcdn.net
Generated: March 21st 2010 2:09:26 PM PDT
Machine: 10.16.140.107
Locale: nu_ll
Path: js/apps/appdirectory.js
*/

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

var AppDirectoryController=function(a,b){this.parent.construct(this,a);this.baseUrl=b.base_url;this.selectedCategory=b.selected_category;this.selectedApplicationType=b.selected_app_type;this.selectedOrder=b.selected_ordering;this.showAllInCategory=b.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(a,b){var c=$N('div',{className:'app_dir_content_loading'},$N('img',{src:b}));DOM.setContent($(a),c);},_deferredImageMap:{},addToDeferredImageMap:function(a){copy_properties(AppDirectoryController._deferredImageMap,a);},loadImage:function(c){var a=AppDirectoryController._deferredImageMap[c.id];var b=$N('img',{src:a.src,width:a.width,className:'app_dir_image'});DOM.replace(c,b);}});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(d){if(d.getPath()==this.baseUrl){var a=d.getQueryData().app_type||"0";var b=d.getQueryData().category||"0";var c=d.getQueryData().seeall=="true"||false;if(c){this.fetchAllApplicationsWithinCategory(a,b);}else this.fetchNewTypeAndCategoryPage(a,b);return true;}return false;},fetchSubcategoryPage:function(event){var a=event.getTarget();a.blur();var b=URI(this.baseUrl).addQueryData({app_type:this.selectedApplicationType,category:a.value,seeall:this.showAllInCategory});b.go();},fetchNewTypeAndCategoryPage:function(d,e){var a='app_dir_dashboard_header';var c='app_dir_main';AppDirectoryController.showLoaderImage(c,AppDirectoryController.LARGER_LOADER_IMAGE);var f=new URI('/ajax/apps/fetchAppDirectoryCategory.php');var b={app_type:d,category:e};new AsyncRequest().setURI(f.toString()).setHandler(this.showCategorySummary.bind(this,a,c)).setData(b).setReadOnly(true).send();},fetchAllApplicationsWithinCategory:function(a,b){var c='app_dir_dashboard_header';var e='app_dir_main';AppDirectoryController.showLoaderImage(e,AppDirectoryController.LARGER_LOADER_IMAGE);var f=new URI('/ajax/apps/fetchApplicationsWithinCategory.php');var d={type:a,category:b,see_all:true};new AsyncRequest().setURI(f.toString()).setHandler(this.showFullCategoryListing.bind(this,c,e)).setData(d).setReadOnly(true).send();},showCategorySummary:function(b,a,e){var d=e.getPayload();DOM.setContent($(a),HTML(d.category_area_html));DOM.replace($(b),HTML(d.header_html));this.attachSubcategorySelector();this.selectedApplicationType=d.app_type;this.selectedCategory=d.category;this.showAllInCategory=false;var c=new URI(this.baseUrl);c.addQueryData({type:d.app_type,category:d.category});ads_refresh('',c.toString());PageTransitions.transitionComplete();},showFullCategoryListing:function(b,a,d){var c=d.getPayload();DOM.replace($(b),HTML(c.header_html));DOM.setContent($(a),HTML(c.full_listing_html));this.attachSubcategorySelector();this.selectedApplicationType=c.app_type;this.selectedCategory=c.category;this.showAllInCategory=true;PageTransitions.transitionComplete();}});var AppDirectorySwisher=function(a,b,c){copy_properties(this,{currPage:b,offset:b-1,numPages:c,pager:new UIPager(c,1,b-1,this.swish.bind(this)),pagesContainer:DOM.find(a,'div.app_dir_pages_container'),swisher:DOM.find(a,'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(a){if(a<this.offset){this.swishLeft();}else this.swishRight();this.offset=a;},swishLeft:function(){if(this.currPage==1)return;this.stillSwishing=true;this.currPage--;var a=this.pageWidth*(this.currPage-1);animation(this.pagesContainer).to('scrollLeft',a).duration(AppDirectorySwisher.SWISH_TIME).ease(animation.ease.both).go();},swishRight:function(){if(this.currPage==this.numPages)return;this.stillSwishing=true;this.currPage++;var a=this.pageWidth*(this.currPage-1);animation(this.pagesContainer).to('scrollLeft',a).ease(animation.ease.both).duration(AppDirectorySwisher.SWISH_TIME).ondone(this.preloadImagesInAnticipation.bind(this,this.currPage,this.currPage+1)).go();},preloadImagesInAnticipation:function(e,a){if(a>=this.pagesContainer.childNodes.length)a=this.pagesContainer.childNodes.length-1;for(var b=e;b<=a;b++){var c=this.pagesContainer.childNodes[b];var d=DOM.scry(c,'span.app_dir_img_placeholder_span');d.forEach(function(f){CSS.removeClass(f,'app_dir_img_placeholder_span');AppDirectoryController.loadImage(f);});}},getSummaryText:function(a,c,b){return _tx("\u05e2\u05de\u05d5\u05d3 {current} \u05de\u05ea\u05d5\u05da {total}",{current:this.currPage,total:this.numPages});}});var FullApplicationListingFilterSet=function(b,h,a,e,g,c){copy_properties(this,{controller:b,type:h,category:a,order:e,seeAll:g,gettingContent:false});var f=DOM.scry(b,'li.app_dir_filter a');for(var d=0;d<c.length;d++)f[d].listen('click',this.loadListing.bind(this,h,a,g,c[d].id));};copy_properties(FullApplicationListingFilterSet.prototype,{loadListing:function(e,a,d,c,event){event.kill();if(this.order!=c){this.hideApplicationListingArea();var b={type:e,category:a,order:c,see_all:d};new AsyncRequest().setURI('/ajax/apps/fetchApplicationsWithinCategory.php').setData(b).setReadOnly(true).setHandler(this.updateApplicationListingArea.bind(this)).send();}return false;},hideApplicationListingArea:function(){if(this.gettingContent)return;this.gettingContent=true;var b=$N('div',{className:'app_dir_content_loading'},$N('img',{src:AppDirectoryController.SMALLER_LOADER_IMAGE}));var d=DOM.scry(this.controller,'span.app_dir_swisher');d.forEach(function(e){CSS.addClass(e,'hidden_elem');});var c=DOM.find(this.controller,'div.app_dir_pages_container');CSS.addClass(c,'hidden_elem');var a=DOM.find(this.controller,'div.app_dir_header');DOM.insertAfter(a,b);},updateApplicationListingArea:function(c){var b=c.getPayload();DOM.replace(this.controller,HTML(b.full_listing_html));this.order=b.order;this.seeAll=b.see_all;var a=new URI(this.baseUrl);a.addQueryData({type:this.type,category:this.category,order:this.order,seeall:this.seeAll});this.gettingContent=false;}});var AppDirectoryActivityStream={fetchOnPageLoad:function(c,a){var b=$(c);var e=$N('div',{className:'app_dir_content_loading'},$N('img',{src:AppDirectoryController.SMALLER_LOADER_IMAGE}));DOM.setContent(b,e);var d={type:a};new AsyncRequest().setURI('/ajax/apps/fetchRecentFriendActivity.php').setData(d).setHandler(function(g){var f=g.getPayload();if(ge(c))DOM.replace(b,HTML(f.html));}).send();}};var AppDirectorySearchInputController=function(a){this.searchForm=$(a);this.searchInput=DOM.find(this.searchForm,'input.inputsearch');this.searchForm.listen('submit',this.fetchSearchResults.bind(this));};copy_properties(AppDirectorySearchInputController.prototype,{fetchSearchResults:function(event){event.kill();var b='app_dir_dashboard_header';var a='app_dir_main';var d=this.searchInput.value.trim();if(d.length>0){AppDirectoryController.showLoaderImage('app_dir_main',AppDirectoryController.LARGER_LOADER_IMAGE);var c={query:d};new AsyncRequest().setURI('/ajax/apps/fetchApplicationsMatchingQuery.php').setData(c).setReadOnly(true).setHandler(this.updateAppDirectoryWithSearchResults.bind(this,b,a)).send();}return false;},updateAppDirectoryWithSearchResults:function(b,a,d){var c=d.getPayload();DOM.replace($(b),HTML(c.header_html));DOM.setContent($(a),HTML(c.search_results_html));}});var AppDirectoryDeactivationController=function(b,a,d){this.controller=b;var c=DOM.find(this.controller,'a.app_dir_deactivate_link');c.listen('click',this.deactivatePrototype.bind(this,a,d));};copy_properties(AppDirectoryDeactivationController.prototype,{deactivatePrototype:function(a,c,event){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 b={app_id:a,user_id:c};new AsyncRequest().setURI('/ajax/apps/deactivatePrototype.php').setData(b).setReadOnly(true).setHandler(this.revertOnFailure.bind(this)).send();},revertOnFailure:function(b){var a=b.getPayload();if(!a.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"]); }