define(["Marionette","base/BaseCtrl","./views/LayoutView","./views/MinMenuView","settings/SettingsCtrl","events/EventManager"],function(a,b,c,d,e,f){var g=a.Controller.extend({initialize:function(a){b.applyMixin.call(this),this.ctrls={},this.views={},this.eventManager=new f(this),this.region=a.region,this.lessonsModel=a.lessonsModel,this.settingsModel=a.settingsModel,this.eventManager.bindKeyboardEvents(),this.eventManager.addKeyVisible(this.cid),_.bindAll(this,"onSettingsModelChanged","onSettingsModelAudioChanged","onCloseMenuViewRequest"),_.bindAll(this,"onShowMenuRequest","onKeyEsc"),this._bindEvents()},_bindEvents:function(){this.eventManager.bind(CtrlEvents.Settings.changed,this.onSettingsModelChanged,this),this.eventManager.bind(CtrlEvents.Settings.audioChanged,this.onSettingsModelAudioChanged,this),this.eventManager.bind("key:esc",this.onKeyEsc,this)},_unbindEvents:function(){this.eventManager&&this.eventManager.unbindAll(),this.eventManager&&this.eventManager.unbindKeyboardEvents()},onKeyEsc:function(a){a.cid===this.cid&&(this.ctrls.settingsCtrl?this.onCloseMenuViewRequest():this.onShowMenuRequest())},onSettingsModelChanged:function(){},onSettingsModelAudioChanged:function(){},onShowMenuRequest:function(){this.settingsModel.onShowMenu(),this.showMenuView()},show:function(){this.views.layoutView=componentUtils.destroy(this.views.layoutView),this.views.layoutView=new c,this.region.show(this.views.layoutView),this.showMinMenu(),this.showMenuView()},showMinMenu:function(){this.views.minMenuView=componentUtils.destroy(this.views.minMenuView),this.views.minMenuView=new d({lessonsModel:this.lessonsModel}),this.views.minMenuView.on("request:showMenu",this.onShowMenuRequest,this),this.views.layoutView.minMenuRegion.show(this.views.minMenuView)},showMenuView:function(){this.settingsModel.isShowMenu()?(this.settingsModel.stopAudio(),this.ctrls.settingsCtrl=new e({region:this.views.layoutView.menuRegion,lessonsModel:this.lessonsModel,settingsModel:this.settingsModel}),this.ctrls.settingsCtrl.on("request:close",this.onCloseMenuViewRequest,this),this.ctrls.settingsCtrl.show()):this.ctrls.settingsCtrl=componentUtils.destroy(this.ctrls.settingsCtrl)},onCloseMenuViewRequest:function(){this.settingsModel.offShowMenu(),this.ctrls.settingsCtrl=componentUtils.destroy(this.ctrls.settingsCtrl)}});return _.extend(g.prototype,b),g});