/*
 * Ext JS Library 2.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/* shortcutbar */
var shortcutbar = {
    xtype: 'panel',
    region: 'north',
    margins: '60 5 5 5',
    border: true,
    height:28,
    id: 'shortcuts',
    tbar: {
        xtype: 'toolbar',
        id: 'shortcut_bar',
        items: [
            {
                xtype: 'tbspacer',
                width: 5
            },
            {
                xtype: 'label',
                text: 'My shortcuts'
            },
            {
                xtype: 'tbspacer',
                width: 5
            },
            {
                xtype: 'tbseparator'
            },
            {
                xtype: 'tbspacer',
                width: 5
            },
            {
                xtype: 'button',
                text: 'Address Book',
                iconCls: 'addressbook',
                handler : function(){
                    addressbookPopup.show();
                }
            },
            {
                xtype: 'tbspacer',
                width: 5
            },
            {
                xtype: 'button',
                text: 'Behavior Request',
                itemId: 'behavior',
                hidden: true,
                iconCls: 'behavior',
                handler : function(){
                    behaviorRequestPopup.show();
                }
            }
        ]
    }
};


/* preferences popup */
var prefsloaded=0;
var preferencepopup = new Ext.Window({
  title: 'Preferences',
  width: 480,
  height: 300,
  autoScroll: true,
  padding: 10,
  id: 'preferences',
  closeAction: 'hide',
  items: [{
     xtype: 'form',
     id: 'prefform',
     border: false,
     bodyStyle: 'background-color: transparent',
     items: [
      {
          xtype: 'panel',
          title: 'Password',
          frame: false,
          footer: false,
          padding: 10,
          autoHeight: true,
          layout: 'form',
          labelWidth: 120,
          style: 'margin-bottom: 10px',
          items: [
              {
                  xtype: 'textfield',
                  fieldLabel: 'Current password',
                  anchor: '80%',
                  name: 'oldpass',
                  tabIndex: 1,
                  inputType: 'password',
                  id: 'prefs-oldpass'
              },
              new Ext.ux.PasswordField({ 
                  xtype: 'textfield',
                  fieldLabel: "New Password",
                  anchor: '80%',
                  maxLength: 10,
                  maxLengthText: 'Password cannot be longer than 10 characters',
                  name: 'newpass', 
                  id: 'prefs-newpass', 
                  msgTarget: 'side', 
                  tabIndex: 2, 
                  showCapsWarning: true, 
                  showStrengthMeter: true 
              }),
              {
                  xtype: 'textfield',
                  fieldLabel: 'Confirm password',
                  anchor: '80%',
                  inputType: 'password',
                  name: 'confirmpass',
                  msgTarget: 'side',
                  maxLength: 10,
                  maxLengthText: 'Password cannot be longer than 10 characters',
                  tabIndex: 3,
                  id: 'prefs-confirmpass'
              },
              {
                  xtype: 'button',
                  text: 'Change password',
                  tabIndex: 4,
                  style: 'margin-left: 125px;',
                  listeners: {
                    click: function(b) {
                        if (Ext.getCmp('prefs-oldpass').getValue() == "" || Ext.getCmp('prefs-newpass').getValue() == "" || Ext.getCmp('prefs-confirmpass').getValue() == "") {
                           Ext.Msg.alert('Password Missing', 'One or more fields are empty.  Please re-enter and try again.');
                           return;
                        }
                        if (Ext.getCmp('prefs-newpass').getValue() == Ext.getCmp('prefs-confirmpass').getValue()) {
                           if (30 >= Ext.getCmp('prefs-newpass').calcStrength(Ext.getCmp('prefs-newpass').getValue())) {
                              Ext.Msg.alert('Password Weak', 'Please enter a stronger password and try again.');
                              return;
                           }
                           if (Ext.getCmp('prefform').getForm().isValid()) {
                              var conn = new Ext.data.Connection();
                              conn.request({
                                 url: 'schooldynamics_data.json.php',
                                 method: 'POST',
                                 params: {command: 'changePassword', oldpass: Ext.getCmp('prefs-oldpass').getValue(), newpass: Ext.getCmp('prefs-newpass').getValue()},
                                 success: function(responseObject) {                                          
                                    eval("var results = "+responseObject.responseText);                        
                                    if (results.success) {                                    
                                       Ext.Msg.alert('Status', 'Password Changed.');
                                    } else if (results.errors.reason) {
                                       Ext.Msg.alert('Status', results.errors.reason);
                                    } else {
                                       Ext.Msg.alert('Status', 'Unable to change password at this time. Please try again later.');
                                    }
                                 },
                                 failure: function() {
                                    Ext.Msg.alert('Status', 'Unable to change password at this time. Please try again later.');
                                 }
                              });
                           } else {
                              Ext.Msg.alert('Error', 'Please make sure all fields have been filled in correctly and try again.');
                           }
                        } else {                              
                           Ext.Msg.alert('Password Mismatch', 'Your new passwords do not match.  Please re-enter and try again.');
                        }
                    }
                }
              }
          ]
      },/*
      {
          xtype: 'panel',
          title: 'Message Center',
          layout: 'form',
          padding: 10,
          autoHeight: true,
          style: 'margin-bottom: 10px;',
          autoScroll: false,
          items: [
              {
                  xtype: 'checkbox',
                  boxLabel: 'Send an email notification when new messages arrive in my inbox.',
                  hideLabel: true,
                  name: 'notify',
                  id: 'notify'
              }
          ]
      },*/
      {
          xtype: 'panel',
          title: 'Home Screen',
          layout: 'form',
          padding: 10,
          autoHeight: true,
          items: [
              {
                  xtype: 'checkbox',
                  fieldLabel: 'Label',
                  boxLabel: 'Hide the School Dynamics home screen.',
                  hideLabel: true,
                  name: 'dontshowhome',
                  id: 'dontshowhome'
              }
          ]
      }]
   }],
   listeners: {
     hide: function (panel) {
       var O=Ext.getCmp('prefform');        
   			if(O.getForm().isValid()){
   				O.getForm().submit({
   					url:'schooldynamics_data.json.php',
                  method: 'POST',
   					params:{command:'submitPreferences'},
      					failure: function(form, action){
   							obj = Ext.util.JSON.decode(action.response.responseText);
   							Ext.Msg.alert('ERROR', obj.errors.reason);
   						}
   		       });
   			} else {
   				Ext.MessageBox.alert ('ERROR','Invalid Data: Please try again.');
   			}
     },
     beforeshow: function (panel) {
         if (!prefsloaded){
           var conn = new Ext.data.Connection();
           conn.request({
               url: 'schooldynamics_data.json.php',
               method: 'POST',
               async: false,
               params: {command: 'getPreferences'},
               success: function(responseObject) {
                   eval("var results = "+responseObject.responseText);
                   
                   Ext.getCmp('prefform').items.each(function(item){
                        if (item.id=="prefs-changepassword" && results[0].role=="teacherid") {
                           Ext.getCmp('prefform').remove(item, true);
                           preferencepopup.setHeight((preferencepopup.height/5)*3);
                        } else if ((item.id=="prefs-messagecenter" || item.id=="prefs-directory") && results[0].role=="studentid") {
                           Ext.getCmp('prefform').remove(item, true);
                           preferencepopup.setHeight((preferencepopup.height/3)*2);
                        }
                   }); 
   
                   //Ext.getCmp('notify').setValue((results[0].notify?results[0].notify.toString():"false"));/
                   Ext.getCmp('dontshowhome').setValue(results[0].dontshowhome.toString());
               },
                failure: function() {
                    Ext.Msg.alert('Status', 'Unable to show preferences at this time. Please try again later.');
                }
           });   
        }
        prefsloaded++;             
    }          
   }
});  


/* Help popup */
var helppopup = new Ext.Window({
     id: 'helppopup',
     title: 'Help',
     width: 480,
     height: 380,
     // set to 'hid by default: closeAction :'hide',
     //autoScroll: true,
     // set to 'false' by default: modal: false,
     layout:'fit',
     items: [{
        xtype:'tabpanel',
        border:false,
        activeTab: 0
     }],
     fbar: {
        xtype: 'toolbar',
        items: [
            {
                xtype: 'button',
                text: 'Close',
                handler: function(btn) {
                    this.ownerCt.ownerCt.hide();
                }
            }
        ]
     },
    helpFile: function(helptitle, closable) {
         return {
            xtype:'panel',
            autoScroll: true,
            closable: closable,
            border:false,
            title: helptitle,
            items: new Ext.DataView({
               tpl: new Ext.XTemplate(
                  '<tpl for=".">',
                     '<div class="help_header" style="background-image: url(images/satin_icons/{icon});"><h2>{title}</h2></div><div class="help_content">{htmlcontents}</div>',
                  '</tpl>'
               ),
               store: new Ext.data.Store({
                  autoLoad : true,
                  url: 'schooldynamics_data.json.php',
                  baseParams: {command: 'getHelpfile', helptitle:helptitle},
                  reader: new Ext.data.JsonReader({root: 'helpFile'}, [
                     {name: 'icon'},
                     {name: 'title'},           
                     {name: 'htmlcontents'}
                  ])
               }),
               itemSelector: 'div.help_content',
               loadingText: 'Please wait while help file is loading...',
               emptyText: 'No help is available on this topic.'
            })
         };
    },
    loadHelpFile: function(helptitle, width, height, top, left) {
      var tabpanel = this.items.item(0);
      var alreadyopen = this.isVisible();
      if (!alreadyopen) {
         tabpanel.removeAll(true);
      }
      var tab = tabpanel.add(new this.helpFile(helptitle, alreadyopen));
      tabpanel.setActiveTab(tab);
      
      
      if (top != undefined && left != undefined) {
         this.setPosition(top, left);
      }
      this.setSize(width, height);
      this.show();
    }
});


Ext.onReady(function(){

  Ext.History.init();

    Ext.History.on('change', function(token){   
        if(token){ 
            var pnl = Ext.getCmp(token);
            treenode = treePanel.getRootNode().findDescendant('id',token);
            treePanel.fireEvent('click',treenode, null, true);
        }else{
            //Ext.getCmp('content-panel').layout.setActiveItem('welcome-panel');
        }
    });    
   
   Ext.QuickTips.init();
    
   var buttonLogout = new Ext.Button({
    	renderTo: 'topButtons',
    	text: 'Logout',
    	iconCls: 'logout',
    	minWidth: 50,
    	width: 65,
    	cls: 'topButton',
   	    listeners: {
            click: function(b) {
                var conn = new Ext.data.Connection();
                conn.request({
                    url: 'session.php',
                    method: 'POST',
                    params: {command: 'logout'},
                    success: function(responseObject) {                                          
                        //alert(responseObject.responseText);      
                        eval("var results = "+responseObject.responseText);                        
                        if (results.success) {                                    
                            window.location = 'login.php?schoolid='+results.schoolid;
                        }
                    },
                     failure: function() {
                         Ext.Msg.alert('Status', 'Unable to logout at this time. Please try again later.');
                     }
                }); 
            }
        } 
    });
    
    var buttonPrefs = new Ext.Button({
    	renderTo: 'topButtons',
    	text: 'Preferences',
    	iconCls: 'preferences',
    	minWidth: 50,
    	width: 95,
   	    cls: 'topButton',
   	    listeners: {
            click: function(b) {
                preferencepopup.show()
            }
        }
    }); 
  
    var contentPanel = {
        id: 'content-panel',
        region: 'center', // this is what makes this panel into a region within the containing layout
        //activeItem: 0,
        deferredRender: true, 
        bodyStyle: 'background:#DFE8F6;',	
    	  layout: 'card',                
        margins: '0 5 25 0',
        border: false
    };
    var toolsPanel = {
        xtype: 'panel',
        title: 'Tools',
        region: 'east',
        width: 225,
        collapsible: true,
        margins: '0 5 25 0',
        cmargins:'0 5 25 0',
        bodyStyle: 'background-color: #cad9ec',
        padding: 6,
        id: 'tools-panel',
        layout: 'card'
    };
    
      var treePanel = new Ext.tree.TreePanel({
         id: 'tree-panel',
         border: false,
         rootVisible: false,
         root: new Ext.tree.AsyncTreeNode(),
         lines: true,
         loader: new Ext.tree.TreeLoader({
            baseParams: {command: 'getMenu'},
            dataUrl:'menu_items.json.php',
            listeners: {
               load : function(treeloader, node, response) {
                  treePanel.expandAll();
                  
                  //check preferences to choose homepage
                  var conn = new Ext.data.Connection();
                  conn.request({
                     url: 'schooldynamics_data.json.php',
                     method: 'POST',
                     async: false,
                     params: {command: 'getPreferences'},
                     success: function(responseObject) {
                         eval("var results = "+responseObject.responseText);
                         if (results[0].dontshowhome.toString() == 0) {
                           treePanel.fireEvent('click', treePanel.getRootNode().childNodes[0]);
                         } else {
                           //replace this with clicking the last page they visited
                           treePanel.fireEvent('click', treePanel.getRootNode().childNodes[0]);
                         }
                     },
                      failure: function() {
                           treePanel.fireEvent('click', treePanel.getRootNode().childNodes[0]);
                      }
                  });
               }
            }
         }),
         listeners: {
            beforeappend : function(treePanel, parentnode, node) {
              if (node.id.toLowerCase().match("behavior") != null) {
                  parentitem = Ext.getCmp('shortcut_bar');
                  parentitem.items.item('behavior').show();
              }
              return true;
            },
            append : function(treePanel, parentnode, node, index) {
              if (node.leaf && !node.id.match("Popup")) {
                 try {
                     Ext.getCmp('content-panel').add(eval(node.id));
                     toolsPanel = eval(node.id + 'tools');
                     toolsPanel.id = node.id + '-tools';
                     Ext.getCmp('tools-panel').add(toolsPanel);
                 } catch (exception) { 
                    //console.log(exception, node);
                 }
              }
            },
            click : function(n,e,historyClicked, forceClick){
               var sn = this.selModel.selNode || {}; // selNode is null on initial selection
               if(n.leaf && n.id != sn.id || forceClick){  // ignore clicks on folders and currently selected node    		
                  if (n.leaf && !n.id.match("Popup")) {

                      Ext.getCmp('content-panel').layout.setActiveItem(n.id + '-panel');
                      toolsPanel = Ext.getCmp('tools-panel');
                       		
                      if (toolsPanel.items.keys.indexOf(n.id + '-tools') != -1){
                        toolsPanel.layout.setActiveItem(n.id + '-tools');
                    toolsPanel.show();
                  } else {
                    toolsPanel.hide();
                      }
                      
                     viewport.doLayout();
                     if (historyClicked == undefined){
                      Ext.History.add(n.id);
                     }
                   
                 } else {
                  eval(n.id+".show()");
                 }
               } else if (n.leaf && n.id.match("Popup")) {
                  eval(n.id+".show()");
               }
            }
         }
      });
     
    var viewport = new Ext.Viewport({
        layout:'border',
        items:[
            shortcutbar
        ,{
            region:'west',
            width: 200,
            title: 'Navigation',
            collapsedTitle: 'Navigation',
            collapsedTitleCls: 'collapsedTitle',
            height: 1000,        
            collapsible: true,   
            margins:'0 5 25 5',
            cmargins:'0 5 25 5',
            autoScroll: true,
            border: true,
            items: treePanel
        },
            contentPanel,
            toolsPanel                        
        ],
        renderTo: Ext.getBody()
    });
      
        
});


// Code to show title on collapsed North and South panels.
// Code copied from the following thread
// http://extjs.com/forum/showthread.php?t=25381
// ALSO: 
// regions can now specify their height as a percentage
// http://www.sencha.com/forum/showthread.php?48859-OPEN-628-BorderLayout-to-offer-age-initial-sizing-of-border-regions/page2
Ext.override(Ext.layout.BorderLayout, {
  northTitleAdded  : false,
  southTitleAdded  : false,
  eastTitleAdded  : false,
  westTitleAdded  : false,

  doCollapsedTitle : function (ct) {
      //TDGi custom title for any region
      //new config options for north/south regions:
      //  collapsedTitle     : 'string'
      //  collapsedTitleCls :  'string'

      //new config options for east/westregions:
      //  collapsedTitleImg   : 'string'
      //  collapsedTitleCls   :  'string'

      var cDiv = ct.collapsedEl;

      if (ct.collapsedTitle) {

          var tpl  = new Ext.Template('<div style="float: left;">{txt}</div>');
          var insertedHtml = tpl.insertFirst(cDiv,{ txt : ct.collapsedTitle });
          if (ct.collapsedTitleStyle) {
              insertedHtml.applyStyles(ct.collapsedTitleStyle);
          }
          
          if (ct.collapsedTitleCls) {
              Ext.get(insertedHtml).addClass(ct.collapsedTitleCls);
          }
          return(true)
      }
      else if (ct.collapsedTitleImg) {

          var tpl  = new Ext.Template('<img style="padding: 0px;" src="{src}"></img>');

          var insertedHtml = tpl.append(cDiv,{ src : ct.collapsedTitleImg });
          if (ct.collapsedTitleStyle) {
              insertedHtml.applyStyles(ct.collapsedTitleStyle);
          }
          
          if (ct.collapsedTitleCls) {
              Ext.get(insertedHtml).addClass(ct.collapsedTitleCls);
          }
          return(true)
      
      }
      else {
          console.info('wtf');
          return(false);
      }
  
  
  },
  // private
  onLayout : function(ct, target){

      var collapsed;
      var size = target.getViewSize(), w = size.width, h = size.height;

      if(!this.rendered){
          
          target.position();
          target.addClass('x-border-layout-ct');
          var items = ct.items.items;
          collapsed = [];
          for(var i = 0, len = items.length; i < len; i++) {
              var c = items[i];
              var pos = c.region;
              if(c.collapsed){
                  collapsed.push(c);
              }
              c.collapsed = false;
   				var r = this[pos] = pos != 'center' && c.split ?
   					new Ext.layout.BorderLayout.SplitRegion(this, c.initialConfig, pos) :
   					new Ext.layout.BorderLayout.Region(this, c.initialConfig, pos);
   				if(pos == 'north' || pos == 'south'){
   					if(typeof c.height == 'string' && c.relHeight === undefined){
   						var p = c.height.match(/(\d+)%/);
   						if(p[1]){
   							c.relHeight = parseInt(p[1], 10) * .01;
   						}
   					}
   					if(c.relHeight !== undefined){
   						if(typeof c.relHeight != 'number'){
   							c.relHeight = parseFloat(c.relHeight);
   						}
   						c.height = h * c.relHeight;
   					}
   					r.minSize = r.minSize || r.minHeight;
   					r.maxSize = r.maxSize || r.maxHeight;
   				} else if(pos == 'east' || pos == 'west'){
   					if(typeof c.width == 'string' && c.relWidth === undefined){
   						var p = c.width.match(/(\d+)%/);
   						if(p[1]){
   							c.relWidth = parseInt(p[1], 10) * .01;
   						}
   					}
   					if(c.relWidth !== undefined){
   						if(typeof c.relWidth != 'number'){
   							c.relWidth = parseFloat(c.relWidth);
   						}
   						c.width = w * c.relWidth;
   					}
   					r.minSize = r.minSize || r.minWidth;
   					r.maxSize = r.maxSize || r.maxWidth;
   				}

              if(!c.rendered){
                  c.cls = c.cls ? c.cls +' x-border-panel' : 'x-border-panel';
                  c.render(target, i);
              }
              this[pos] = pos != 'center' && c.split ?
                  new Ext.layout.BorderLayout.SplitRegion(this, c.initialConfig, pos) :
                  new Ext.layout.BorderLayout.Region(this, c.initialConfig, pos);
              this[pos].render(target, c);
          }
          this.rendered = true;
      }

      var size = target.getViewSize();
      if(size.width < 20 || size.height < 20){ // display none?
          if(collapsed){
              this.restoreCollapsed = collapsed;
          }
          return;
      }else if(this.restoreCollapsed){
          collapsed = this.restoreCollapsed;
          delete this.restoreCollapsed;
      }

      var w = size.width, h = size.height;
      var centerW = w, centerH = h, centerY = 0, centerX = 0;

      var n = this.north, s = this.south, west = this.west, e = this.east, c = this.center;
      if(!c){
          throw 'No center region defined in BorderLayout ' + ct.id;
      }

      if(n && n.isVisible()){
          var b = n.getSize();
          var m = n.getMargins();
          b.width = w - (m.left+m.right);
   		 if(n.panel.relHeight !== undefined){
   				n.height = Math.round(h * n.panel.relHeight);
   				b.height = n.minSize && n.height < n.minSize ? n.minSize :
   					(n.maxSize && n.height > n.maxSize ? n.maxSize : n.height);
   		 }
          b.x = m.left;
          b.y = m.top;
          centerY = b.height + b.y + m.bottom;
          centerH -= centerY;
          n.applyLayout(b);
      
          //TDGi custom title for north
          //new config options for north region:
          //  collapsedTitle    : 'string'
          //  collapsedTitleCls :  'string'
          
          if (typeof n.collapsedEl != 'undefined' && n.collapsedTitle && this.northTitleAdded == false) {
              if (this.doCollapsedTitle(n)) {
                  this.northTitleAdded = true;
              }
          }                    
      }
      if(s && s.isVisible()){
          var b = s.getSize();
          var m = s.getMargins();
          b.width = w - (m.left+m.right);
   		 if(s.panel.relHeight !== undefined){
   				s.height = Math.round(h * s.panel.relHeight);
   				b.height = s.minSize && s.height < s.minSize ? s.minSize :
   					(s.maxSize && s.height > s.maxSize ? s.maxSize : s.height);
   		 }
          b.x = m.left;
          var totalHeight = (b.height + m.top + m.bottom);
          b.y = h - totalHeight + m.top;
          centerH -= totalHeight;
          s.applyLayout(b);

          //TDGi custom title for south
          //new config options for south region:
          //  collapsedTitle    : 'string'
          //  collapsedTitleCls :  'string'
          if (typeof s.collapsedEl != 'undefined' && s.collapsedTitle && this.southTitleAdded == false) {
              if (this.doCollapsedTitle(s)) {
                  this.southTitleAdded = true;
              }
          }                
      }
      if(west && west.isVisible()){
          var b = west.getSize();
          var m = west.getMargins();
          b.height = centerH - (m.top+m.bottom);
   		 if(west.panel.relWidth !== undefined){
   				west.width = Math.round(w * west.panel.relWidth);
   				b.width = west.minSize && west.width < west.minSize ? west.minSize :
   					(west.maxSize && west.width > west.maxSize ? west.maxSize : west.width);
   		 }
          b.x = m.left;
          b.y = centerY + m.top;
          var totalWidth = (b.width + m.left + m.right);
          centerX += totalWidth;
          centerW -= totalWidth;
          west.applyLayout(b);

          //TDGi custom title for west
          //new config options for wset region:
          //  collapsedTitleImg : 'string'
          //  collapsedTitleCls :  'string'
          if (typeof west.collapsedEl != 'undefined' && west.collapsedTitleImg && this.westTitleAdded == false) {
              if (this.doCollapsedTitle(west)) {
                  this.westTitleAdded = true;
              }
          
          }                
          
      }
      if(e && e.isVisible()){
          var b = e.getSize();
          var m = e.getMargins();
          b.height = centerH - (m.top+m.bottom);
   		 if(e.panel.relWidth !== undefined){
   				e.width = Math.round(w * e.panel.relWidth);
   				b.width = e.minSize && e.width < e.minSize ? e.minSize :
   					(e.maxSize && e.width > e.maxSize ? e.maxSize : e.width);
   		 }
          var totalWidth = (b.width + m.left + m.right);
          b.x = w - totalWidth + m.left;
          b.y = centerY + m.top;
          centerW -= totalWidth;
          e.applyLayout(b);
          //TDGi custom title for east
          //new config options for east region:
          //  collapsedTitleImg : 'string'
          //  collapsedTitleCls :  'string'
          if (typeof e.collapsedEl != 'undefined' && e.collapsedTitleImg && this.eastTitleAdded == false) {
              if (this.doCollapsedTitle(e)) {
                  this.eastTitleAdded = true;
              }
          }                
          
      }

      var m = c.getMargins();
      var centerBox = {
          x: centerX + m.left,
          y: centerY + m.top,
          width: centerW - (m.left+m.right),
          height: centerH - (m.top+m.bottom)
      };
      c.applyLayout(centerBox);

      if(collapsed){
          for(var i = 0, len = collapsed.length; i < len; i++){
              collapsed[i].collapse(false);
          }
      }

      if(Ext.isIE && Ext.isStrict){ // workaround IE strict repainting issue
          target.repaint();
      }
  }
}); 
Ext.override(Ext.layout.BorderLayout.SplitRegion, {
	onSplitMove : function(split, newSize){
		var s = this.panel.getSize();
		this.lastSplitSize = newSize;
		if(this.position == 'north' || this.position == 'south'){
			this.panel.setSize(s.width, newSize);
			if(this.panel.relHeight !== undefined){
				this.state.relHeight = this.panel.relHeight *= newSize / this.height;
			}else{
				this.state.height = newSize;
			}
		}else{
			this.panel.setSize(newSize, s.height);
			if(this.panel.relWidth !== undefined){
				this.state.relWidth = this.panel.relWidth *= newSize / this.width;
			}else{
				this.state.width = newSize;
			}
		}
		this.layout.layout();
		this.panel.saveState();
		return false;
	}
});

cookie.get();

