ComCore.GameMoreController=Class.create({initialize:function(A){debug("ComCore.GameMoreController.initialize()");this.type=A;this.wrapper=$(A);this.page=0;this.gamesWrapper=this.wrapper.down("div.gamesWrapper");this.height=this.wrapper.getHeight();this.animationRunning=false;this.noNextGameCard=false;if(this.gamesWrapper){this.currentGames=this.gamesWrapper.select(".gameCardWrapper");this.noNextGameCard=(this.currentGames.size()<2);this.startObserving();this.endReached=(this.wrapper.down("input.allLoaded")!==undefined)}},startObserving:function(){this.nextButton=this.wrapper.down("a.next");this.previousButton=this.wrapper.down("a.previous");if(this.noNextGameCard){this.nextButton.addClassName("disabled")}if(this.nextButton&&!this.noNextGameCard){this.nextButton.stopObserving();this.previousButton.stopObserving();this.nextButton.observe("click",this.onMore.bind(this));this.previousButton.observe("click",this.onPrevious.bind(this))}},onMore:function(B){B.stop();if(!this.animationRunning&&!this.nextButton.hasClassName("disabled")){if(this.currentGames[this.page+1]){this.currentGames[this.page].hide();this.currentGames[++this.page].show();this.previousButton.removeClassName("disabled");if(this.endReached&&!this.currentGames[this.page+1]){this.nextButton.addClassName("disabled")}}else{if(!this.endReached){this.animationRunning=true;ComCore.LoadingIndicator.show();var A=this;var D="action=getMore";D+="&view="+this.type;if(ComCore.gameControl){D+="&categoryid="+ComCore.gameControl.categoryid}D+="&page="+(this.page+1);var C=new Ajax.Request("/ajax/games/",{method:"post",parameters:D,onSuccess:A.onMoreGamesReceived.bind(A),onComplete:function(){A.gamesWrapper.setOpacity(1);A.animationRunning=false;ComCore.LoadingIndicator.hide()}});this.gamesWrapper.setOpacity(0.4)}}}},onPrevious:function(A){A.stop();if(this.currentGames[this.page-1]&&!this.animationRunning){this.currentGames[this.page].hide();this.currentGames[--this.page].show();this.nextButton.removeClassName("disabled");if(!this.currentGames[this.page-1]){this.previousButton.addClassName("disabled")}}},onMoreGamesReceived:function(B,A){A=B.responseJSON;if(A.success){this.currentGames=this.gamesWrapper.select(".gameCardWrapper");this.currentGames[this.page].hide();++this.page;this.gamesWrapper.insert({bottom:A.HTML});this.currentGames=this.gamesWrapper.select(".gameCardWrapper");this.previousButton.removeClassName("disabled")}if(A.more===false){this.nextButton.addClassName("disabled");this.endReached=true}},reInit:function(){this.page=0;this.currentGames=this.gamesWrapper.select(".gameCardWrapper");this.nextButton.removeClassName("disabled");this.previousButton.addClassName("disabled");this.animationRunning=false;this.endReached=false},_eoo:true});