// Copyright (c) 2007 Michael Schreckenberg (http://www.markt8.de)

  
  /*
   * auth handler
   * login/logout
   */
  App.AuthHandler = Ext.extend(Ext.app.Module, {
      init : function(){
        this.id = 'AppAuthHandler';
      },
      
      showLogin: function () {
        el  = Ext.get('loginFormDiv');
        el.setLeft( (Ext.lib.Dom.getViewWidth()/2) +131 );
        if(!el.isDisplayed()) {
          el.slideIn('t', {
            duration: .3
          });
          //Ext.getBody().on('click', this.showLogin, this);
        } else {
          el.slideOut('t', {
            duration: .3,
            remove: false,
            useDisplay: true
          });
          //Ext.getBody().un('click', this.showLogin, this);
        }
      },
      
      logout: function(){
        document.location.href = 'auth.php?__LOGOUT__=true';  
      },
      
      inAdminMode: function(){
        return (typeof(adminMode) != 'undefined' && adminMode == true) ? true : false;
      },
      
      isAdmin: function(){
        return (typeof(isAdmin) != 'undefined') ? true : false;
      }
      
  });
  
  
  /*
   * Taskbar
   * creates the taskbar
   */
  App.Taskbar = Ext.extend(Ext.app.Module, {
      
      init : function() {
        
        var tb = new Ext.Toolbar({
          renderTo: 'TASKBAR'
        });
        tb.add({
            text: '&nbsp;Adminmodus&nbsp;',
            style: 'margin: 0 4px',
            enableToggle: true,
            pressed: auth.inAdminMode(),
            handler: function(){
              document.location.href = (auth.inAdminMode()) ? 'index.php?admin=false' : 'index.php?admin=true'
            },
            iconCls: 'admin-view'
          },'-', {
            id: 'PageProps',
            text: 'Seiteneigenschaften',
            style: 'margin: 0 4px',
            handler: function(){
              App.load('appsrv/cms/page/properties/id/'+pageID)
            },
            iconCls: 'page-properties'
          },'-', {
            text: 'Neue Seite anlegen',
            style: 'margin: 0 4px',
            handler: function(){
              App.load('appsrv/cms/page/new/pid/'+pageID)
            },
            iconCls: 'page-new'
          },'-', {
            text: 'Neuer Artikel',
            style: 'margin: 0 4px',
            handler: function(){
              App.load('appsrv/cms/article/new/pid/'+pageID)
            },
            iconCls: 'article-new'
          },'-', {
            text: 'Dateien verwalten',
            style: 'margin: 0 4px',
            handler: function(){
              App.load('appsrv/cms/media/manager')
            },
            iconCls: 'filemanager'
          },'-', {
            text: 'Benutzer verwalten',
            style: 'margin: 0 4px',
            handler: function(){
              App.load('appsrv/community/profile/manager')
            },
            iconCls: 'group-edit'
          },'-', {
            text: 'Unternehmen verwalten',
            style: 'margin: 0 4px',
            handler: function(){
              App.load('appsrv/community/company/manager')
            },
            iconCls: 'company-edit'
          }
        );
      }
  });
  
  
   /*
   * ArticlePanel
   * creates the taskbar
   */
  App.ArticlePanel = Ext.extend(Ext.Panel, {
    
    xtype: 'portlet',
    width: '100%',
    hideCollapseTool: true,
    titleCollapse: true,
    collapsible: true,
    border: false,
    
    tools: [{
        id:'gear',
        handler: function(e, target, panel){
          App.load('appsrv/cms/article/edit/id/'+panel.article_id);
        },
        qtip: 'Artikelinhalt'
      },{
        id:'restore',
        handler: function(e, target, panel){
          App.load('appsrv/cms/article/properties/id/'+panel.article_id);
        },
        qtip: 'Artikeloptionen'
    }],
    
    init: function () {
      // on init...
    }
      
  });
  
  
  // on ready
  Ext.onReady(function() {
  
    // root ID
      rootID = '00000056';
    
    // auth handler
      auth = new App.AuthHandler;
    
    // taskbar
      if(auth.isAdmin()) {
        taskbar = new App.Taskbar;
      }
      
    // create articles panels
    
  });
