function Controller(){function e(e){Alloy.Globals.loading.showHide("show"),e.source.children[0].color=Alloy.CFG.colors.black,e.source.backgroundGradient=Alloy.CFG.gradients.lightGreen,_.defer(function(){void 0!==m&&(m.children[0].color=Alloy.CFG.colors.white,m.backgroundGradient=Alloy.CFG.gradients.darkBlue),_.defer(function(){m=e.source,n.dateScroll.scrollTo(e.source.scrollToValue,0),_.defer(function(){a(b(e.source.moment))})})})}function l(e){Alloy.createController("matchDetail",{id:e.source.matchId,competition:e.source.competition}).getView().open()}function t(e){y.i("scrolling... y: "+e.y+" | next load point: "+k),e.y>k&&(k+=500,o(10))}function o(e){var l=_.first(A,e);A=_.rest(A,e),_.each(l,function(e){(e.competitionId!==h||void 0===h)&&(h=e.competitionId,n.table.add(n.UI.create("Label",{text:"  "+e.competitionName,backgroundGradient:Alloy.CFG.gradients.lightGrey,height:28,width:Ti.UI.FILL}))),y.i("adding ["+e.teams.home.name+"] vs ["+e.teams.away.name+"]"),n.table.add(Alloy.createController("matchTableRow",{id:e.matchId,competition:e.competitionName,time:e.kickoff,status:e.status,teamHome:e.teams.home.name,teamAway:e.teams.away.name,scoreHome:e.score.home,scoreAway:e.score.away}).getView())}),_.defer(function(){Alloy.Globals.loading.showHide("hide")})}function a(e){function l(e){_.each(f,function(l){A=A.concat(_.filter(e.matches,function(e){return e.competitionId===l}))}),_.defer(function(){A.length>0?o(10):(n.table.add(n.UI.create("Label",{text:"  "+L("AllMatches_NoData"),backgroundGradient:Alloy.CFG.gradients.lightGrey,height:28,width:Ti.UI.FILL})),Alloy.Globals.loading.showHide("hide"))})}function t(){Alloy.Globals.loading.showHide("hide")}if(0!==n.table.children.length){var a=n.table.children.slice(0);_.each(a,function(e){n.table.remove(e),e.destroy&&e.destroy()}),A=[],_.defer(function(){n.table.scrollTo(0,0),k=120})}var i=Alloy.CFG.feedUrls.matches;void 0!==g.competitionId&&(i=i+"&competitionId="+g.competitionId);var r=v.signUrl(i.replace("{{date}}",e.format("YYYY-MM-DD")).replace("{{page}}",1).replace("{{count}}",100));_.defer(function(){w.getData({getUrl:r},l,t)})}function i(l){var t=Alloy.createController("dateScrollItem",{date:l}).getView();l.isSame(C)&&e({source:t}),n.dateScroll.add(t),void 0===u&&(u=t.width+t.left+t.right,dateItemWidthHalf=Math.floor(u/2)),p+=u,t.scrollToValue=p-dateItemWidthHalf-160}function r(){for(var e=G;I>=e;e.add("days",1))i(e)}function c(){f=_.difference(Alloy.Globals.competitionSort,Alloy.Globals.favourites.leagues),f=Alloy.Globals.favourites.leagues.concat(f),_.defer(r)}require("alloy/controllers/BaseController").apply(this,Array.prototype.slice.call(arguments)),this.__controllerPath="matchTable",arguments[0]?arguments[0].__parentSymbol:null,arguments[0]?arguments[0].$model:null,arguments[0]?arguments[0].__itemTemplate:null;var n=this,d={},s={};n.__views.matchTable=Ti.UI.createView({layout:"vertical",id:"matchTable"}),n.__views.matchTable&&n.addTopLevelView(n.__views.matchTable),n.__views.dateScroll=Ti.UI.createScrollView({height:90,layout:"horizontal",backgroundColor:Alloy.CFG.colors.black,showHorizontalScrollIndicator:!1,id:"dateScroll"}),n.__views.matchTable.add(n.__views.dateScroll),e?n.__views.dateScroll.addEventListener("click",e):s["$.__views.dateScroll!click!dateClicked"]=!0,n.__views.table=Ti.UI.createScrollView({layout:"vertical",id:"table"}),n.__views.matchTable.add(n.__views.table),l?n.__views.table.addEventListener("click",l):s["$.__views.table!click!matchClicked"]=!0,t?n.__views.table.addEventListener("scroll",t):s["$.__views.table!scroll!tableScrolled"]=!0,d.destroy=function(){},_.extend(n,n.__views);var u,m,h,f,y=require("helpers"),b=require("alloy/moment"),v=require("feedSigner"),w=require("netConnect"),g=arguments[0]||{},p=0,A=[],k=120,C=b(),G=C.clone().subtract("days",Math.floor(Alloy.CFG.matchDatesCount/2)),I=C.clone().add("days",Math.floor(Alloy.CFG.matchDatesCount/2)+1);c(),s["$.__views.dateScroll!click!dateClicked"]&&n.__views.dateScroll.addEventListener("click",e),s["$.__views.table!click!matchClicked"]&&n.__views.table.addEventListener("click",l),s["$.__views.table!scroll!tableScrolled"]&&n.__views.table.addEventListener("scroll",t),_.extend(n,d)}var Alloy=require("alloy"),Backbone=Alloy.Backbone,_=Alloy._;module.exports=Controller;