Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / js / layout / jquery.layout-latest.js
1 /**
2  * @preserve
3  * jquery.layout 1.4.3
4  * $Date: 2015/03/13 22:37:04 $
5  * $Rev: 1.0403 $
6  *
7  * Copyright (c) 2014 Kevin Dalman (http://jquery-dev.com)
8  * Based on work by Fabrizio Balliano (http://www.fabrizioballiano.net)
9  *
10  * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
11  * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
12  *
13  * SEE: http://layout.jquery-dev.com/LICENSE.txt
14  *
15  * Changelog: http://layout.jquery-dev.com/changelog.cfm
16  *
17  * Docs: http://layout.jquery-dev.com/documentation.html
18  * Tips: http://layout.jquery-dev.com/tips.html
19  * Help: http://groups.google.com/group/jquery-ui-layout
20  */
21
22 /* JavaDoc Info: http://code.google.com/closure/compiler/docs/js-for-compiler.html
23  * {!Object}    non-nullable type (never NULL)
24  * {?string}    nullable type (sometimes NULL) - default for {Object}
25  * {number=}    optional parameter
26  * {*}                  ALL types
27  */
28 /*      TODO for jQ 2.0 
29  *      change .andSelf() to .addBack()
30  *      check $.fn.disableSelection - this is in jQuery UI 1.9.x
31  */
32
33 // NOTE: For best readability, view with a fixed-width font and tabs equal to 4-chars
34
35 ;(function ($) {
36
37 // alias Math methods - used a lot!
38 var     min             = Math.min
39 ,       max             = Math.max
40 ,       round   = Math.floor
41
42 ,       isStr   =  function (v) { return $.type(v) === "string"; }
43
44         /**
45          * @param {!Object}                     Instance
46          * @param {Array.<string>}      a_fn
47          */
48 ,       runPluginCallbacks = function (Instance, a_fn) {
49                 if ($.isArray(a_fn))
50                         for (var i=0, c=a_fn.length; i<c; i++) {
51                                 var fn = a_fn[i];
52                                 try {
53                                         if (isStr(fn)) // 'name' of a function
54                                                 fn = eval(fn);
55                                         if ($.isFunction(fn))
56                                                 g(fn)( Instance );
57                                 } catch (ex) {}
58                         }
59                 function g (f) { return f; }; // compiler hack
60         }
61 ;
62
63 /*
64  *      GENERIC $.layout METHODS - used by all layouts
65  */
66 $.layout = {
67
68         version:        "1.4.3"
69 ,       revision:       1.0403 // eg: 1.4.1 final = 1.0401 - major(n+).minor(nn)+patch(nn+)
70
71         // $.layout.browser REPLACES $.browser
72 ,       browser:        {} // set below
73
74         // *PREDEFINED* EFFECTS & DEFAULTS 
75         // MUST list effect here - OR MUST set an fxSettings option (can be an empty hash: {})
76 ,       effects: {
77
78         //      Pane Open/Close Animations
79                 slide: {
80                         all:    { duration:  "fast"     } // eg: duration: 1000, easing: "easeOutBounce"
81                 ,       north:  { direction: "up"       }
82                 ,       south:  { direction: "down"     }
83                 ,       east:   { direction: "right"}
84                 ,       west:   { direction: "left"     }
85                 }
86         ,       drop: {
87                         all:    { duration:  "slow"     }
88                 ,       north:  { direction: "up"       }
89                 ,       south:  { direction: "down"     }
90                 ,       east:   { direction: "right"}
91                 ,       west:   { direction: "left"     }
92                 }
93         ,       scale: {
94                         all:    { duration:     "fast"  }
95                 }
96         //      these are not recommended, but can be used
97         ,       blind:          {}
98         ,       clip:           {}
99         ,       explode:        {}
100         ,       fade:           {}
101         ,       fold:           {}
102         ,       puff:           {}
103
104         //      Pane Resize Animations
105         ,       size: {
106                         all:    { easing:       "swing" }
107                 }
108         }
109
110         // INTERNAL CONFIG DATA - DO NOT CHANGE THIS!
111 ,       config: {
112                 optionRootKeys: "effects,panes,north,south,west,east,center".split(",")
113         ,       allPanes:               "north,south,west,east,center".split(",")
114         ,       borderPanes:    "north,south,west,east".split(",")
115         ,       oppositeEdge: {
116                         north:  "south"
117                 ,       south:  "north"
118                 ,       east:   "west"
119                 ,       west:   "east"
120                 }
121         //      offscreen data
122         ,       offscreenCSS:   { left: "-99999px", right: "auto" } // used by hide/close if useOffscreenClose=true
123         ,       offscreenReset: "offscreenReset" // key used for data
124         //      CSS used in multiple places
125         ,       hidden:         { visibility: "hidden" }
126         ,       visible:        { visibility: "visible" }
127         //      layout element settings
128         ,       resizers: {
129                         cssReq: {
130                                 position:       "absolute"
131                         ,       padding:        0
132                         ,       margin:         0
133                         ,       fontSize:       "1px"
134                         ,       textAlign:      "left"  // to counter-act "center" alignment!
135                         ,       overflow:       "hidden" // prevent toggler-button from overflowing
136                         //      SEE $.layout.defaults.zIndexes.resizer_normal
137                         }
138                 ,       cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
139                                 background: "#DDD"
140                         ,       border:         "none"
141                         }
142                 }
143         ,       togglers: {
144                         cssReq: {
145                                 position:       "absolute"
146                         ,       display:        "block"
147                         ,       padding:        0
148                         ,       margin:         0
149                         ,       overflow:       "hidden"
150                         ,       textAlign:      "center"
151                         ,       fontSize:       "1px"
152                         ,       cursor:         "pointer"
153                         ,       zIndex:         1
154                         }
155                 ,       cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
156                                 background: "#AAA"
157                         }
158                 }
159         ,       content: {
160                         cssReq: {
161                                 position:       "relative" /* contain floated or positioned elements */
162                         }
163                 ,       cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
164                                 overflow:       "auto"
165                         ,       padding:        "10px"
166                         }
167                 ,       cssDemoPane: { // DEMO CSS - REMOVE scrolling from 'pane' when it has a content-div
168                                 overflow:       "hidden"
169                         ,       padding:        0
170                         }
171                 }
172         ,       panes: { // defaults for ALL panes - overridden by 'per-pane settings' below
173                         cssReq: {
174                                 position:       "absolute"
175                         ,       margin:         0
176                         //      $.layout.defaults.zIndexes.pane_normal
177                         }
178                 ,       cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
179                                 padding:        "10px"
180                         ,       background:     "#FFF"
181                         ,       border:         "1px solid #BBB"
182                         ,       overflow:       "auto"
183                         }
184                 }
185         ,       north: {
186                         side:                   "top"
187                 ,       sizeType:               "Height"
188                 ,       dir:                    "horz"
189                 ,       cssReq: {
190                                 top:            0
191                         ,       bottom:         "auto"
192                         ,       left:           0
193                         ,       right:          0
194                         ,       width:          "auto"
195                         //      height:         DYNAMIC
196                         }
197                 }
198         ,       south: {
199                         side:                   "bottom"
200                 ,       sizeType:               "Height"
201                 ,       dir:                    "horz"
202                 ,       cssReq: {
203                                 top:            "auto"
204                         ,       bottom:         0
205                         ,       left:           0
206                         ,       right:          0
207                         ,       width:          "auto"
208                         //      height:         DYNAMIC
209                         }
210                 }
211         ,       east: {
212                         side:                   "right"
213                 ,       sizeType:               "Width"
214                 ,       dir:                    "vert"
215                 ,       cssReq: {
216                                 left:           "auto"
217                         ,       right:          0
218                         ,       top:            "auto" // DYNAMIC
219                         ,       bottom:         "auto" // DYNAMIC
220                         ,       height:         "auto"
221                         //      width:          DYNAMIC
222                         }
223                 }
224         ,       west: {
225                         side:                   "left"
226                 ,       sizeType:               "Width"
227                 ,       dir:                    "vert"
228                 ,       cssReq: {
229                                 left:           0
230                         ,       right:          "auto"
231                         ,       top:            "auto" // DYNAMIC
232                         ,       bottom:         "auto" // DYNAMIC
233                         ,       height:         "auto"
234                         //      width:          DYNAMIC
235                         }
236                 }
237         ,       center: {
238                         dir:                    "center"
239                 ,       cssReq: {
240                                 left:           "auto" // DYNAMIC
241                         ,       right:          "auto" // DYNAMIC
242                         ,       top:            "auto" // DYNAMIC
243                         ,       bottom:         "auto" // DYNAMIC
244                         ,       height:         "auto"
245                         ,       width:          "auto"
246                         }
247                 }
248         }
249
250         // CALLBACK FUNCTION NAMESPACE - used to store reusable callback functions
251 ,       callbacks: {}
252
253 ,       getParentPaneElem: function (el) {
254                 // must pass either a container or pane element
255                 var $el = $(el)
256                 ,       layout = $el.data("layout") || $el.data("parentLayout");
257                 if (layout) {
258                         var $cont = layout.container;
259                         // see if this container is directly-nested inside an outer-pane
260                         if ($cont.data("layoutPane")) return $cont;
261                         var $pane = $cont.closest("."+ $.layout.defaults.panes.paneClass);
262                         // if a pane was found, return it
263                         if ($pane.data("layoutPane")) return $pane;
264                 }
265                 return null;
266         }
267
268 ,       getParentPaneInstance: function (el) {
269                 // must pass either a container or pane element
270                 var $pane = $.layout.getParentPaneElem(el);
271                 return $pane ? $pane.data("layoutPane") : null;
272         }
273
274 ,       getParentLayoutInstance: function (el) {
275                 // must pass either a container or pane element
276                 var $pane = $.layout.getParentPaneElem(el);
277                 return $pane ? $pane.data("parentLayout") : null;
278         }
279
280 ,       getEventObject: function (evt) {
281                 return typeof evt === "object" && evt.stopPropagation ? evt : null;
282         }
283 ,       parsePaneName: function (evt_or_pane) {
284                 var evt = $.layout.getEventObject( evt_or_pane )
285                 ,       pane = evt_or_pane;
286                 if (evt) {
287                         // ALWAYS stop propagation of events triggered in Layout!
288                         evt.stopPropagation();
289                         pane = $(this).data("layoutEdge");
290                 }
291                 if (pane && !/^(west|east|north|south|center)$/.test(pane)) {
292                         $.layout.msg('LAYOUT ERROR - Invalid pane-name: "'+ pane +'"');
293                         pane = "error";
294                 }
295                 return pane;
296         }
297
298
299         // LAYOUT-PLUGIN REGISTRATION
300         // more plugins can added beyond this default list
301 ,       plugins: {
302                 draggable:              !!$.fn.draggable // resizing
303         ,       effects: {
304                         core:           !!$.effects             // animimations (specific effects tested by initOptions)
305                 ,       slide:          $.effects && ($.effects.slide || ($.effects.effect && $.effects.effect.slide)) // default effect
306                 }
307         }
308
309 //      arrays of plugin or other methods to be triggered for events in *each layout* - will be passed 'Instance'
310 ,       onCreate:       []      // runs when layout is just starting to be created - right after options are set
311 ,       onLoad:         []      // runs after layout container and global events init, but before initPanes is called
312 ,       onReady:        []      // runs after initialization *completes* - ie, after initPanes completes successfully
313 ,       onDestroy:      []      // runs after layout is destroyed
314 ,       onUnload:       []      // runs after layout is destroyed OR when page unloads
315 ,       afterOpen:      []      // runs after setAsOpen() completes
316 ,       afterClose:     []      // runs after setAsClosed() completes
317
318         /*
319          *      GENERIC UTILITY METHODS
320          */
321
322         // calculate and return the scrollbar width, as an integer
323 ,       scrollbarWidth:         function () { return window.scrollbarWidth  || $.layout.getScrollbarSize('width'); }
324 ,       scrollbarHeight:        function () { return window.scrollbarHeight || $.layout.getScrollbarSize('height'); }
325 ,       getScrollbarSize:       function (dim) {
326                 var $c  = $('<div style="position: absolute; top: -10000px; left: -10000px; width: 100px; height: 100px; border: 0; overflow: scroll;"></div>').appendTo("body")
327                 ,       d       = { width: $c.outerWidth - $c[0].clientWidth, height: 100 - $c[0].clientHeight };
328                 $c.remove();
329                 window.scrollbarWidth   = d.width;
330                 window.scrollbarHeight  = d.height;
331                 return dim.match(/^(width|height)$/) ? d[dim] : d;
332         }
333
334
335 ,       disableTextSelection: function () {
336                 var $d  = $(document)
337                 ,       s       = 'textSelectionDisabled'
338                 ,       x       = 'textSelectionInitialized'
339                 ;
340                 if ($.fn.disableSelection) {
341                         if (!$d.data(x)) // document hasn't been initialized yet
342                                 $d.on('mouseup', $.layout.enableTextSelection ).data(x, true);
343                         if (!$d.data(s))
344                                 $d.disableSelection().data(s, true);
345                 }
346         }
347 ,       enableTextSelection: function () {
348                 var $d  = $(document)
349                 ,       s       = 'textSelectionDisabled';
350                 if ($.fn.enableSelection && $d.data(s))
351                         $d.enableSelection().data(s, false);
352         }
353
354
355         /**
356          * Returns hash container 'display' and 'visibility'
357          *
358          * @see $.swap() - swaps CSS, runs callback, resets CSS
359          * @param  {!Object}            $E                              jQuery element
360          * @param  {boolean=}   [force=false]   Run even if display != none
361          * @return {!Object}                                            Returns current style props, if applicable
362          */
363 ,       showInvisibly: function ($E, force) {
364                 if ($E && $E.length && (force || $E.css("display") === "none")) { // only if not *already hidden*
365                         var s = $E[0].style
366                                 // save ONLY the 'style' props because that is what we must restore
367                         ,       CSS = { display: s.display || '', visibility: s.visibility || '' };
368                         // show element 'invisibly' so can be measured
369                         $E.css({ display: "block", visibility: "hidden" });
370                         return CSS;
371                 }
372                 return {};
373         }
374
375         /**
376          * Returns data for setting size of an element (container or a pane).
377          *
378          * @see  _create(), onWindowResize() for container, plus others for pane
379          * @return JSON  Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc
380          */
381 ,       getElementDimensions: function ($E, inset) {
382                 var
383                 //      dimensions hash - start with current data IF passed
384                         d       = { css: {}, inset: {} }
385                 ,       x       = d.css                 // CSS hash
386                 ,       i       = { bottom: 0 } // TEMP insets (bottom = complier hack)
387                 ,       N       = $.layout.cssNum
388                 ,       R       = Math.round
389                 ,       off = $E.offset()
390                 ,       b, p, ei                        // TEMP border, padding
391                 ;
392                 d.offsetLeft = off.left;
393                 d.offsetTop  = off.top;
394
395                 if (!inset) inset = {}; // simplify logic below
396
397                 $.each("Left,Right,Top,Bottom".split(","), function (idx, e) { // e = edge
398                         b = x["border" + e] = $.layout.borderWidth($E, e);
399                         p = x["padding"+ e] = $.layout.cssNum($E, "padding"+e);
400                         ei = e.toLowerCase();
401                         d.inset[ei] = inset[ei] >= 0 ? inset[ei] : p; // any missing insetX value = paddingX
402                         i[ei] = d.inset[ei] + b; // total offset of content from outer side
403                 });
404
405                 x.width         = R($E.width());
406                 x.height        = R($E.height());
407                 x.top           = N($E,"top",true);
408                 x.bottom        = N($E,"bottom",true);
409                 x.left          = N($E,"left",true);
410                 x.right         = N($E,"right",true);
411
412                 d.outerWidth    = R($E.outerWidth());
413                 d.outerHeight   = R($E.outerHeight());
414                 // calc the TRUE inner-dimensions, even in quirks-mode!
415                 d.innerWidth    = max(0, d.outerWidth  - i.left - i.right);
416                 d.innerHeight   = max(0, d.outerHeight - i.top  - i.bottom);
417                 // layoutWidth/Height is used in calcs for manual resizing
418                 // layoutW/H only differs from innerW/H when in quirks-mode - then is like outerW/H
419                 d.layoutWidth   = R($E.innerWidth());
420                 d.layoutHeight  = R($E.innerHeight());
421
422                 //if ($E.prop('tagName') === 'BODY') { debugData( d, $E.prop('tagName') ); } // DEBUG
423
424                 //d.visible     = $E.is(":visible");// && x.width > 0 && x.height > 0;
425
426                 return d;
427         }
428
429 ,       getElementStyles: function ($E, list) {
430                 var
431                         CSS     = {}
432                 ,       style   = $E[0].style
433                 ,       props   = list.split(",")
434                 ,       sides   = "Top,Bottom,Left,Right".split(",")
435                 ,       attrs   = "Color,Style,Width".split(",")
436                 ,       p, s, a, i, j, k
437                 ;
438                 for (i=0; i < props.length; i++) {
439                         p = props[i];
440                         if (p.match(/(border|padding|margin)$/))
441                                 for (j=0; j < 4; j++) {
442                                         s = sides[j];
443                                         if (p === "border")
444                                                 for (k=0; k < 3; k++) {
445                                                         a = attrs[k];
446                                                         CSS[p+s+a] = style[p+s+a];
447                                                 }
448                                         else
449                                                 CSS[p+s] = style[p+s];
450                                 }
451                         else
452                                 CSS[p] = style[p];
453                 };
454                 return CSS
455         }
456
457         /**
458          * Return the innerWidth for the current browser/doctype
459          *
460          * @see  initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
461          * @param  {Array.<Object>}     $E  Must pass a jQuery object - first element is processed
462          * @param  {number=}                    outerWidth (optional) Can pass a width, allowing calculations BEFORE element is resized
463          * @return {number}                     Returns the innerWidth of the elem by subtracting padding and borders
464          */
465 ,       cssWidth: function ($E, outerWidth) {
466                 // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
467                 if (outerWidth <= 0) return 0;
468
469                 var lb  = $.layout.browser
470                 ,       bs      = !lb.boxModel ? "border-box" : lb.boxSizing ? $E.css("boxSizing") : "content-box"
471                 ,       b       = $.layout.borderWidth
472                 ,       n       = $.layout.cssNum
473                 ,       W       = outerWidth
474                 ;
475                 // strip border and/or padding from outerWidth to get CSS Width
476                 if (bs !== "border-box")
477                         W -= (b($E, "Left") + b($E, "Right"));
478                 if (bs === "content-box")
479                         W -= (n($E, "paddingLeft") + n($E, "paddingRight"));
480                 return max(0,W);
481         }
482
483         /**
484          * Return the innerHeight for the current browser/doctype
485          *
486          * @see  initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
487          * @param  {Array.<Object>}     $E  Must pass a jQuery object - first element is processed
488          * @param  {number=}                    outerHeight  (optional) Can pass a width, allowing calculations BEFORE element is resized
489          * @return {number}                     Returns the innerHeight of the elem by subtracting padding and borders
490          */
491 ,       cssHeight: function ($E, outerHeight) {
492                 // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
493                 if (outerHeight <= 0) return 0;
494
495                 var lb  = $.layout.browser
496                 ,       bs      = !lb.boxModel ? "border-box" : lb.boxSizing ? $E.css("boxSizing") : "content-box"
497                 ,       b       = $.layout.borderWidth
498                 ,       n       = $.layout.cssNum
499                 ,       H       = outerHeight
500                 ;
501                 // strip border and/or padding from outerHeight to get CSS Height
502                 if (bs !== "border-box")
503                         H -= (b($E, "Top") + b($E, "Bottom"));
504                 if (bs === "content-box")
505                         H -= (n($E, "paddingTop") + n($E, "paddingBottom"));
506                 return max(0,H);
507         }
508
509         /**
510          * Returns the 'current CSS numeric value' for a CSS property - 0 if property does not exist
511          *
512          * @see  Called by many methods
513          * @param {Array.<Object>}      $E                                      Must pass a jQuery object - first element is processed
514          * @param {string}                      prop                            The name of the CSS property, eg: top, width, etc.
515          * @param {boolean=}                    [allowAuto=false]       true = return 'auto' if that is value; false = return 0
516          * @return {(string|number)}                                            Usually used to get an integer value for position (top, left) or size (height, width)
517          */
518 ,       cssNum: function ($E, prop, allowAuto) {
519                 if (!$E.jquery) $E = $($E);
520                 var CSS = $.layout.showInvisibly($E)
521                 ,       p       = $.css($E[0], prop, true)
522                 ,       v       = allowAuto && p=="auto" ? p : Math.round(parseFloat(p) || 0);
523                 $E.css( CSS ); // RESET
524                 return v;
525         }
526
527 ,       borderWidth: function (el, side) {
528                 if (el.jquery) el = el[0];
529                 var b = "border"+ side.substr(0,1).toUpperCase() + side.substr(1); // left => Left
530                 return $.css(el, b+"Style", true) === "none" ? 0 : Math.round(parseFloat($.css(el, b+"Width", true)) || 0);
531         }
532
533         /**
534          * Mouse-tracking utility - FUTURE REFERENCE
535          *
536          * init: if (!window.mouse) {
537          *                      window.mouse = { x: 0, y: 0 };
538          *                      $(document).mousemove( $.layout.trackMouse );
539          *              }
540          *
541          * @param {Object}              evt
542          *
543 ,       trackMouse: function (evt) {
544                 window.mouse = { x: evt.clientX, y: evt.clientY };
545         }
546         */
547
548         /**
549          * SUBROUTINE for preventPrematureSlideClose option
550          *
551          * @param {Object}              evt
552          * @param {Object=}             el
553          */
554 ,       isMouseOverElem: function (evt, el) {
555                 var
556                         $E      = $(el || this)
557                 ,       d       = $E.offset()
558                 ,       T       = d.top
559                 ,       L       = d.left
560                 ,       R       = L + $E.outerWidth()
561                 ,       B       = T + $E.outerHeight()
562                 ,       x       = evt.pageX     // evt.clientX ?
563                 ,       y       = evt.pageY     // evt.clientY ?
564                 ;
565                 // if X & Y are < 0, probably means is over an open SELECT
566                 return ($.layout.browser.msie && x < 0 && y < 0) || ((x >= L && x <= R) && (y >= T && y <= B));
567         }
568
569         /**
570          * Message/Logging Utility
571          *
572          * @example $.layout.msg("My message");                         // log text
573          * @example $.layout.msg("My message", true);           // alert text
574          * @example $.layout.msg({ foo: "bar" }, "Title");      // log hash-data, with custom title
575          * @example $.layout.msg({ foo: "bar" }, true, "Title", { sort: false }); -OR-
576          * @example $.layout.msg({ foo: "bar" }, "Title", { sort: false, display: true }); // alert hash-data
577          *
578          * @param {(Object|string)}                     info                    String message OR Hash/Array
579          * @param {(Boolean|string|Object)=}    [popup=false]   True means alert-box - can be skipped
580          * @param {(Object|string)=}                    [debugTitle=""] Title for Hash data - can be skipped
581          * @param {Object=}                                     [debugOpts]             Extra options for debug output
582          */
583 ,       msg: function (info, popup, debugTitle, debugOpts) {
584                 if ($.isPlainObject(info) && window.debugData) {
585                         if (typeof popup === "string") {
586                                 debugOpts       = debugTitle;
587                                 debugTitle      = popup;
588                         }
589                         else if (typeof debugTitle === "object") {
590                                 debugOpts       = debugTitle;
591                                 debugTitle      = null;
592                         }
593                         var t = debugTitle || "log( <object> )"
594                         ,       o = $.extend({ sort: false, returnHTML: false, display: false }, debugOpts);
595                         if (popup === true || o.display)
596                                 debugData( info, t, o );
597                         else if (window.console)
598                                 console.log(debugData( info, t, o ));
599                 }
600                 else if (popup)
601                         alert(info);
602                 else if (window.console)
603                         console.log(info);
604                 else {
605                         var id  = "#layoutLogger"
606                         ,       $l = $(id);
607                         if (!$l.length)
608                                 $l = createLog();
609                         $l.children("ul").append('<li style="padding: 4px 10px; margin: 0; border-top: 1px solid #CCC;">'+ info.replace(/\</g,"&lt;").replace(/\>/g,"&gt;") +'</li>');
610                 }
611
612                 function createLog () {
613                         var pos = $.support.fixedPosition ? 'fixed' : 'absolute'
614                         ,       $e = $('<div id="layoutLogger" style="position: '+ pos +'; top: 5px; z-index: 999999; max-width: 25%; overflow: hidden; border: 1px solid #000; border-radius: 5px; background: #FBFBFB; box-shadow: 0 2px 10px rgba(0,0,0,0.3);">'
615                                 +       '<div style="font-size: 13px; font-weight: bold; padding: 5px 10px; background: #F6F6F6; border-radius: 5px 5px 0 0; cursor: move;">'
616                                 +       '<span style="float: right; padding-left: 7px; cursor: pointer;" title="Remove Console" onclick="$(this).closest(\'#layoutLogger\').remove()">X</span>Layout console.log</div>'
617                                 +       '<ul style="font-size: 13px; font-weight: none; list-style: none; margin: 0; padding: 0 0 2px;"></ul>'
618                                 + '</div>'
619                                 ).appendTo("body");
620                         $e.css('left', $(window).width() - $e.outerWidth() - 5)
621                         if ($.ui.draggable) $e.draggable({ handle: ':first-child' });
622                         return $e;
623                 };
624         }
625
626 };
627
628
629 /*
630  *      $.layout.browser REPLACES removed $.browser, with extra data
631  *      Parsing code here adapted from jQuery 1.8 $.browse
632  */
633 (function(){
634         var u = navigator.userAgent.toLowerCase()
635         ,       m = /(chrome)[ \/]([\w.]+)/.exec( u )
636                 ||      /(webkit)[ \/]([\w.]+)/.exec( u )
637                 ||      /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( u )
638                 ||      /(msie) ([\w.]+)/.exec( u )
639                 ||      u.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( u )
640                 ||      []
641         ,       b = m[1] || ""
642         ,       v = m[2] || 0
643         ,       ie = b === "msie"
644         ,       cm = document.compatMode
645         ,       $s = $.support
646         ,       bs = $s.boxSizing !== undefined ? $s.boxSizing : $s.boxSizingReliable
647         ,       bm = !ie || !cm || cm === "CSS1Compat" || $s.boxModel || false
648         ,       lb = $.layout.browser = {
649                         version:        v
650                 ,       safari:         b === "webkit"  // webkit (NOT chrome) = safari
651                 ,       webkit:         b === "chrome"  // chrome = webkit
652                 ,       msie:           ie
653                 ,       isIE6:          ie && v == 6
654                         // ONLY IE reverts to old box-model - Note that compatMode was deprecated as of IE8
655                 ,       boxModel:       bm
656                 ,       boxSizing:      !!(typeof bs === "function" ? bs() : bs)
657                 };
658         ;
659         if (b) lb[b] = true; // set CURRENT browser
660         /*      OLD versions of jQuery only set $.support.boxModel after page is loaded
661          *      so if this is IE, use support.boxModel to test for quirks-mode (ONLY IE changes boxModel) */
662         if (!bm && !cm) $(function(){ lb.boxModel = $s.boxModel; });
663 })();
664
665
666 // DEFAULT OPTIONS
667 $.layout.defaults = {
668 /*
669  *      LAYOUT & LAYOUT-CONTAINER OPTIONS
670  *      - none of these options are applicable to individual panes
671  */
672         name:                                           ""                      // Not required, but useful for buttons and used for the state-cookie
673 ,       containerClass:                         "ui-layout-container" // layout-container element
674 ,       inset:                                          null            // custom container-inset values (override padding)
675 ,       scrollToBookmarkOnLoad:         true            // after creating a layout, scroll to bookmark in URL (.../page.htm#myBookmark)
676 ,       resizeWithWindow:                       true            // bind thisLayout.resizeAll() to the window.resize event
677 ,       resizeWithWindowDelay:          200                     // delay calling resizeAll because makes window resizing very jerky
678 ,       resizeWithWindowMaxDelay:       0                       // 0 = none - force resize every XX ms while window is being resized
679 ,       maskPanesEarly:                         false           // true = create pane-masks on resizer.mouseDown instead of waiting for resizer.dragstart
680 ,       onresizeall_start:                      null            // CALLBACK when resizeAll() STARTS     - NOT pane-specific
681 ,       onresizeall_end:                        null            // CALLBACK when resizeAll() ENDS       - NOT pane-specific
682 ,       onload_start:                           null            // CALLBACK when Layout inits - after options initialized, but before elements
683 ,       onload_end:                                     null            // CALLBACK when Layout inits - after EVERYTHING has been initialized
684 ,       onunload_start:                         null            // CALLBACK when Layout is destroyed OR onWindowUnload
685 ,       onunload_end:                           null            // CALLBACK when Layout is destroyed OR onWindowUnload
686 ,       initPanes:                                      true            // false = DO NOT initialize the panes onLoad - will init later
687 ,       showErrorMessages:                      true            // enables fatal error messages to warn developers of common errors
688 ,       showDebugMessages:                      false           // display console-and-alert debug msgs - IF this Layout version _has_ debugging code!
689 //      Changing this zIndex value will cause other zIndex values to automatically change
690 ,       zIndex:                                         null            // the PANE zIndex - resizers and masks will be +1
691 //      DO NOT CHANGE the zIndex values below unless you clearly understand their relationships
692 ,       zIndexes: {                                                             // set _default_ z-index values here...
693                 pane_normal:                    0                       // normal z-index for panes
694         ,       content_mask:                   1                       // applied to overlays used to mask content INSIDE panes during resizing
695         ,       resizer_normal:                 2                       // normal z-index for resizer-bars
696         ,       pane_sliding:                   100                     // applied to *BOTH* the pane and its resizer when a pane is 'slid open'
697         ,       pane_animate:                   1000            // applied to the pane when being animated - not applied to the resizer
698         ,       resizer_drag:                   10000           // applied to the CLONED resizer-bar when being 'dragged'
699         }
700 ,       errors: {
701                 pane:                                   "pane"          // description of "layout pane element" - used only in error messages
702         ,       selector:                               "selector"      // description of "jQuery-selector" - used only in error messages
703         ,       addButtonError:                 "Error Adding Button\nInvalid "
704         ,       containerMissing:               "UI Layout Initialization Error\nThe specified layout-container does not exist."
705         ,       centerPaneMissing:              "UI Layout Initialization Error\nThe center-pane element does not exist.\nThe center-pane is a required element."
706         ,       noContainerHeight:              "UI Layout Initialization Warning\nThe layout-container \"CONTAINER\" has no height.\nTherefore the layout is 0-height and hence 'invisible'!"
707         ,       callbackError:                  "UI Layout Callback Error\nThe EVENT callback is not a valid function."
708         }
709 /*
710  *      PANE DEFAULT SETTINGS
711  *      - settings under the 'panes' key become the default settings for *all panes*
712  *      - ALL pane-options can also be set specifically for each panes, which will override these 'default values'
713  */
714 ,       panes: { // default options for 'all panes' - will be overridden by 'per-pane settings'
715                 applyDemoStyles:                false           // NOTE: renamed from applyDefaultStyles for clarity
716         ,       closable:                               true            // pane can open & close
717         ,       resizable:                              true            // when open, pane can be resized 
718         ,       slidable:                               true            // when closed, pane can 'slide open' over other panes - closes on mouse-out
719         ,       initClosed:                             false           // true = init pane as 'closed'
720         ,       initHidden:                     false           // true = init pane as 'hidden' - no resizer-bar/spacing
721         //      SELECTORS
722         //,     paneSelector:                   ""                      // MUST be pane-specific - jQuery selector for pane
723         ,       contentSelector:                ".ui-layout-content" // INNER div/element to auto-size so only it scrolls, not the entire pane!
724         ,       contentIgnoreSelector:  ".ui-layout-ignore"     // element(s) to 'ignore' when measuring 'content'
725         ,       findNestedContent:              false           // true = $P.find(contentSelector), false = $P.children(contentSelector)
726         //      GENERIC ROOT-CLASSES - for auto-generated classNames
727         ,       paneClass:                              "ui-layout-pane"        // Layout Pane
728         ,       resizerClass:                   "ui-layout-resizer"     // Resizer Bar
729         ,       togglerClass:                   "ui-layout-toggler"     // Toggler Button
730         ,       buttonClass:                    "ui-layout-button"      // CUSTOM Buttons       - eg: '[ui-layout-button]-toggle/-open/-close/-pin'
731         //      ELEMENT SIZE & SPACING
732         //,     size:                                   100                     // MUST be pane-specific -initial size of pane
733         ,       minSize:                                0                       // when manually resizing a pane
734         ,       maxSize:                                0                       // ditto, 0 = no limit
735         ,       spacing_open:                   6                       // space between pane and adjacent panes - when pane is 'open'
736         ,       spacing_closed:                 6                       // ditto - when pane is 'closed'
737         ,       togglerLength_open:             50                      // Length = WIDTH of toggler button on north/south sides - HEIGHT on east/west sides
738         ,       togglerLength_closed:   50                      // 100% OR -1 means 'full height/width of resizer bar' - 0 means 'hidden'
739         ,       togglerAlign_open:              "center"        // top/left, bottom/right, center, OR...
740         ,       togglerAlign_closed:    "center"        // 1 => nn = offset from top/left, -1 => -nn == offset from bottom/right
741         ,       togglerContent_open:    ""                      // text or HTML to put INSIDE the toggler
742         ,       togglerContent_closed:  ""                      // ditto
743         //      RESIZING OPTIONS
744         ,       resizerDblClickToggle:  true            // 
745         ,       autoResize:                             true            // IF size is 'auto' or a percentage, then recalc 'pixel size' whenever the layout resizes
746         ,       autoReopen:                             true            // IF a pane was auto-closed due to noRoom, reopen it when there is room? False = leave it closed
747         ,       resizerDragOpacity:             1                       // option for ui.draggable
748         //,     resizerCursor:                  ""                      // MUST be pane-specific - cursor when over resizer-bar
749         ,       maskContents:                   false           // true = add DIV-mask over-or-inside this pane so can 'drag' over IFRAMES
750         ,       maskObjects:                    false           // true = add IFRAME-mask over-or-inside this pane to cover objects/applets - content-mask will overlay this mask
751         ,       maskZindex:                             null            // will override zIndexes.content_mask if specified - not applicable to iframe-panes
752         ,       resizingGrid:                   false           // grid size that the resizers will snap-to during resizing, eg: [20,20]
753         ,       livePaneResizing:               false           // true = LIVE Resizing as resizer is dragged
754         ,       liveContentResizing:    false           // true = re-measure header/footer heights as resizer is dragged
755         ,       liveResizingTolerance:  1                       // how many px change before pane resizes, to control performance
756         //      SLIDING OPTIONS
757         ,       sliderCursor:                   "pointer"       // cursor when resizer-bar will trigger 'sliding'
758         ,       slideTrigger_open:              "click"         // click, dblclick, mouseenter
759         ,       slideTrigger_close:             "mouseleave"// click, mouseleave
760         ,       slideDelay_open:                300                     // applies only for mouseenter event - 0 = instant open
761         ,       slideDelay_close:               300                     // applies only for mouseleave event (300ms is the minimum!)
762         ,       hideTogglerOnSlide:             false           // when pane is slid-open, should the toggler show?
763         ,       preventQuickSlideClose: $.layout.browser.webkit // Chrome triggers slideClosed as it is opening
764         ,       preventPrematureSlideClose: false       // handle incorrect mouseleave trigger, like when over a SELECT-list in IE
765         //      PANE-SPECIFIC TIPS & MESSAGES
766         ,       tips: {
767                         Open:                           "Open"          // eg: "Open Pane"
768                 ,       Close:                          "Close"
769                 ,       Resize:                         "Resize"
770                 ,       Slide:                          "Slide Open"
771                 ,       Pin:                            "Pin"
772                 ,       Unpin:                          "Un-Pin"
773                 ,       noRoomToOpen:           "Not enough room to show this panel."   // alert if user tries to open a pane that cannot
774                 ,       minSizeWarning:         "Panel has reached its minimum size"    // displays in browser statusbar
775                 ,       maxSizeWarning:         "Panel has reached its maximum size"    // ditto
776                 }
777         //      HOT-KEYS & MISC
778         ,       showOverflowOnHover:    false           // will bind allowOverflow() utility to pane.onMouseOver
779         ,       enableCursorHotkey:             true            // enabled 'cursor' hotkeys
780         //,     customHotkey:                   ""                      // MUST be pane-specific - EITHER a charCode OR a character
781         ,       customHotkeyModifier:   "SHIFT"         // either 'SHIFT', 'CTRL' or 'CTRL+SHIFT' - NOT 'ALT'
782         //      PANE ANIMATION
783         //      NOTE: fxSss_open, fxSss_close & fxSss_size options (eg: fxName_open) are auto-generated if not passed
784         ,       fxName:                                 "slide"         // ('none' or blank), slide, drop, scale -- only relevant to 'open' & 'close', NOT 'size'
785         ,       fxSpeed:                                null            // slow, normal, fast, 200, nnn - if passed, will OVERRIDE fxSettings.duration
786         ,       fxSettings:                             {}                      // can be passed, eg: { easing: "easeOutBounce", duration: 1500 }
787         ,       fxOpacityFix:                   true            // tries to fix opacity in IE to restore anti-aliasing after animation
788         ,       animatePaneSizing:              false           // true = animate resizing after dragging resizer-bar OR sizePane() is called
789         /*  NOTE: Action-specific FX options are auto-generated from the options above if not specifically set:
790                 fxName_open:                    "slide"         // 'Open' pane animation
791                 fnName_close:                   "slide"         // 'Close' pane animation
792                 fxName_size:                    "slide"         // 'Size' pane animation - when animatePaneSizing = true
793                 fxSpeed_open:                   null
794                 fxSpeed_close:                  null
795                 fxSpeed_size:                   null
796                 fxSettings_open:                {}
797                 fxSettings_close:               {}
798                 fxSettings_size:                {}
799         */
800         //      CHILD/NESTED LAYOUTS
801         ,       children:                               null            // Layout-options for nested/child layout - even {} is valid as options
802         ,       containerSelector:              ''                      // if child is NOT 'directly nested', a selector to find it/them (can have more than one child layout!)
803         ,       initChildren:                   true            // true = child layout will be created as soon as _this_ layout completes initialization
804         ,       destroyChildren:                true            // true = destroy child-layout if this pane is destroyed
805         ,       resizeChildren:                 true            // true = trigger child-layout.resizeAll() when this pane is resized
806         //      EVENT TRIGGERING
807         ,       triggerEventsOnLoad:    false           // true = trigger onopen OR onclose callbacks when layout initializes
808         ,       triggerEventsDuringLiveResize: true     // true = trigger onresize callback REPEATEDLY if livePaneResizing==true
809         //      PANE CALLBACKS
810         ,       onshow_start:                   null            // CALLBACK when pane STARTS to Show    - BEFORE onopen/onhide_start
811         ,       onshow_end:                             null            // CALLBACK when pane ENDS being Shown  - AFTER  onopen/onhide_end
812         ,       onhide_start:                   null            // CALLBACK when pane STARTS to Close   - BEFORE onclose_start
813         ,       onhide_end:                             null            // CALLBACK when pane ENDS being Closed - AFTER  onclose_end
814         ,       onopen_start:                   null            // CALLBACK when pane STARTS to Open
815         ,       onopen_end:                             null            // CALLBACK when pane ENDS being Opened
816         ,       onclose_start:                  null            // CALLBACK when pane STARTS to Close
817         ,       onclose_end:                    null            // CALLBACK when pane ENDS being Closed
818         ,       onresize_start:                 null            // CALLBACK when pane STARTS being Resized ***FOR ANY REASON***
819         ,       onresize_end:                   null            // CALLBACK when pane ENDS being Resized ***FOR ANY REASON***
820         ,       onsizecontent_start:    null            // CALLBACK when sizing of content-element STARTS
821         ,       onsizecontent_end:              null            // CALLBACK when sizing of content-element ENDS
822         ,       onswap_start:                   null            // CALLBACK when pane STARTS to Swap
823         ,       onswap_end:                             null            // CALLBACK when pane ENDS being Swapped
824         ,       ondrag_start:                   null            // CALLBACK when pane STARTS being ***MANUALLY*** Resized
825         ,       ondrag_end:                             null            // CALLBACK when pane ENDS being ***MANUALLY*** Resized
826         }
827 /*
828  *      PANE-SPECIFIC SETTINGS
829  *      - options listed below MUST be specified per-pane - they CANNOT be set under 'panes'
830  *      - all options under the 'panes' key can also be set specifically for any pane
831  *      - most options under the 'panes' key apply only to 'border-panes' - NOT the the center-pane
832  */
833 ,       north: {
834                 paneSelector:                   ".ui-layout-north"
835         ,       size:                                   "auto"          // eg: "auto", "30%", .30, 200
836         ,       resizerCursor:                  "n-resize"      // custom = url(myCursor.cur)
837         ,       customHotkey:                   ""                      // EITHER a charCode (43) OR a character ("o")
838         }
839 ,       south: {
840                 paneSelector:                   ".ui-layout-south"
841         ,       size:                                   "50%"//"auto"
842         ,       resizerCursor:                  "s-resize"
843         ,       customHotkey:                   ""
844         ,   initClosed:                         true    
845         }
846 ,       east: {
847                 paneSelector:                   ".ui-layout-east"
848         ,       size:                                   "5%"//200
849         ,       resizerCursor:                  "e-resize"
850         ,       customHotkey:                   ""
851         }
852 ,       west: {
853                 paneSelector:                   ".ui-layout-west"
854         ,       size:                                   "70%" //200
855         ,       resizerCursor:                  "w-resize"
856         ,       customHotkey:                   ""
857         ,   initClosed:                         true    
858         }
859 ,       center: {
860                 paneSelector:                   ".ui-layout-center"
861         ,       size:                                   "30%"//"auto"
862         ,       minWidth:                               0
863         ,       minHeight:                              0
864         }
865 };
866
867 $.layout.optionsMap = {
868         // layout/global options - NOT pane-options
869         layout: ("name,instanceKey,stateManagement,effects,inset,zIndexes,errors,"
870         +       "zIndex,scrollToBookmarkOnLoad,showErrorMessages,maskPanesEarly,"
871         +       "outset,resizeWithWindow,resizeWithWindowDelay,resizeWithWindowMaxDelay,"
872         +       "onresizeall,onresizeall_start,onresizeall_end,onload,onload_start,onload_end,onunload,onunload_start,onunload_end").split(",")
873 //      borderPanes: [ ALL options that are NOT specified as 'layout' ]
874         // default.panes options that apply to the center-pane (most options apply _only_ to border-panes)
875 ,       center: ("paneClass,contentSelector,contentIgnoreSelector,findNestedContent,applyDemoStyles,triggerEventsOnLoad,"
876         +       "showOverflowOnHover,maskContents,maskObjects,liveContentResizing,"
877         +       "containerSelector,children,initChildren,resizeChildren,destroyChildren,"
878         +       "onresize,onresize_start,onresize_end,onsizecontent,onsizecontent_start,onsizecontent_end").split(",")
879         // options that MUST be specifically set 'per-pane' - CANNOT set in the panes (defaults) key
880 ,       noDefault: ("paneSelector,resizerCursor,customHotkey").split(",")
881 };
882
883 /**
884  * Processes options passed in converts flat-format data into subkey (JSON) format
885  * In flat-format, subkeys are _currently_ separated with 2 underscores, like north__optName
886  * Plugins may also call this method so they can transform their own data
887  *
888  * @param  {!Object}    hash                    Data/options passed by user - may be a single level or nested levels
889  * @param  {boolean=}   [addKeys=false] Should the primary layout.options keys be added if they do not exist?
890  * @return {Object}                                             Returns hash of minWidth & minHeight
891  */
892 $.layout.transformData = function (hash, addKeys) {
893         var     json = addKeys ? { panes: {}, center: {} } : {} // init return object
894         ,       branch, optKey, keys, key, val, i, c;
895
896         if (typeof hash !== "object") return json; // no options passed
897
898         // convert all 'flat-keys' to 'sub-key' format
899         for (optKey in hash) {
900                 branch  = json;
901                 val             = hash[ optKey ];
902                 keys    = optKey.split("__"); // eg: west__size or north__fxSettings__duration
903                 c               = keys.length - 1;
904                 // convert underscore-delimited to subkeys
905                 for (i=0; i <= c; i++) {
906                         key = keys[i];
907                         if (i === c) {  // last key = value
908                                 if ($.isPlainObject( val ))
909                                         branch[key] = $.layout.transformData( val ); // RECURSE
910                                 else
911                                         branch[key] = val;
912                         }
913                         else {
914                                 if (!branch[key])
915                                         branch[key] = {}; // create the subkey
916                                 // recurse to sub-key for next loop - if not done
917                                 branch = branch[key];
918                         }
919                 }
920         }
921         return json;
922 };
923
924 // INTERNAL CONFIG DATA - DO NOT CHANGE THIS!
925 $.layout.backwardCompatibility = {
926         // data used by renameOldOptions()
927         map: {
928         //      OLD Option Name:                        NEW Option Name
929                 applyDefaultStyles:                     "applyDemoStyles"
930         //      CHILD/NESTED LAYOUTS
931         ,       childOptions:                           "children"
932         ,       initChildLayout:                        "initChildren"
933         ,       destroyChildLayout:                     "destroyChildren"
934         ,       resizeChildLayout:                      "resizeChildren"
935         ,       resizeNestedLayout:                     "resizeChildren"
936         //      MISC Options
937         ,       resizeWhileDragging:            "livePaneResizing"
938         ,       resizeContentWhileDragging:     "liveContentResizing"
939         ,       triggerEventsWhileDragging:     "triggerEventsDuringLiveResize"
940         ,       maskIframesOnResize:            "maskContents"
941         //      STATE MANAGEMENT
942         ,       useStateCookie:                         "stateManagement.enabled"
943         ,       "cookie.autoLoad":                      "stateManagement.autoLoad"
944         ,       "cookie.autoSave":                      "stateManagement.autoSave"
945         ,       "cookie.keys":                          "stateManagement.stateKeys"
946         ,       "cookie.name":                          "stateManagement.cookie.name"
947         ,       "cookie.domain":                        "stateManagement.cookie.domain"
948         ,       "cookie.path":                          "stateManagement.cookie.path"
949         ,       "cookie.expires":                       "stateManagement.cookie.expires"
950         ,       "cookie.secure":                        "stateManagement.cookie.secure"
951         //      OLD Language options
952         ,       noRoomToOpenTip:                        "tips.noRoomToOpen"
953         ,       togglerTip_open:                        "tips.Close"    // open   = Close
954         ,       togglerTip_closed:                      "tips.Open"             // closed = Open
955         ,       resizerTip:                                     "tips.Resize"
956         ,       sliderTip:                                      "tips.Slide"
957         }
958
959 /**
960 * @param {Object}       opts
961 */
962 ,       renameOptions: function (opts) {
963                 var map = $.layout.backwardCompatibility.map
964                 ,       oldData, newData, value
965                 ;
966                 for (var itemPath in map) {
967                         oldData = getBranch( itemPath );
968                         value   = oldData.branch[ oldData.key ];
969                         if (value !== undefined) {
970                                 newData = getBranch( map[itemPath], true );
971                                 newData.branch[ newData.key ] = value;
972                                 delete oldData.branch[ oldData.key ];
973                         }
974                 }
975
976                 /**
977                  * @param {string}      path
978                  * @param {boolean=}    [create=false]  Create path if does not exist
979                  */
980                 function getBranch (path, create) {
981                         var a = path.split(".") // split keys into array
982                         ,       c = a.length - 1
983                         ,       D = { branch: opts, key: a[c] } // init branch at top & set key (last item)
984                         ,       i = 0, k, undef;
985                         for (; i<c; i++) { // skip the last key (data)
986                                 k = a[i];
987                                 if (D.branch[ k ] == undefined) { // child-key does not exist
988                                         if (create) {
989                                                 D.branch = D.branch[ k ] = {}; // create child-branch
990                                         }
991                                         else // can't go any farther
992                                                 D.branch = {}; // branch is undefined
993                                 }
994                                 else
995                                         D.branch = D.branch[ k ]; // get child-branch
996                         }
997                         return D;
998                 };
999         }
1000
1001 /**
1002 * @param {Object}       opts
1003 */
1004 ,       renameAllOptions: function (opts) {
1005                 var ren = $.layout.backwardCompatibility.renameOptions;
1006                 // rename root (layout) options
1007                 ren( opts );
1008                 // rename 'defaults' to 'panes'
1009                 if (opts.defaults) {
1010                         if (typeof opts.panes !== "object")
1011                                 opts.panes = {};
1012                         $.extend(true, opts.panes, opts.defaults);
1013                         delete opts.defaults;
1014                 }
1015                 // rename options in the the options.panes key
1016                 if (opts.panes) ren( opts.panes );
1017                 // rename options inside *each pane key*, eg: options.west
1018                 $.each($.layout.config.allPanes, function (i, pane) {
1019                         if (opts[pane]) ren( opts[pane] );
1020                 });     
1021                 return opts;
1022         }
1023 };
1024
1025
1026
1027
1028 /*      ============================================================
1029  *      BEGIN WIDGET: $( selector ).layout( {options} );
1030  *      ============================================================
1031  */
1032 $.fn.layout = function (opts) {
1033         var
1034
1035         // local aliases to global data
1036         browser = $.layout.browser
1037 ,       _c              = $.layout.config
1038
1039         // local aliases to utlity methods
1040 ,       cssW    = $.layout.cssWidth
1041 ,       cssH    = $.layout.cssHeight
1042 ,       elDims  = $.layout.getElementDimensions
1043 ,       styles  = $.layout.getElementStyles
1044 ,       evtObj  = $.layout.getEventObject
1045 ,       evtPane = $.layout.parsePaneName
1046
1047 /**
1048  * options - populated by initOptions()
1049  */
1050 ,       options = $.extend(true, {}, $.layout.defaults)
1051 ,       effects = options.effects = $.extend(true, {}, $.layout.effects)
1052
1053 /**
1054  * layout-state object
1055  */
1056 ,       state = {
1057                 // generate unique ID to use for event.namespace so can unbind only events added by 'this layout'
1058                 id:                             "layout"+ $.now()       // code uses alias: sID
1059         ,       initialized:    false
1060         ,       paneResizing:   false
1061         ,       panesSliding:   {}
1062         ,       container:      {       // list all keys referenced in code to avoid compiler error msgs
1063                         innerWidth:             0
1064                 ,       innerHeight:    0
1065                 ,       outerWidth:             0
1066                 ,       outerHeight:    0
1067                 ,       layoutWidth:    0
1068                 ,       layoutHeight:   0
1069                 }
1070         ,       north:          { childIdx: 0 }
1071         ,       south:          { childIdx: 0 }
1072         ,       east:           { childIdx: 0 }
1073         ,       west:           { childIdx: 0 }
1074         ,       center:         { childIdx: 0 }
1075         }
1076
1077 /**
1078  * parent/child-layout pointers
1079  */
1080 //,     hasParentLayout = false - exists ONLY inside Instance so can be set externally
1081 ,       children = {
1082                 north:          null
1083         ,       south:          null
1084         ,       east:           null
1085         ,       west:           null
1086         ,       center:         null
1087         }
1088
1089 /*
1090  * ###########################
1091  *  INTERNAL HELPER FUNCTIONS
1092  * ###########################
1093  */
1094
1095         /**
1096          * Manages all internal timers
1097          */
1098 ,       timer = {
1099                 data:   {}
1100         ,       set:    function (s, fn, ms) { timer.clear(s); timer.data[s] = setTimeout(fn, ms); }
1101         ,       clear:  function (s) { var t=timer.data; if (t[s]) {clearTimeout(t[s]); delete t[s];} }
1102         }
1103
1104         /**
1105          * Alert or console.log a message - IF option is enabled.
1106          *
1107          * @param {(string|!Object)}    msg                             Message (or debug-data) to display
1108          * @param {boolean=}                    [popup=false]   True by default, means 'alert', false means use console.log
1109          * @param {boolean=}                    [debug=false]   True means is a widget debugging message
1110          */
1111 ,       _log = function (msg, popup, debug) {
1112                 var o = options;
1113                 if ((o.showErrorMessages && !debug) || (debug && o.showDebugMessages))
1114                         $.layout.msg( o.name +' / '+ msg, (popup !== false) );
1115                 return false;
1116         }
1117
1118         /**
1119          * Executes a Callback function after a trigger event, like resize, open or close
1120          *
1121          * @param {string}                              evtName                                 Name of the layout callback, eg "onresize_start"
1122          * @param {(string|boolean)=}   [pane=""]                               This is passed only so we can pass the 'pane object' to the callback
1123          * @param {(string|boolean)=}   [skipBoundEvents=false] True = do not run events bound to the elements - only the callbacks set in options
1124          */
1125 ,       _runCallbacks = function (evtName, pane, skipBoundEvents) {
1126                 var     hasPane = pane && isStr(pane)
1127                 ,       s               = hasPane ? state[pane] : state
1128                 ,       o               = hasPane ? options[pane] : options
1129                 ,       lName   = options.name
1130                         // names like onopen and onopen_end separate are interchangeable in options...
1131                 ,       lng             = evtName + (evtName.match(/_/) ? "" : "_end")
1132                 ,       shrt    = lng.match(/_end$/) ? lng.substr(0, lng.length - 4) : ""
1133                 ,       fn              = o[lng] || o[shrt]
1134                 ,       retVal  = "NC" // NC = No Callback
1135                 ,       args    = []
1136                 ,       $P              = hasPane ? $Ps[pane] : 0
1137                 ;
1138                 if (hasPane && !$P) // a pane is specified, but does not exist!
1139                         return retVal;
1140                 if ( !hasPane && $.type(pane) === "boolean" ) {
1141                         skipBoundEvents = pane; // allow pane param to be skipped for Layout callback
1142                         pane = "";
1143                 }
1144
1145                 // first trigger the callback set in the options
1146                 if (fn) {
1147                         try {
1148                                 // convert function name (string) to function object
1149                                 if (isStr( fn )) {
1150                                         if (fn.match(/,/)) {
1151                                                 // function name cannot contain a comma, 
1152                                                 // so must be a function name AND a parameter to pass
1153                                                 args = fn.split(",")
1154                                                 ,       fn = eval(args[0]);
1155                                         }
1156                                         else // just the name of an external function?
1157                                                 fn = eval(fn);
1158                                 }
1159                                 // execute the callback, if exists
1160                                 if ($.isFunction( fn )) {
1161                                         if (args.length)
1162                                                 retVal = g(fn)(args[1]); // pass the argument parsed from 'list'
1163                                         else if ( hasPane )
1164                                                 // pass data: pane-name, pane-element, pane-state, pane-options, and layout-name
1165                                                 retVal = g(fn)( pane, $Ps[pane], s, o, lName );
1166                                         else // must be a layout/container callback - pass suitable info
1167                                                 retVal = g(fn)( Instance, s, o, lName );
1168                                 }
1169                         }
1170                         catch (ex) {
1171                                 _log( options.errors.callbackError.replace(/EVENT/, $.trim((pane || "") +" "+ lng)), false );
1172                                 if ($.type(ex) === "string" && string.length)
1173                                         _log("Exception:  "+ ex, false );
1174                         }
1175                 }
1176
1177                 // trigger additional events bound directly to the pane
1178                 if (!skipBoundEvents && retVal !== false) {
1179                         if ( hasPane ) { // PANE events can be bound to each pane-elements
1180                                 o       = options[pane];
1181                                 s       = state[pane];
1182                                 $P.triggerHandler("layoutpane"+ lng, [ pane, $P, s, o, lName ]);
1183                                 if (shrt)
1184                                         $P.triggerHandler("layoutpane"+ shrt, [ pane, $P, s, o, lName ]);
1185                         }
1186                         else { // LAYOUT events can be bound to the container-element
1187                                 $N.triggerHandler("layout"+ lng, [ Instance, s, o, lName ]);
1188                                 if (shrt)
1189                                         $N.triggerHandler("layout"+ shrt, [ Instance, s, o, lName ]);
1190                         }
1191                 }
1192
1193                 // ALWAYS resizeChildren after an onresize_end event - even during initialization
1194                 // IGNORE onsizecontent_end event because causes child-layouts to resize TWICE
1195                 if (hasPane && evtName === "onresize_end") // BAD: || evtName === "onsizecontent_end"
1196                         resizeChildren(pane+"", true); // compiler hack -force string
1197
1198                 return retVal;
1199
1200                 function g (f) { return f; }; // compiler hack
1201         }
1202
1203
1204         /**
1205          * cure iframe display issues in IE & other browsers
1206          */
1207 ,       _fixIframe = function (pane) {
1208                 if (browser.mozilla) return; // skip FireFox - it auto-refreshes iframes onShow
1209                 var $P = $Ps[pane];
1210                 // if the 'pane' is an iframe, do it
1211                 if (state[pane].tagName === "IFRAME")
1212                         $P.css(_c.hidden).css(_c.visible); 
1213                 else // ditto for any iframes INSIDE the pane
1214                         $P.find('IFRAME').css(_c.hidden).css(_c.visible);
1215         }
1216
1217         /**
1218          * @param  {string}             pane            Can accept ONLY a 'pane' (east, west, etc)
1219          * @param  {number=}            outerSize       (optional) Can pass a width, allowing calculations BEFORE element is resized
1220          * @return {number}             Returns the innerHeight/Width of el by subtracting padding and borders
1221          */
1222 ,       cssSize = function (pane, outerSize) {
1223                 var fn = _c[pane].dir=="horz" ? cssH : cssW;
1224                 return fn($Ps[pane], outerSize);
1225         }
1226
1227         /**
1228          * @param  {string}             pane            Can accept ONLY a 'pane' (east, west, etc)
1229          * @return {Object}             Returns hash of minWidth & minHeight
1230          */
1231 ,       cssMinDims = function (pane) {
1232                 // minWidth/Height means CSS width/height = 1px
1233                 var     $P      = $Ps[pane]
1234                 ,       dir     = _c[pane].dir
1235                 ,       d       = {
1236                                 minWidth:       1001 - cssW($P, 1000)
1237                         ,       minHeight:      1001 - cssH($P, 1000)
1238                         }
1239                 ;
1240                 if (dir === "horz") d.minSize = d.minHeight;
1241                 if (dir === "vert") d.minSize = d.minWidth;
1242                 return d;
1243         }
1244
1245         // TODO: see if these methods can be made more useful...
1246         // TODO: *maybe* return cssW/H from these so caller can use this info
1247
1248         /**
1249          * @param {(string|!Object)}            el
1250          * @param {number=}                             outerWidth
1251          * @param {boolean=}                            [autoHide=false]
1252          */
1253 ,       setOuterWidth = function (el, outerWidth, autoHide) {
1254                 var $E = el, w;
1255                 if (isStr(el)) $E = $Ps[el]; // west
1256                 else if (!el.jquery) $E = $(el);
1257                 w = cssW($E, outerWidth);
1258                 $E.css({ width: w });
1259                 if (w > 0) {
1260                         if (autoHide && $E.data('autoHidden') && $E.innerHeight() > 0) {
1261                                 $E.show().data('autoHidden', false);
1262                                 if (!browser.mozilla) // FireFox refreshes iframes - IE does not
1263                                         // make hidden, then visible to 'refresh' display after animation
1264                                         $E.css(_c.hidden).css(_c.visible);
1265                         }
1266                 }
1267                 else if (autoHide && !$E.data('autoHidden'))
1268                         $E.hide().data('autoHidden', true);
1269         }
1270
1271         /**
1272          * @param {(string|!Object)}            el
1273          * @param {number=}                             outerHeight
1274          * @param {boolean=}                            [autoHide=false]
1275          */
1276 ,       setOuterHeight = function (el, outerHeight, autoHide) {
1277                 var $E = el, h;
1278                 if (isStr(el)) $E = $Ps[el]; // west
1279                 else if (!el.jquery) $E = $(el);
1280                 h = cssH($E, outerHeight);
1281                 $E.css({ height: h, visibility: "visible" }); // may have been 'hidden' by sizeContent
1282                 if (h > 0 && $E.innerWidth() > 0) {
1283                         if (autoHide && $E.data('autoHidden')) {
1284                                 $E.show().data('autoHidden', false);
1285                                 if (!browser.mozilla) // FireFox refreshes iframes - IE does not
1286                                         $E.css(_c.hidden).css(_c.visible);
1287                         }
1288                 }
1289                 else if (autoHide && !$E.data('autoHidden'))
1290                         $E.hide().data('autoHidden', true);
1291         }
1292
1293
1294         /**
1295          * Converts any 'size' params to a pixel/integer size, if not already
1296          * If 'auto' or a decimal/percentage is passed as 'size', a pixel-size is calculated
1297          *
1298         /**
1299          * @param  {string}                             pane
1300          * @param  {(string|number)=}   size
1301          * @param  {string=}                            [dir]
1302          * @return {number}
1303          */
1304 ,       _parseSize = function (pane, size, dir) {
1305                 if (!dir) dir = _c[pane].dir;
1306
1307                 if (isStr(size) && size.match(/%/))
1308                         size = (size === '100%') ? -1 : parseInt(size, 10) / 100; // convert % to decimal
1309
1310                 if (size === 0)
1311                         return 0;
1312                 else if (size >= 1)
1313                         return parseInt(size, 10);
1314
1315                 var o = options, avail = 0;
1316                 if (dir=="horz") // north or south or center.minHeight
1317                         avail = sC.innerHeight - ($Ps.north ? o.north.spacing_open : 0) - ($Ps.south ? o.south.spacing_open : 0);
1318                 else if (dir=="vert") // east or west or center.minWidth
1319                         avail = sC.innerWidth - ($Ps.west ? o.west.spacing_open : 0) - ($Ps.east ? o.east.spacing_open : 0);
1320
1321                 if (size === -1) // -1 == 100%
1322                         return avail;
1323                 else if (size > 0) // percentage, eg: .25
1324                         return round(avail * size);
1325                 else if (pane=="center")
1326                         return 0;
1327                 else { // size < 0 || size=='auto' || size==Missing || size==Invalid
1328                         // auto-size the pane
1329                         var     dim     = (dir === "horz" ? "height" : "width")
1330                         ,       $P      = $Ps[pane]
1331                         ,       $C      = dim === 'height' ? $Cs[pane] : false
1332                         ,       vis     = $.layout.showInvisibly($P) // show pane invisibly if hidden
1333                         ,       szP     = $P.css(dim) // SAVE current pane size
1334                         ,       szC     = $C ? $C.css(dim) : 0 // SAVE current content size
1335                         ;
1336                         $P.css(dim, "auto");
1337                         if ($C) $C.css(dim, "auto");
1338                         size = (dim === "height") ? $P.outerHeight() : $P.outerWidth(); // MEASURE
1339                         $P.css(dim, szP).css(vis); // RESET size & visibility
1340                         if ($C) $C.css(dim, szC);
1341                         return size;
1342                 }
1343         }
1344
1345         /**
1346          * Calculates current 'size' (outer-width or outer-height) of a border-pane - optionally with 'pane-spacing' added
1347          *
1348          * @param  {(string|!Object)}   pane
1349          * @param  {boolean=}                   [inclSpace=false]
1350          * @return {number}                             Returns EITHER Width for east/west panes OR Height for north/south panes
1351          */
1352 ,       getPaneSize = function (pane, inclSpace) {
1353                 var 
1354                         $P      = $Ps[pane]
1355                 ,       o       = options[pane]
1356                 ,       s       = state[pane]
1357                 ,       oSp     = (inclSpace ? o.spacing_open : 0)
1358                 ,       cSp     = (inclSpace ? o.spacing_closed : 0)
1359                 ;
1360                 if (!$P || s.isHidden)
1361                         return 0;
1362                 else if (s.isClosed || (s.isSliding && inclSpace))
1363                         return cSp;
1364                 else if (_c[pane].dir === "horz")
1365                         return $P.outerHeight() + oSp;
1366                 else // dir === "vert"
1367                         return $P.outerWidth() + oSp;
1368         }
1369
1370         /**
1371          * Calculate min/max pane dimensions and limits for resizing
1372          *
1373          * @param  {string}             pane
1374          * @param  {boolean=}   [slide=false]
1375          */
1376 ,       setSizeLimits = function (pane, slide) {
1377                 if (!isInitialized()) return;
1378                 var 
1379                         o                               = options[pane]
1380                 ,       s                               = state[pane]
1381                 ,       c                               = _c[pane]
1382                 ,       dir                             = c.dir
1383                 ,       type                    = c.sizeType.toLowerCase()
1384                 ,       isSliding               = (slide != undefined ? slide : s.isSliding) // only open() passes 'slide' param
1385                 ,       $P                              = $Ps[pane]
1386                 ,       paneSpacing             = o.spacing_open
1387                 //      measure the pane on the *opposite side* from this pane
1388                 ,       altPane                 = _c.oppositeEdge[pane]
1389                 ,       altS                    = state[altPane]
1390                 ,       $altP                   = $Ps[altPane]
1391                 ,       altPaneSize             = (!$altP || altS.isVisible===false || altS.isSliding ? 0 : (dir=="horz" ? $altP.outerHeight() : $altP.outerWidth()))
1392                 ,       altPaneSpacing  = ((!$altP || altS.isHidden ? 0 : options[altPane][ altS.isClosed !== false ? "spacing_closed" : "spacing_open" ]) || 0)
1393                 //      limitSize prevents this pane from 'overlapping' opposite pane
1394                 ,       containerSize   = (dir=="horz" ? sC.innerHeight : sC.innerWidth)
1395                 ,       minCenterDims   = cssMinDims("center")
1396                 ,       minCenterSize   = dir=="horz" ? max(options.center.minHeight, minCenterDims.minHeight) : max(options.center.minWidth, minCenterDims.minWidth)
1397                 //      if pane is 'sliding', then ignore center and alt-pane sizes - because 'overlays' them
1398                 ,       limitSize               = (containerSize - paneSpacing - (isSliding ? 0 : (_parseSize("center", minCenterSize, dir) + altPaneSize + altPaneSpacing)))
1399                 ,       minSize                 = s.minSize = max( _parseSize(pane, o.minSize), cssMinDims(pane).minSize )
1400                 ,       maxSize                 = s.maxSize = min( (o.maxSize ? _parseSize(pane, o.maxSize) : 100000), limitSize )
1401                 ,       r                               = s.resizerPosition = {} // used to set resizing limits
1402                 ,       top                             = sC.inset.top
1403                 ,       left                    = sC.inset.left
1404                 ,       W                               = sC.innerWidth
1405                 ,       H                               = sC.innerHeight
1406                 ,       rW                              = o.spacing_open // subtract resizer-width to get top/left position for south/east
1407                 ;
1408                 switch (pane) {
1409                         case "north":   r.min = top + minSize;
1410                                                         r.max = top + maxSize;
1411                                                         break;
1412                         case "west":    r.min = left + minSize;
1413                                                         r.max = left + maxSize;
1414                                                         break;
1415                         case "south":   r.min = top + H - maxSize - rW;
1416                                                         r.max = top + H - minSize - rW;
1417                                                         break;
1418                         case "east":    r.min = left + W - maxSize - rW;
1419                                                         r.max = left + W - minSize - rW;
1420                                                         break;
1421                 };
1422         }
1423
1424         /**
1425          * Returns data for setting the size/position of center pane. Also used to set Height for east/west panes
1426          *
1427          * @return JSON  Returns a hash of all dimensions: top, bottom, left, right, (outer) width and (outer) height
1428          */
1429 ,       calcNewCenterPaneDims = function () {
1430                 var d = {
1431                         top:    getPaneSize("north", true) // true = include 'spacing' value for pane
1432                 ,       bottom: getPaneSize("south", true)
1433                 ,       left:   getPaneSize("west", true)
1434                 ,       right:  getPaneSize("east", true)
1435                 ,       width:  0
1436                 ,       height: 0
1437                 };
1438
1439                 // NOTE: sC = state.container
1440                 // calc center-pane outer dimensions
1441                 d.width         = sC.innerWidth - d.left - d.right;  // outerWidth
1442                 d.height        = sC.innerHeight - d.bottom - d.top; // outerHeight
1443                 // add the 'container border/padding' to get final positions relative to the container
1444                 d.top           += sC.inset.top;
1445                 d.bottom        += sC.inset.bottom;
1446                 d.left          += sC.inset.left;
1447                 d.right         += sC.inset.right;
1448
1449                 return d;
1450         }
1451
1452
1453         /**
1454          * @param {!Object}             el
1455          * @param {boolean=}            [allStates=false]
1456          */
1457 ,       getHoverClasses = function (el, allStates) {
1458                 var
1459                         $El             = $(el)
1460                 ,       type    = $El.data("layoutRole")
1461                 ,       pane    = $El.data("layoutEdge")
1462                 ,       o               = options[pane]
1463                 ,       root    = o[type +"Class"]
1464                 ,       _pane   = "-"+ pane // eg: "-west"
1465                 ,       _open   = "-open"
1466                 ,       _closed = "-closed"
1467                 ,       _slide  = "-sliding"
1468                 ,       _hover  = "-hover " // NOTE the trailing space
1469                 ,       _state  = $El.hasClass(root+_closed) ? _closed : _open
1470                 ,       _alt    = _state === _closed ? _open : _closed
1471                 ,       classes = (root+_hover) + (root+_pane+_hover) + (root+_state+_hover) + (root+_pane+_state+_hover)
1472                 ;
1473                 if (allStates) // when 'removing' classes, also remove alternate-state classes
1474                         classes += (root+_alt+_hover) + (root+_pane+_alt+_hover);
1475
1476                 if (type=="resizer" && $El.hasClass(root+_slide))
1477                         classes += (root+_slide+_hover) + (root+_pane+_slide+_hover);
1478
1479                 return $.trim(classes);
1480         }
1481 ,       addHover        = function (evt, el) {
1482                 var $E = $(el || this);
1483                 if (evt && $E.data("layoutRole") === "toggler")
1484                         evt.stopPropagation(); // prevent triggering 'slide' on Resizer-bar
1485                 $E.addClass( getHoverClasses($E) );
1486         }
1487 ,       removeHover     = function (evt, el) {
1488                 var $E = $(el || this);
1489                 $E.removeClass( getHoverClasses($E, true) );
1490         }
1491
1492 ,       onResizerEnter  = function (evt) { // ALSO called by toggler.mouseenter
1493                 var pane        = $(this).data("layoutEdge")
1494                 ,       s               = state[pane]
1495                 ,       $d              = $(document)
1496                 ;
1497                 // ignore closed-panes and mouse moving back & forth over resizer!
1498                 // also ignore if ANY pane is currently resizing
1499                 if ( s.isResizing || state.paneResizing ) return;
1500
1501                 if (options.maskPanesEarly)
1502                         showMasks( pane, { resizing: true });
1503         }
1504 ,       onResizerLeave  = function (evt, el) {
1505                 var     e               = el || this // el is only passed when called by the timer
1506                 ,       pane    = $(e).data("layoutEdge")
1507                 ,       name    = pane +"ResizerLeave"
1508                 ,       $d              = $(document)
1509                 ;
1510                 timer.clear(pane+"_openSlider"); // cancel slideOpen timer, if set
1511                 timer.clear(name); // cancel enableSelection timer - may re/set below
1512                 // this method calls itself on a timer because it needs to allow
1513                 // enough time for dragging to kick-in and set the isResizing flag
1514                 // dragging has a 100ms delay set, so this delay must be >100
1515                 if (!el) // 1st call - mouseleave event
1516                         timer.set(name, function(){ onResizerLeave(evt, e); }, 200);
1517                 // if user is resizing, dragStop will reset everything, so skip it here
1518                 else if (options.maskPanesEarly && !state.paneResizing) // 2nd call - by timer
1519                         hideMasks();
1520         }
1521
1522 /*
1523  * ###########################
1524  *   INITIALIZATION METHODS
1525  * ###########################
1526  */
1527
1528         /**
1529          * Initialize the layout - called automatically whenever an instance of layout is created
1530          *
1531          * @see  none - triggered onInit
1532          * @return  mixed       true = fully initialized | false = panes not initialized (yet) | 'cancel' = abort
1533          */
1534 ,       _create = function () {
1535                 // initialize config/options
1536                 initOptions();
1537                 var o = options
1538                 ,       s = state;
1539
1540                 // TEMP state so isInitialized returns true during init process
1541                 s.creatingLayout = true;
1542
1543                 // init plugins for this layout, if there are any (eg: stateManagement)
1544                 runPluginCallbacks( Instance, $.layout.onCreate );
1545
1546                 // options & state have been initialized, so now run beforeLoad callback
1547                 // onload will CANCEL layout creation if it returns false
1548                 if (false === _runCallbacks("onload_start"))
1549                         return 'cancel';
1550
1551                 // initialize the container element
1552                 _initContainer();
1553
1554                 // bind hotkey function - keyDown - if required
1555                 initHotkeys();
1556
1557                 // bind window.onunload
1558                 $(window).bind("unload."+ sID, unload);
1559
1560                 // init plugins for this layout, if there are any (eg: customButtons)
1561                 runPluginCallbacks( Instance, $.layout.onLoad );
1562
1563                 // if layout elements are hidden, then layout WILL NOT complete initialization!
1564                 // initLayoutElements will set initialized=true and run the onload callback IF successful
1565                 if (o.initPanes) _initLayoutElements();
1566
1567                 delete s.creatingLayout;
1568
1569                 return state.initialized;
1570         }
1571
1572         /**
1573          * Initialize the layout IF not already
1574          *
1575          * @see  All methods in Instance run this test
1576          * @return  boolean     true = layoutElements have been initialized | false = panes are not initialized (yet)
1577          */
1578 ,       isInitialized = function () {
1579                 if (state.initialized || state.creatingLayout) return true;     // already initialized
1580                 else return _initLayoutElements();      // try to init panes NOW
1581         }
1582
1583         /**
1584          * Initialize the layout - called automatically whenever an instance of layout is created
1585          *
1586          * @see  _create() & isInitialized
1587          * @param {boolean=}            [retry=false]   // indicates this is a 2nd try
1588          * @return  An object pointer to the instance created
1589          */
1590 ,       _initLayoutElements = function (retry) {
1591                 // initialize config/options
1592                 var o = options;
1593                 // CANNOT init panes inside a hidden container!
1594                 if (!$N.is(":visible")) {
1595                         // handle Chrome bug where popup window 'has no height'
1596                         // if layout is BODY element, try again in 50ms
1597                         // SEE: http://layout.jquery-dev.com/samples/test_popup_window.html
1598                         if ( !retry && browser.webkit && $N[0].tagName === "BODY" )
1599                                 setTimeout(function(){ _initLayoutElements(true); }, 50);
1600                         return false;
1601                 }
1602
1603                 // a center pane is required, so make sure it exists
1604                 if (!getPane("center").length) {
1605                         return _log( o.errors.centerPaneMissing );
1606                 }
1607
1608                 // TEMP state so isInitialized returns true during init process
1609                 state.creatingLayout = true;
1610
1611                 // update Container dims
1612                 $.extend(sC, elDims( $N, o.inset )); // passing inset means DO NOT include insetX values
1613
1614                 // initialize all layout elements
1615                 initPanes();    // size & position panes - calls initHandles() - which calls initResizable()
1616
1617                 if (o.scrollToBookmarkOnLoad) {
1618                         var l = self.location;
1619                         if (l.hash) l.replace( l.hash ); // scrollTo Bookmark
1620                 }
1621
1622                 // check to see if this layout 'nested' inside a pane
1623                 if (Instance.hasParentLayout)
1624                         o.resizeWithWindow = false;
1625                 // bind resizeAll() for 'this layout instance' to window.resize event
1626                 else if (o.resizeWithWindow)
1627                         $(window).bind("resize."+ sID, windowResize);
1628
1629                 delete state.creatingLayout;
1630                 state.initialized = true;
1631
1632                 // init plugins for this layout, if there are any
1633                 runPluginCallbacks( Instance, $.layout.onReady );
1634
1635                 // now run the onload callback, if exists
1636                 _runCallbacks("onload_end");
1637
1638                 return true; // elements initialized successfully
1639         }
1640
1641         /**
1642          * Initialize nested layouts for a specific pane - can optionally pass layout-options
1643          *
1644          * @param {(string|Object)}     evt_or_pane     The pane being opened, ie: north, south, east, or west
1645          * @param {Object=}                     [opts]          Layout-options - if passed, will OVERRRIDE options[pane].children
1646          * @return  An object pointer to the layout instance created - or null
1647          */
1648 ,       createChildren = function (evt_or_pane, opts) {
1649                 var     pane = evtPane.call(this, evt_or_pane)
1650                 ,       $P      = $Ps[pane]
1651                 ;
1652                 if (!$P) return;
1653                 var     $C      = $Cs[pane]
1654                 ,       s       = state[pane]
1655                 ,       o       = options[pane]
1656                 ,       sm      = options.stateManagement || {}
1657                 ,       cos = opts ? (o.children = opts) : o.children
1658                 ;
1659                 if ( $.isPlainObject( cos ) )
1660                         cos = [ cos ]; // convert a hash to a 1-elem array
1661                 else if (!cos || !$.isArray( cos ))
1662                         return;
1663
1664                 $.each( cos, function (idx, co) {
1665                         if ( !$.isPlainObject( co ) ) return;
1666
1667                         // determine which element is supposed to be the 'child container'
1668                         // if pane has a 'containerSelector' OR a 'content-div', use those instead of the pane
1669                         var $containers = co.containerSelector ? $P.find( co.containerSelector ) : ($C || $P);
1670
1671                         $containers.each(function(){
1672                                 var $cont       = $(this)
1673                                 ,       child   = $cont.data("layout") //       see if a child-layout ALREADY exists on this element
1674                                 ;
1675                                 // if no layout exists, but children are set, try to create the layout now
1676                                 if (!child) {
1677                                         // TODO: see about moving this to the stateManagement plugin, as a method
1678                                         // set a unique child-instance key for this layout, if not already set
1679                                         setInstanceKey({ container: $cont, options: co }, s );
1680                                         // If THIS layout has a hash in stateManagement.autoLoad,
1681                                         // then see if it also contains state-data for this child-layout
1682                                         // If so, copy the stateData to child.options.stateManagement.autoLoad
1683                                         if ( sm.includeChildren && state.stateData[pane] ) {
1684                                                 //      THIS layout's state was cached when its state was loaded
1685                                                 var     paneChildren = state.stateData[pane].children || {}
1686                                                 ,       childState      = paneChildren[ co.instanceKey ]
1687                                                 ,       co_sm           = co.stateManagement || (co.stateManagement = { autoLoad: true })
1688                                                 ;
1689                                                 // COPY the stateData into the autoLoad key
1690                                                 if ( co_sm.autoLoad === true && childState ) {
1691                                                         co_sm.autoSave                  = false; // disable autoSave because saving handled by parent-layout
1692                                                         co_sm.includeChildren   = true;  // cascade option - FOR NOW
1693                                                         co_sm.autoLoad = $.extend(true, {}, childState); // COPY the state-hash
1694                                                 }
1695                                         }
1696
1697                                         // create the layout
1698                                         child = $cont.layout( co );
1699
1700                                         // if successful, update data
1701                                         if (child) {
1702                                                 // add the child and update all layout-pointers
1703                                                 // MAY have already been done by child-layout calling parent.refreshChildren()
1704                                                 refreshChildren( pane, child );
1705                                         }
1706                                 }
1707                         });
1708                 });
1709         }
1710
1711 ,       setInstanceKey = function (child, parentPaneState) {
1712                 // create a named key for use in state and instance branches
1713                 var     $c      = child.container
1714                 ,       o       = child.options
1715                 ,       sm      = o.stateManagement
1716                 ,       key     = o.instanceKey || $c.data("layoutInstanceKey")
1717                 ;
1718                 if (!key) key = (sm && sm.cookie ? sm.cookie.name : '') || o.name; // look for a name/key
1719                 if (!key) key = "layout"+ (++parentPaneState.childIdx); // if no name/key found, generate one
1720                 else key = key.replace(/[^\w-]/gi, '_').replace(/_{2,}/g, '_');  // ensure is valid as a hash key
1721                 o.instanceKey = key;
1722                 $c.data("layoutInstanceKey", key); // useful if layout is destroyed and then recreated
1723                 return key;
1724         }
1725
1726         /**
1727          * @param {string}              pane            The pane being opened, ie: north, south, east, or west
1728          * @param {Object=}             newChild        New child-layout Instance to add to this pane
1729          */
1730 ,       refreshChildren = function (pane, newChild) {
1731                 var     $P      = $Ps[pane]
1732                 ,       pC      = children[pane]
1733                 ,       s       = state[pane]
1734                 ,       o
1735                 ;
1736                 // check for destroy()ed layouts and update the child pointers & arrays
1737                 if ($.isPlainObject( pC )) {
1738                         $.each( pC, function (key, child) {
1739                                 if (child.destroyed) delete pC[key]
1740                         });
1741                         // if no more children, remove the children hash
1742                         if ($.isEmptyObject( pC ))
1743                                 pC = children[pane] = null; // clear children hash
1744                 }
1745
1746                 // see if there is a directly-nested layout inside this pane
1747                 // if there is, then there can be only ONE child-layout, so check that...
1748                 if (!newChild && !pC) {
1749                         newChild = $P.data("layout");
1750                 }
1751
1752                 // if a newChild instance was passed, add it to children[pane]
1753                 if (newChild) {
1754                         // update child.state
1755                         newChild.hasParentLayout = true; // set parent-flag in child
1756                         // instanceKey is a key-name used in both state and children
1757                         o = newChild.options;
1758                         // set a unique child-instance key for this layout, if not already set
1759                         setInstanceKey( newChild, s );
1760                         // add pointer to pane.children hash
1761                         if (!pC) pC = children[pane] = {}; // create an empty children hash
1762                         pC[ o.instanceKey ] = newChild.container.data("layout"); // add childLayout instance
1763                 }
1764
1765                 // ALWAYS refresh the pane.children alias, even if null
1766                 Instance[pane].children = children[pane];
1767
1768                 // if newChild was NOT passed - see if there is a child layout NOW
1769                 if (!newChild) {
1770                         createChildren(pane); // MAY create a child and re-call this method
1771                 }
1772         }
1773
1774 ,       windowResize = function () {
1775                 var     o = options
1776                 ,       delay = Number(o.resizeWithWindowDelay);
1777                 if (delay < 10) delay = 100; // MUST have a delay!
1778                 // resizing uses a delay-loop because the resize event fires repeatly - except in FF, but delay anyway
1779                 timer.clear("winResize"); // if already running
1780                 timer.set("winResize", function(){
1781                         timer.clear("winResize");
1782                         timer.clear("winResizeRepeater");
1783                         var dims = elDims( $N, o.inset );
1784                         // only trigger resizeAll() if container has changed size
1785                         if (dims.innerWidth !== sC.innerWidth || dims.innerHeight !== sC.innerHeight)
1786                                 resizeAll();
1787                 }, delay);
1788                 // ALSO set fixed-delay timer, if not already running
1789                 if (!timer.data["winResizeRepeater"]) setWindowResizeRepeater();
1790         }
1791
1792 ,       setWindowResizeRepeater = function () {
1793                 var delay = Number(options.resizeWithWindowMaxDelay);
1794                 if (delay > 0)
1795                         timer.set("winResizeRepeater", function(){ setWindowResizeRepeater(); resizeAll(); }, delay);
1796         }
1797
1798 ,       unload = function () {
1799                 var o = options;
1800
1801                 _runCallbacks("onunload_start");
1802
1803                 // trigger plugin callabacks for this layout (eg: stateManagement)
1804                 runPluginCallbacks( Instance, $.layout.onUnload );
1805
1806                 _runCallbacks("onunload_end");
1807         }
1808
1809         /**
1810          * Validate and initialize container CSS and events
1811          *
1812          * @see  _create()
1813          */
1814 ,       _initContainer = function () {
1815                 var
1816                         N               = $N[0] 
1817                 ,       $H              = $("html")
1818                 ,       tag             = sC.tagName = N.tagName
1819                 ,       id              = sC.id = N.id
1820                 ,       cls             = sC.className = N.className
1821                 ,       o               = options
1822                 ,       name    = o.name
1823                 ,       props   = "position,margin,padding,border"
1824                 ,       css             = "layoutCSS"
1825                 ,       CSS             = {}
1826                 ,       hid             = "hidden" // used A LOT!
1827                 //      see if this container is a 'pane' inside an outer-layout
1828                 ,       parent  = $N.data("parentLayout")       // parent-layout Instance
1829                 ,       pane    = $N.data("layoutEdge")         // pane-name in parent-layout
1830                 ,       isChild = parent && pane
1831                 ,       num             = $.layout.cssNum
1832                 ,       $parent, n
1833                 ;
1834                 // sC = state.container
1835                 sC.selector = $N.selector.split(".slice")[0];
1836                 sC.ref          = (o.name ? o.name +' layout / ' : '') + tag + (id ? "#"+id : cls ? '.['+cls+']' : ''); // used in messages
1837                 sC.isBody       = (tag === "BODY");
1838
1839                 // try to find a parent-layout
1840                 if (!isChild && !sC.isBody) {
1841                         $parent = $N.closest("."+ $.layout.defaults.panes.paneClass);
1842                         parent  = $parent.data("parentLayout");
1843                         pane    = $parent.data("layoutEdge");
1844                         isChild = parent && pane;
1845                 }
1846
1847                 $N      .data({
1848                                 layout: Instance
1849                         ,       layoutContainer: sID // FLAG to indicate this is a layout-container - contains unique internal ID
1850                         })
1851                         .addClass(o.containerClass)
1852                 ;
1853                 var layoutMethods = {
1854                         destroy:        ''
1855                 ,       initPanes:      ''
1856                 ,       resizeAll:      'resizeAll'
1857                 ,       resize:         'resizeAll'
1858                 };
1859                 // loop hash and bind all methods - include layoutID namespacing
1860                 for (name in layoutMethods) {
1861                         $N.bind("layout"+ name.toLowerCase() +"."+ sID, Instance[ layoutMethods[name] || name ]);
1862                 }
1863
1864                 // if this container is another layout's 'pane', then set child/parent pointers
1865                 if (isChild) {
1866                         // update parent flag
1867                         Instance.hasParentLayout = true;
1868                         // set pointers to THIS child-layout (Instance) in parent-layout
1869                         parent.refreshChildren( pane, Instance );
1870                 }
1871
1872                 // SAVE original container CSS for use in destroy()
1873                 if (!$N.data(css)) {
1874                         // handle props like overflow different for BODY & HTML - has 'system default' values
1875                         if (sC.isBody) {
1876                                 // SAVE <BODY> CSS
1877                                 $N.data(css, $.extend( styles($N, props), {
1878                                         height:         $N.css("height")
1879                                 ,       overflow:       $N.css("overflow")
1880                                 ,       overflowX:      $N.css("overflowX")
1881                                 ,       overflowY:      $N.css("overflowY")
1882                                 }));
1883                                 // ALSO SAVE <HTML> CSS
1884                                 $H.data(css, $.extend( styles($H, 'padding'), {
1885                                         height:         "auto" // FF would return a fixed px-size!
1886                                 ,       overflow:       $H.css("overflow")
1887                                 ,       overflowX:      $H.css("overflowX")
1888                                 ,       overflowY:      $H.css("overflowY")
1889                                 }));
1890                         }
1891                         else // handle props normally for non-body elements
1892                                 $N.data(css, styles($N, props+",top,bottom,left,right,width,height,overflow,overflowX,overflowY") );
1893                 }
1894
1895                 try {
1896                         // common container CSS
1897                         CSS = {
1898                                 overflow:       hid
1899                         ,       overflowX:      hid
1900                         ,       overflowY:      hid
1901                         };
1902                         $N.css( CSS );
1903
1904                         if (o.inset && !$.isPlainObject(o.inset)) {
1905                                 // can specify a single number for equal outset all-around
1906                                 n = parseInt(o.inset, 10) || 0
1907                                 o.inset = {
1908                                         top:    n
1909                                 ,       bottom: n
1910                                 ,       left:   n
1911                                 ,       right:  n
1912                                 };
1913                         }
1914
1915                         // format html & body if this is a full page layout
1916                         if (sC.isBody) {
1917                                 // if HTML has padding, use this as an outer-spacing around BODY
1918                                 if (!o.outset) {
1919                                         // use padding from parent-elem (HTML) as outset
1920                                         o.outset = {
1921                                                 top:    num($H, "paddingTop")
1922                                         ,       bottom: num($H, "paddingBottom")
1923                                         ,       left:   num($H, "paddingLeft")
1924                                         ,       right:  num($H, "paddingRight")
1925                                         };
1926                                 }
1927                                 else if (!$.isPlainObject(o.outset)) {
1928                                         // can specify a single number for equal outset all-around
1929                                         n = parseInt(o.outset, 10) || 0
1930                                         o.outset = {
1931                                                 top:    n
1932                                         ,       bottom: n
1933                                         ,       left:   n
1934                                         ,       right:  n
1935                                         };
1936                                 }
1937                                 // HTML
1938                                 $H.css( CSS ).css({
1939                                         height:         "100%"
1940                                 ,       border:         "none"  // no border or padding allowed when using height = 100%
1941                                 ,       padding:        0               // ditto
1942                                 ,       margin:         0
1943                                 });
1944                                 // BODY
1945                                 if (browser.isIE6) {
1946                                         // IE6 CANNOT use the trick of setting absolute positioning on all 4 sides - must have 'height'
1947                                         $N.css({
1948                                                 width:          "100%"
1949                                         ,       height:         "100%"
1950                                         ,       border:         "none"  // no border or padding allowed when using height = 100%
1951                                         ,       padding:        0               // ditto
1952                                         ,       margin:         0
1953                                         ,       position:       "relative"
1954                                         });
1955                                         // convert body padding to an inset option - the border cannot be measured in IE6!
1956                                         if (!o.inset) o.inset = elDims( $N ).inset;
1957                                 }
1958                                 else { // use absolute positioning for BODY to allow borders & padding without overflow
1959                                         $N.css({
1960                                                 width:          "auto"
1961                                         ,       height:         "auto"
1962                                         ,       margin:         0
1963                                         ,       position:       "absolute"      // allows for border and padding on BODY
1964                                         });
1965                                         // apply edge-positioning created above
1966                                         $N.css( o.outset );
1967                                 }
1968                                 // set current layout-container dimensions
1969                                 $.extend(sC, elDims( $N, o.inset )); // passing inset means DO NOT include insetX values
1970                         }
1971                         else {
1972                                 // container MUST have 'position'
1973                                 var     p = $N.css("position");
1974                                 if (!p || !p.match(/(fixed|absolute|relative)/))
1975                                         $N.css("position","relative");
1976
1977                                 // set current layout-container dimensions
1978                                 if ( $N.is(":visible") ) {
1979                                         $.extend(sC, elDims( $N, o.inset )); // passing inset means DO NOT change insetX (padding) values
1980                                         if (sC.innerHeight < 1) // container has no 'height' - warn developer
1981                                                 _log( o.errors.noContainerHeight.replace(/CONTAINER/, sC.ref) );
1982                                 }
1983                         }
1984
1985                         // if container has min-width/height, then enable scrollbar(s)
1986                         if ( num($N, "minWidth")  ) $N.parent().css("overflowX","auto");
1987                         if ( num($N, "minHeight") ) $N.parent().css("overflowY","auto");
1988
1989                 } catch (ex) {}
1990         }
1991
1992         /**
1993          * Bind layout hotkeys - if options enabled
1994          *
1995          * @see  _create() and addPane()
1996          * @param {string=}     [panes=""]      The edge(s) to process
1997          */
1998 ,       initHotkeys = function (panes) {
1999                 panes = panes ? panes.split(",") : _c.borderPanes;
2000                 // bind keyDown to capture hotkeys, if option enabled for ANY pane
2001                 $.each(panes, function (i, pane) {
2002                         var o = options[pane];
2003                         if (o.enableCursorHotkey || o.customHotkey) {
2004                                 $(document).bind("keydown."+ sID, keyDown); // only need to bind this ONCE
2005                                 return false; // BREAK - binding was done
2006                         }
2007                 });
2008         }
2009
2010         /**
2011          * Build final OPTIONS data
2012          *
2013          * @see  _create()
2014          */
2015 ,       initOptions = function () {
2016                 var data, d, pane, key, val, i, c, o;
2017
2018                 // reprocess user's layout-options to have correct options sub-key structure
2019                 opts = $.layout.transformData( opts, true ); // panes = default subkey
2020
2021                 // auto-rename old options for backward compatibility
2022                 opts = $.layout.backwardCompatibility.renameAllOptions( opts );
2023
2024                 // if user-options has 'panes' key (pane-defaults), clean it...
2025                 if (!$.isEmptyObject(opts.panes)) {
2026                         // REMOVE any pane-defaults that MUST be set per-pane
2027                         data = $.layout.optionsMap.noDefault;
2028                         for (i=0, c=data.length; i<c; i++) {
2029                                 key = data[i];
2030                                 delete opts.panes[key]; // OK if does not exist
2031                         }
2032                         // REMOVE any layout-options specified under opts.panes
2033                         data = $.layout.optionsMap.layout;
2034                         for (i=0, c=data.length; i<c; i++) {
2035                                 key = data[i];
2036                                 delete opts.panes[key]; // OK if does not exist
2037                         }
2038                 }
2039
2040                 // MOVE any NON-layout-options from opts-root to opts.panes
2041                 data = $.layout.optionsMap.layout;
2042                 var rootKeys = $.layout.config.optionRootKeys;
2043                 for (key in opts) {
2044                         val = opts[key];
2045                         if ($.inArray(key, rootKeys) < 0 && $.inArray(key, data) < 0) {
2046                                 if (!opts.panes[key])
2047                                         opts.panes[key] = $.isPlainObject(val) ? $.extend(true, {}, val) : val;
2048                                 delete opts[key]
2049                         }
2050                 }
2051
2052                 // START by updating ALL options from opts
2053                 $.extend(true, options, opts);
2054
2055                 // CREATE final options (and config) for EACH pane
2056                 $.each(_c.allPanes, function (i, pane) {
2057
2058                         // apply 'pane-defaults' to CONFIG.[PANE]
2059                         _c[pane] = $.extend(true, {}, _c.panes, _c[pane]);
2060
2061                         d = options.panes;
2062                         o = options[pane];
2063
2064                         // center-pane uses SOME keys in defaults.panes branch
2065                         if (pane === 'center') {
2066                                 // ONLY copy keys from opts.panes listed in: $.layout.optionsMap.center
2067                                 data = $.layout.optionsMap.center;              // list of 'center-pane keys'
2068                                 for (i=0, c=data.length; i<c; i++) {    // loop the list...
2069                                         key = data[i];
2070                                         // only need to use pane-default if pane-specific value not set
2071                                         if (!opts.center[key] && (opts.panes[key] || !o[key]))
2072                                                 o[key] = d[key]; // pane-default
2073                                 }
2074                         }
2075                         else {
2076                                 // border-panes use ALL keys in defaults.panes branch
2077                                 o = options[pane] = $.extend(true, {}, d, o); // re-apply pane-specific opts AFTER pane-defaults
2078                                 createFxOptions( pane );
2079                                 // ensure all border-pane-specific base-classes exist
2080                                 if (!o.resizerClass)    o.resizerClass  = "ui-layout-resizer";
2081                                 if (!o.togglerClass)    o.togglerClass  = "ui-layout-toggler";
2082                         }
2083                         // ensure we have base pane-class (ALL panes)
2084                         if (!o.paneClass) o.paneClass = "ui-layout-pane";
2085                 });
2086
2087                 // update options.zIndexes if a zIndex-option specified
2088                 var zo  = opts.zIndex
2089                 ,       z       = options.zIndexes;
2090                 if (zo > 0) {
2091                         z.pane_normal           = zo;
2092                         z.content_mask          = max(zo+1, z.content_mask);    // MIN = +1
2093                         z.resizer_normal        = max(zo+2, z.resizer_normal);  // MIN = +2
2094                 }
2095
2096                 // DELETE 'panes' key now that we are done - values were copied to EACH pane
2097                 delete options.panes;
2098
2099
2100                 function createFxOptions ( pane ) {
2101                         var     o = options[pane]
2102                         ,       d = options.panes;
2103                         // ensure fxSettings key to avoid errors
2104                         if (!o.fxSettings) o.fxSettings = {};
2105                         if (!d.fxSettings) d.fxSettings = {};
2106
2107                         $.each(["_open","_close","_size"], function (i,n) { 
2108                                 var
2109                                         sName           = "fxName"+ n
2110                                 ,       sSpeed          = "fxSpeed"+ n
2111                                 ,       sSettings       = "fxSettings"+ n
2112                                         // recalculate fxName according to specificity rules
2113                                 ,       fxName = o[sName] =
2114                                                 o[sName]        // options.west.fxName_open
2115                                         ||      d[sName]        // options.panes.fxName_open
2116                                         ||      o.fxName        // options.west.fxName
2117                                         ||      d.fxName        // options.panes.fxName
2118                                         ||      "none"          // MEANS $.layout.defaults.panes.fxName == "" || false || null || 0
2119                                 ,       fxExists        = $.effects && ($.effects[fxName] || ($.effects.effect && $.effects.effect[fxName]))
2120                                 ;
2121                                 // validate fxName to ensure is valid effect - MUST have effect-config data in options.effects
2122                                 if (fxName === "none" || !options.effects[fxName] || !fxExists)
2123                                         fxName = o[sName] = "none"; // effect not loaded OR unrecognized fxName
2124
2125                                 // set vars for effects subkeys to simplify logic
2126                                 var     fx              = options.effects[fxName] || {} // effects.slide
2127                                 ,       fx_all  = fx.all        || null                         // effects.slide.all
2128                                 ,       fx_pane = fx[pane]      || null                         // effects.slide.west
2129                                 ;
2130                                 // create fxSpeed[_open|_close|_size]
2131                                 o[sSpeed] =
2132                                         o[sSpeed]                               // options.west.fxSpeed_open
2133                                 ||      d[sSpeed]                               // options.west.fxSpeed_open
2134                                 ||      o.fxSpeed                               // options.west.fxSpeed
2135                                 ||      d.fxSpeed                               // options.panes.fxSpeed
2136                                 ||      null                                    // DEFAULT - let fxSetting.duration control speed
2137                                 ;
2138                                 // create fxSettings[_open|_close|_size]
2139                                 o[sSettings] = $.extend(
2140                                         true
2141                                 ,       {}
2142                                 ,       fx_all                                  // effects.slide.all
2143                                 ,       fx_pane                                 // effects.slide.west
2144                                 ,       d.fxSettings                    // options.panes.fxSettings
2145                                 ,       o.fxSettings                    // options.west.fxSettings
2146                                 ,       d[sSettings]                    // options.panes.fxSettings_open
2147                                 ,       o[sSettings]                    // options.west.fxSettings_open
2148                                 );
2149                         });
2150
2151                         // DONE creating action-specific-settings for this pane,
2152                         // so DELETE generic options - are no longer meaningful
2153                         delete o.fxName;
2154                         delete o.fxSpeed;
2155                         delete o.fxSettings;
2156                 }
2157         }
2158
2159         /**
2160          * Initialize module objects, styling, size and position for all panes
2161          *
2162          * @see  _initElements()
2163          * @param {string}      pane            The pane to process
2164          */
2165 ,       getPane = function (pane) {
2166                 var sel = options[pane].paneSelector
2167                 if (sel.substr(0,1)==="#") // ID selector
2168                         // NOTE: elements selected 'by ID' DO NOT have to be 'children'
2169                         return $N.find(sel).eq(0);
2170                 else { // class or other selector
2171                         var $P = $N.children(sel).eq(0);
2172                         // look for the pane nested inside a 'form' element
2173                         return $P.length ? $P : $N.children("form:first").children(sel).eq(0);
2174                 }
2175         }
2176
2177         /**
2178          * @param {Object=}             evt
2179          */
2180 ,       initPanes = function (evt) {
2181                 // stopPropagation if called by trigger("layoutinitpanes") - use evtPane utility 
2182                 evtPane(evt);
2183
2184                 // NOTE: do north & south FIRST so we can measure their height - do center LAST
2185                 $.each(_c.allPanes, function (idx, pane) {
2186                         addPane( pane, true );
2187                 });
2188
2189                 // init the pane-handles NOW in case we have to hide or close the pane below
2190                 initHandles();
2191
2192                 // now that all panes have been initialized and initially-sized,
2193                 // make sure there is really enough space available for each pane
2194                 $.each(_c.borderPanes, function (i, pane) {
2195                         if ($Ps[pane] && state[pane].isVisible) { // pane is OPEN
2196                                 setSizeLimits(pane);
2197                                 makePaneFit(pane); // pane may be Closed, Hidden or Resized by makePaneFit()
2198                         }
2199                 });
2200                 // size center-pane AGAIN in case we 'closed' a border-pane in loop above
2201                 sizeMidPanes("center");
2202
2203                 //      Chrome/Webkit sometimes fires callbacks BEFORE it completes resizing!
2204                 //      Before RC30.3, there was a 10ms delay here, but that caused layout 
2205                 //      to load asynchrously, which is BAD, so try skipping delay for now
2206
2207                 // process pane contents and callbacks, and init/resize child-layout if exists
2208                 $.each(_c.allPanes, function (idx, pane) {
2209                         afterInitPane(pane);
2210                 });
2211         }
2212
2213         /**
2214          * Add a pane to the layout - subroutine of initPanes()
2215          *
2216          * @see  initPanes()
2217          * @param {string}      pane                    The pane to process
2218          * @param {boolean=}    [force=false]   Size content after init
2219          */
2220 ,       addPane = function (pane, force) {
2221                 if ( !force && !isInitialized() ) return;
2222                 var
2223                         o               = options[pane]
2224                 ,       s               = state[pane]
2225                 ,       c               = _c[pane]
2226                 ,       dir             = c.dir
2227                 ,       fx              = s.fx
2228                 ,       spacing = o.spacing_open || 0
2229                 ,       isCenter = (pane === "center")
2230                 ,       CSS             = {}
2231                 ,       $P              = $Ps[pane]
2232                 ,       size, minSize, maxSize, child
2233                 ;
2234                 // if pane-pointer already exists, remove the old one first
2235                 if ($P)
2236                         removePane( pane, false, true, false );
2237                 else
2238                         $Cs[pane] = false; // init
2239
2240                 $P = $Ps[pane] = getPane(pane);
2241                 if (!$P.length) {
2242                         $Ps[pane] = false; // logic
2243                         return;
2244                 }
2245
2246                 // SAVE original Pane CSS
2247                 if (!$P.data("layoutCSS")) {
2248                         var props = "position,top,left,bottom,right,width,height,overflow,zIndex,display,backgroundColor,padding,margin,border";
2249                         $P.data("layoutCSS", styles($P, props));
2250                 }
2251
2252                 // create alias for pane data in Instance - initHandles will add more
2253                 Instance[pane] = {
2254                         name:           pane
2255                 ,       pane:           $Ps[pane]
2256                 ,       content:        $Cs[pane]
2257                 ,       options:        options[pane]
2258                 ,       state:          state[pane]
2259                 ,       children:       children[pane]
2260                 };
2261
2262                 // add classes, attributes & events
2263                 $P      .data({
2264                                 parentLayout:   Instance                // pointer to Layout Instance
2265                         ,       layoutPane:             Instance[pane]  // NEW pointer to pane-alias-object
2266                         ,       layoutEdge:             pane
2267                         ,       layoutRole:             "pane"
2268                         })
2269                         .css(c.cssReq).css("zIndex", options.zIndexes.pane_normal)
2270                         .css(o.applyDemoStyles ? c.cssDemo : {}) // demo styles
2271                         .addClass( o.paneClass +" "+ o.paneClass+"-"+pane ) // default = "ui-layout-pane ui-layout-pane-west" - may be a dupe of 'paneSelector'
2272                         .bind("mouseenter."+ sID, addHover )
2273                         .bind("mouseleave."+ sID, removeHover )
2274                         ;
2275                 var paneMethods = {
2276                                 hide:                           ''
2277                         ,       show:                           ''
2278                         ,       toggle:                         ''
2279                         ,       close:                          ''
2280                         ,       open:                           ''
2281                         ,       slideOpen:                      ''
2282                         ,       slideClose:                     ''
2283                         ,       slideToggle:            ''
2284                         ,       size:                           'sizePane'
2285                         ,       sizePane:                       'sizePane'
2286                         ,       sizeContent:            ''
2287                         ,       sizeHandles:            ''
2288                         ,       enableClosable:         ''
2289                         ,       disableClosable:        ''
2290                         ,       enableSlideable:        ''
2291                         ,       disableSlideable:       ''
2292                         ,       enableResizable:        ''
2293                         ,       disableResizable:       ''
2294                         ,       swapPanes:                      'swapPanes'
2295                         ,       swap:                           'swapPanes'
2296                         ,       move:                           'swapPanes'
2297                         ,       removePane:                     'removePane'
2298                         ,       remove:                         'removePane'
2299                         ,       createChildren:         ''
2300                         ,       resizeChildren:         ''
2301                         ,       resizeAll:                      'resizeAll'
2302                         ,       resizeLayout:           'resizeAll'
2303                         }
2304                 ,       name;
2305                 // loop hash and bind all methods - include layoutID namespacing
2306                 for (name in paneMethods) {
2307                         $P.bind("layoutpane"+ name.toLowerCase() +"."+ sID, Instance[ paneMethods[name] || name ]);
2308                 }
2309
2310                 // see if this pane has a 'scrolling-content element'
2311                 initContent(pane, false); // false = do NOT sizeContent() - called later
2312
2313                 if (!isCenter) {
2314                         // call _parseSize AFTER applying pane classes & styles - but before making visible (if hidden)
2315                         // if o.size is auto or not valid, then MEASURE the pane and use that as its 'size'
2316                         size    = s.size = _parseSize(pane, o.size);
2317                         minSize = _parseSize(pane,o.minSize) || 1;
2318                         maxSize = _parseSize(pane,o.maxSize) || 100000;
2319                         if (size > 0) size = max(min(size, maxSize), minSize);
2320                         s.autoResize = o.autoResize; // used with percentage sizes
2321
2322                         // state for border-panes
2323                         s.isClosed  = false; // true = pane is closed
2324                         s.isSliding = false; // true = pane is currently open by 'sliding' over adjacent panes
2325                         s.isResizing= false; // true = pane is in process of being resized
2326                         s.isHidden      = false; // true = pane is hidden - no spacing, resizer or toggler is visible!
2327
2328                         // array for 'pin buttons' whose classNames are auto-updated on pane-open/-close
2329                         if (!s.pins) s.pins = [];
2330                 }
2331                 //      states common to ALL panes
2332                 s.tagName       = $P[0].tagName;
2333                 s.edge          = pane;         // useful if pane is (or about to be) 'swapped' - easy find out where it is (or is going)
2334                 s.noRoom        = false;        // true = pane 'automatically' hidden due to insufficient room - will unhide automatically
2335                 s.isVisible     = true;         // false = pane is invisible - closed OR hidden - simplify logic
2336
2337                 // init pane positioning
2338                 setPanePosition( pane );
2339
2340                 // if pane is not visible, 
2341                 if (dir === "horz") // north or south pane
2342                         CSS.height = cssH($P, size);
2343                 else if (dir === "vert") // east or west pane
2344                         CSS.width = cssW($P, size);
2345                 //else if (isCenter) {}
2346
2347                 $P.css(CSS); // apply size -- top, bottom & height will be set by sizeMidPanes
2348                 if (dir != "horz") sizeMidPanes(pane, true); // true = skipCallback
2349
2350                 // if manually adding a pane AFTER layout initialization, then...
2351                 if (state.initialized) {
2352                         initHandles( pane );
2353                         initHotkeys( pane );
2354                 }
2355
2356                 // close or hide the pane if specified in settings
2357                 if (o.initClosed && o.closable && !o.initHidden)
2358                         close(pane, true, true); // true, true = force, noAnimation
2359                 else if (o.initHidden || o.initClosed)
2360                         hide(pane); // will be completely invisible - no resizer or spacing
2361                 else if (!s.noRoom)
2362                         // make the pane visible - in case was initially hidden
2363                         $P.css("display","block");
2364                 // ELSE setAsOpen() - called later by initHandles()
2365
2366                 // RESET visibility now - pane will appear IF display:block
2367                 $P.css("visibility","visible");
2368
2369                 // check option for auto-handling of pop-ups & drop-downs
2370                 if (o.showOverflowOnHover)
2371                         $P.hover( allowOverflow, resetOverflow );
2372
2373                 // if manually adding a pane AFTER layout initialization, then...
2374                 if (state.initialized) {
2375                         afterInitPane( pane );
2376                 }
2377         }
2378
2379 ,       afterInitPane = function (pane) {
2380                 var     $P      = $Ps[pane]
2381                 ,       s       = state[pane]
2382                 ,       o       = options[pane]
2383                 ;
2384                 if (!$P) return;
2385
2386                 // see if there is a directly-nested layout inside this pane
2387                 if ($P.data("layout"))
2388                         refreshChildren( pane, $P.data("layout") );
2389
2390                 // process pane contents and callbacks, and init/resize child-layout if exists
2391                 if (s.isVisible) { // pane is OPEN
2392                         if (state.initialized) // this pane was added AFTER layout was created
2393                                 resizeAll(); // will also sizeContent
2394                         else
2395                                 sizeContent(pane);
2396
2397                         if (o.triggerEventsOnLoad)
2398                                 _runCallbacks("onresize_end", pane);
2399                         else // automatic if onresize called, otherwise call it specifically
2400                                 // resize child - IF inner-layout already exists (created before this layout)
2401                                 resizeChildren(pane, true); // a previously existing childLayout
2402                 }
2403
2404                 // init childLayouts - even if pane is not visible
2405                 if (o.initChildren && o.children)
2406                         createChildren(pane);
2407         }
2408
2409         /**
2410          * @param {string=}     panes           The pane(s) to process
2411          */
2412 ,       setPanePosition = function (panes) {
2413                 panes = panes ? panes.split(",") : _c.borderPanes;
2414
2415                 // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV
2416                 $.each(panes, function (i, pane) {
2417                         var $P  = $Ps[pane]
2418                         ,       $R      = $Rs[pane]
2419                         ,       o       = options[pane]
2420                         ,       s       = state[pane]
2421                         ,       side =  _c[pane].side
2422                         ,       CSS     = {}
2423                         ;
2424                         if (!$P) return; // pane does not exist - skip
2425
2426                         // set css-position to account for container borders & padding
2427                         switch (pane) {
2428                                 case "north":   CSS.top         = sC.inset.top;
2429                                                                 CSS.left        = sC.inset.left;
2430                                                                 CSS.right       = sC.inset.right;
2431                                                                 break;
2432                                 case "south":   CSS.bottom      = sC.inset.bottom;
2433                                                                 CSS.left        = sC.inset.left;
2434                                                                 CSS.right       = sC.inset.right;
2435                                                                 break;
2436                                 case "west":    CSS.left        = sC.inset.left; // top, bottom & height set by sizeMidPanes()
2437                                                                 break;
2438                                 case "east":    CSS.right       = sC.inset.right; // ditto
2439                                                                 break;
2440                                 case "center":  // top, left, width & height set by sizeMidPanes()
2441                         }
2442                         // apply position
2443                         $P.css(CSS); 
2444
2445                         // update resizer position
2446                         if ($R && s.isClosed)
2447                                 $R.css(side, sC.inset[side]);
2448                         else if ($R && !s.isHidden)
2449                                 $R.css(side, sC.inset[side] + getPaneSize(pane));
2450                 });
2451         }
2452
2453         /**
2454          * Initialize module objects, styling, size and position for all resize bars and toggler buttons
2455          *
2456          * @see  _create()
2457          * @param {string=}     [panes=""]      The edge(s) to process
2458          */
2459 ,       initHandles = function (panes) {
2460                 panes = panes ? panes.split(",") : _c.borderPanes;
2461
2462                 // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV
2463                 $.each(panes, function (i, pane) {
2464                         var $P          = $Ps[pane];
2465                         $Rs[pane]       = false; // INIT
2466                         $Ts[pane]       = false;
2467                         if (!$P) return; // pane does not exist - skip
2468
2469                         var     o               = options[pane]
2470                         ,       s               = state[pane]
2471                         ,       c               = _c[pane]
2472                         ,       paneId  = o.paneSelector.substr(0,1) === "#" ? o.paneSelector.substr(1) : ""
2473                         ,       rClass  = o.resizerClass
2474                         ,       tClass  = o.togglerClass
2475                         ,       spacing = (s.isVisible ? o.spacing_open : o.spacing_closed)
2476                         ,       _pane   = "-"+ pane // used for classNames
2477                         ,       _state  = (s.isVisible ? "-open" : "-closed") // used for classNames
2478                         ,       I               = Instance[pane]
2479                                 // INIT RESIZER BAR
2480                         ,       $R              = I.resizer = $Rs[pane] = $("<div></div>")
2481                                 // INIT TOGGLER BUTTON
2482                         ,       $T              = I.toggler = (o.closable ? $Ts[pane] = $("<div></div>") : false)
2483                         ;
2484
2485                         //if (s.isVisible && o.resizable) ... handled by initResizable
2486                         if (!s.isVisible && o.slidable)
2487                                 $R.attr("title", o.tips.Slide).css("cursor", o.sliderCursor);
2488
2489                         $R      // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "paneLeft-resizer"
2490                                 .attr("id", paneId ? paneId +"-resizer" : "" )
2491                                 .data({
2492                                         parentLayout:   Instance
2493                                 ,       layoutPane:             Instance[pane]  // NEW pointer to pane-alias-object
2494                                 ,       layoutEdge:             pane
2495                                 ,       layoutRole:             "resizer"
2496                                 })
2497                                 .css(_c.resizers.cssReq).css("zIndex", options.zIndexes.resizer_normal)
2498                                 .css(o.applyDemoStyles ? _c.resizers.cssDemo : {}) // add demo styles
2499                                 .addClass(rClass +" "+ rClass+_pane)
2500                                 .hover(addHover, removeHover) // ALWAYS add hover-classes, even if resizing is not enabled - handle with CSS instead
2501                                 .hover(onResizerEnter, onResizerLeave) // ALWAYS NEED resizer.mouseleave to balance toggler.mouseenter
2502                                 .mousedown($.layout.disableTextSelection)       // prevent text-selection OUTSIDE resizer
2503                                 .mouseup($.layout.enableTextSelection)          // not really necessary, but just in case
2504                                 .appendTo($N) // append DIV to container
2505                         ;
2506                         if ($.fn.disableSelection)
2507                                 $R.disableSelection(); // prevent text-selection INSIDE resizer
2508                         if (o.resizerDblClickToggle)
2509                                 $R.bind("dblclick."+ sID, toggle );
2510
2511                         if ($T) {
2512                                 $T      // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "#paneLeft-toggler"
2513                                         .attr("id", paneId ? paneId +"-toggler" : "" )
2514                                         .data({
2515                                                 parentLayout:   Instance
2516                                         ,       layoutPane:             Instance[pane]  // NEW pointer to pane-alias-object
2517                                         ,       layoutEdge:             pane
2518                                         ,       layoutRole:             "toggler"
2519                                         })
2520                                         .css(_c.togglers.cssReq) // add base/required styles
2521                                         .css(o.applyDemoStyles ? _c.togglers.cssDemo : {}) // add demo styles
2522                                         .addClass(tClass +" "+ tClass+_pane)
2523                                         .hover(addHover, removeHover) // ALWAYS add hover-classes, even if toggling is not enabled - handle with CSS instead
2524                                         .bind("mouseenter", onResizerEnter) // NEED toggler.mouseenter because mouseenter MAY NOT fire on resizer
2525                                         .appendTo($R) // append SPAN to resizer DIV
2526                                 ;
2527                                 // ADD INNER-SPANS TO TOGGLER
2528                                 if (o.togglerContent_open) // ui-layout-open
2529                                         $("<span>"+ o.togglerContent_open +"</span>")
2530                                                 .data({
2531                                                         layoutEdge:             pane
2532                                                 ,       layoutRole:             "togglerContent"
2533                                                 })
2534                                                 .data("layoutRole", "togglerContent")
2535                                                 .data("layoutEdge", pane)
2536                                                 .addClass("content content-open")
2537                                                 .css("display","none")
2538                                                 .appendTo( $T )
2539                                                 //.hover( addHover, removeHover ) // use ui-layout-toggler-west-hover .content-open instead!
2540                                         ;
2541                                 if (o.togglerContent_closed) // ui-layout-closed
2542                                         $("<span>"+ o.togglerContent_closed +"</span>")
2543                                                 .data({
2544                                                         layoutEdge:             pane
2545                                                 ,       layoutRole:             "togglerContent"
2546                                                 })
2547                                                 .addClass("content content-closed")
2548                                                 .css("display","none")
2549                                                 .appendTo( $T )
2550                                                 //.hover( addHover, removeHover ) // use ui-layout-toggler-west-hover .content-closed instead!
2551                                         ;
2552                                 // ADD TOGGLER.click/.hover
2553                                 enableClosable(pane);
2554                         }
2555
2556                         // add Draggable events
2557                         initResizable(pane);
2558
2559                         // ADD CLASSNAMES & SLIDE-BINDINGS - eg: class="resizer resizer-west resizer-open"
2560                         if (s.isVisible)
2561                                 setAsOpen(pane);        // onOpen will be called, but NOT onResize
2562                         else {
2563                                 setAsClosed(pane);      // onClose will be called
2564                                 bindStartSlidingEvents(pane, true); // will enable events IF option is set
2565                         }
2566
2567                 });
2568
2569                 // SET ALL HANDLE DIMENSIONS
2570                 sizeHandles();
2571         }
2572
2573
2574         /**
2575          * Initialize scrolling ui-layout-content div - if exists
2576          *
2577          * @see  initPane() - or externally after an Ajax injection
2578          * @param {string}      pane                    The pane to process
2579          * @param {boolean=}    [resize=true]   Size content after init
2580          */
2581 ,       initContent = function (pane, resize) {
2582                 if (!isInitialized()) return;
2583                 var 
2584                         o       = options[pane]
2585                 ,       sel     = o.contentSelector
2586                 ,       I       = Instance[pane]
2587                 ,       $P      = $Ps[pane]
2588                 ,       $C
2589                 ;
2590                 if (sel) $C = I.content = $Cs[pane] = (o.findNestedContent)
2591                         ? $P.find(sel).eq(0) // match 1-element only
2592                         : $P.children(sel).eq(0)
2593                 ;
2594                 if ($C && $C.length) {
2595                         $C.data("layoutRole", "content");
2596                         // SAVE original Content CSS
2597                         if (!$C.data("layoutCSS"))
2598                                 $C.data("layoutCSS", styles($C, "height"));
2599                         $C.css( _c.content.cssReq );
2600                         if (o.applyDemoStyles) {
2601                                 $C.css( _c.content.cssDemo ); // add padding & overflow: auto to content-div
2602                                 $P.css( _c.content.cssDemoPane ); // REMOVE padding/scrolling from pane
2603                         }
2604                         // ensure no vertical scrollbar on pane - will mess up measurements
2605                         if ($P.css("overflowX").match(/(scroll|auto)/)) {
2606                                 $P.css("overflow", "hidden");
2607                         }
2608                         state[pane].content = {}; // init content state
2609                         if (resize !== false) sizeContent(pane);
2610                         // sizeContent() is called AFTER init of all elements
2611                 }
2612                 else
2613                         I.content = $Cs[pane] = false;
2614         }
2615
2616
2617         /**
2618          * Add resize-bars to all panes that specify it in options
2619          * -dependancy: $.fn.resizable - will skip if not found
2620          *
2621          * @see  _create()
2622          * @param {string=}     [panes=""]      The edge(s) to process
2623          */
2624 ,       initResizable = function (panes) {
2625                 var     draggingAvailable = $.layout.plugins.draggable
2626                 ,       side // set in start()
2627                 ;
2628                 panes = panes ? panes.split(",") : _c.borderPanes;
2629
2630                 $.each(panes, function (idx, pane) {
2631                         var o = options[pane];
2632                         if (!draggingAvailable || !$Ps[pane] || !o.resizable) {
2633                                 o.resizable = false;
2634                                 return true; // skip to next
2635                         }
2636
2637                         var s           = state[pane]
2638                         ,       z               = options.zIndexes
2639                         ,       c               = _c[pane]
2640                         ,       side    = c.dir=="horz" ? "top" : "left"
2641                         ,       $P              = $Ps[pane]
2642                         ,       $R              = $Rs[pane]
2643                         ,       base    = o.resizerClass
2644                         ,       lastPos = 0 // used when live-resizing
2645                         ,       r, live // set in start because may change
2646                         //      'drag' classes are applied to the ORIGINAL resizer-bar while dragging is in process
2647                         ,       resizerClass            = base+"-drag"                          // resizer-drag
2648                         ,       resizerPaneClass        = base+"-"+pane+"-drag"         // resizer-north-drag
2649                         //      'helper' class is applied to the CLONED resizer-bar while it is being dragged
2650                         ,       helperClass                     = base+"-dragging"                      // resizer-dragging
2651                         ,       helperPaneClass         = base+"-"+pane+"-dragging" // resizer-north-dragging
2652                         ,       helperLimitClass        = base+"-dragging-limit"        // resizer-drag
2653                         ,       helperPaneLimitClass = base+"-"+pane+"-dragging-limit"  // resizer-north-drag
2654                         ,       helperClassesSet        = false                                         // logic var
2655                         ;
2656
2657                         if (!s.isClosed)
2658                                 $R.attr("title", o.tips.Resize)
2659                                   .css("cursor", o.resizerCursor); // n-resize, s-resize, etc
2660
2661                         $R.draggable({
2662                                 containment:    $N[0] // limit resizing to layout container
2663                         ,       axis:                   (c.dir=="horz" ? "y" : "x") // limit resizing to horz or vert axis
2664                         ,       delay:                  0
2665                         ,       distance:               1
2666                         ,       grid:                   o.resizingGrid
2667                         //      basic format for helper - style it using class: .ui-draggable-dragging
2668                         ,       helper:                 "clone"
2669                         ,       opacity:                o.resizerDragOpacity
2670                         ,       addClasses:             false // avoid ui-state-disabled class when disabled
2671                         //,     iframeFix:              o.draggableIframeFix // TODO: consider using when bug is fixed
2672                         ,       zIndex:                 z.resizer_drag
2673
2674                         ,       start: function (e, ui) {
2675                                         // REFRESH options & state pointers in case we used swapPanes
2676                                         o = options[pane];
2677                                         s = state[pane];
2678                                         // re-read options
2679                                         live = o.livePaneResizing;
2680
2681                                         // ondrag_start callback - will CANCEL hide if returns false
2682                                         // TODO: dragging CANNOT be cancelled like this, so see if there is a way?
2683                                         if (false === _runCallbacks("ondrag_start", pane)) return false;
2684
2685                                         s.isResizing            = true; // prevent pane from closing while resizing
2686                                         state.paneResizing      = pane; // easy to see if ANY pane is resizing
2687                                         timer.clear(pane+"_closeSlider"); // just in case already triggered
2688
2689                                         // SET RESIZER LIMITS - used in drag()
2690                                         setSizeLimits(pane); // update pane/resizer state
2691                                         r = s.resizerPosition;
2692                                         lastPos = ui.position[ side ]
2693
2694                                         $R.addClass( resizerClass +" "+ resizerPaneClass ); // add drag classes
2695                                         helperClassesSet = false; // reset logic var - see drag()
2696
2697                                         // MASK PANES CONTAINING IFRAMES, APPLETS OR OTHER TROUBLESOME ELEMENTS
2698                                         showMasks( pane, { resizing: true });
2699                                 }
2700
2701                         ,       drag: function (e, ui) {
2702                                         if (!helperClassesSet) { // can only add classes after clone has been added to the DOM
2703                                                 //$(".ui-draggable-dragging")
2704                                                 ui.helper
2705                                                         .addClass( helperClass +" "+ helperPaneClass ) // add helper classes
2706                                                         .css({ right: "auto", bottom: "auto" }) // fix dir="rtl" issue
2707                                                         .children().css("visibility","hidden")  // hide toggler inside dragged resizer-bar
2708                                                 ;
2709                                                 helperClassesSet = true;
2710                                                 // draggable bug!? RE-SET zIndex to prevent E/W resize-bar showing through N/S pane!
2711                                                 if (s.isSliding) $Ps[pane].css("zIndex", z.pane_sliding);
2712                                         }
2713                                         // CONTAIN RESIZER-BAR TO RESIZING LIMITS
2714                                         var limit = 0;
2715                                         if (ui.position[side] < r.min) {
2716                                                 ui.position[side] = r.min;
2717                                                 limit = -1;
2718                                         }
2719                                         else if (ui.position[side] > r.max) {
2720                                                 ui.position[side] = r.max;
2721                                                 limit = 1;
2722                                         }
2723                                         // ADD/REMOVE dragging-limit CLASS
2724                                         if (limit) {
2725                                                 ui.helper.addClass( helperLimitClass +" "+ helperPaneLimitClass ); // at dragging-limit
2726                                                 window.defaultStatus = (limit>0 && pane.match(/(north|west)/)) || (limit<0 && pane.match(/(south|east)/)) ? o.tips.maxSizeWarning : o.tips.minSizeWarning;
2727                                         }
2728                                         else {
2729                                                 ui.helper.removeClass( helperLimitClass +" "+ helperPaneLimitClass ); // not at dragging-limit
2730                                                 window.defaultStatus = "";
2731                                         }
2732                                         // DYNAMICALLY RESIZE PANES IF OPTION ENABLED
2733                                         // won't trigger unless resizer has actually moved!
2734                                         if (live && Math.abs(ui.position[side] - lastPos) >= o.liveResizingTolerance) {
2735                                                 lastPos = ui.position[side];
2736                                                 resizePanes(e, ui, pane)
2737                                         }
2738                                 }
2739
2740                         ,       stop: function (e, ui) {
2741                                         $('body').enableSelection(); // RE-ENABLE TEXT SELECTION
2742                                         window.defaultStatus = ""; // clear 'resizing limit' message from statusbar
2743                                         $R.removeClass( resizerClass +" "+ resizerPaneClass ); // remove drag classes from Resizer
2744                                         s.isResizing            = false;
2745                                         state.paneResizing      = false; // easy to see if ANY pane is resizing
2746                                         resizePanes(e, ui, pane, true); // true = resizingDone
2747                                 }
2748
2749                         });
2750                 });
2751
2752                 /**
2753                  * resizePanes
2754                  *
2755                  * Sub-routine called from stop() - and drag() if livePaneResizing
2756                  *
2757                  * @param {!Object}             evt
2758                  * @param {!Object}             ui
2759                  * @param {string}              pane
2760                  * @param {boolean=}            [resizingDone=false]
2761                  */
2762                 var resizePanes = function (evt, ui, pane, resizingDone) {
2763                         var     dragPos = ui.position
2764                         ,       c               = _c[pane]
2765                         ,       o               = options[pane]
2766                         ,       s               = state[pane]
2767                         ,       resizerPos
2768                         ;
2769                         switch (pane) {
2770                                 case "north":   resizerPos = dragPos.top; break;
2771                                 case "west":    resizerPos = dragPos.left; break;
2772                                 case "south":   resizerPos = sC.layoutHeight - dragPos.top  - o.spacing_open; break;
2773                                 case "east":    resizerPos = sC.layoutWidth  - dragPos.left - o.spacing_open; break;
2774                         };
2775                         // remove container margin from resizer position to get the pane size
2776                         var newSize = resizerPos - sC.inset[c.side];
2777
2778                         // Disable OR Resize Mask(s) created in drag.start
2779                         if (!resizingDone) {
2780                                 // ensure we meet liveResizingTolerance criteria
2781                                 if (Math.abs(newSize - s.size) < o.liveResizingTolerance)
2782                                         return; // SKIP resize this time
2783                                 // resize the pane
2784                                 manualSizePane(pane, newSize, false, true); // true = noAnimation
2785                                 sizeMasks(); // resize all visible masks
2786                         }
2787                         else { // resizingDone
2788                                 // ondrag_end callback
2789                                 if (false !== _runCallbacks("ondrag_end", pane))
2790                                         manualSizePane(pane, newSize, false, true); // true = noAnimation
2791                                 hideMasks(true); // true = force hiding all masks even if one is 'sliding'
2792                                 if (s.isSliding) // RE-SHOW 'object-masks' so objects won't show through sliding pane
2793                                         showMasks( pane, { resizing: true });
2794                         }
2795                 };
2796         }
2797
2798         /**
2799          *      sizeMask
2800          *
2801          *      Needed to overlay a DIV over an IFRAME-pane because mask CANNOT be *inside* the pane
2802          *      Called when mask created, and during livePaneResizing
2803          */
2804 ,       sizeMask = function () {
2805                 var $M          = $(this)
2806                 ,       pane    = $M.data("layoutMask") // eg: "west"
2807                 ,       s               = state[pane]
2808                 ;
2809                 // only masks over an IFRAME-pane need manual resizing
2810                 if (s.tagName == "IFRAME" && s.isVisible) // no need to mask closed/hidden panes
2811                         $M.css({
2812                                 top:    s.offsetTop
2813                         ,       left:   s.offsetLeft
2814                         ,       width:  s.outerWidth
2815                         ,       height: s.outerHeight
2816                         });
2817                 /* ALT Method...
2818                 var $P = $Ps[pane];
2819                 $M.css( $P.position() ).css({ width: $P[0].offsetWidth, height: $P[0].offsetHeight });
2820                 */
2821         }
2822 ,       sizeMasks = function () {
2823                 $Ms.each( sizeMask ); // resize all 'visible' masks
2824         }
2825
2826         /**
2827          * @param {string}      pane            The pane being resized, animated or isSliding
2828          * @param {Object=}     [args]          (optional) Options: which masks to apply, and to which panes
2829          */
2830 ,       showMasks = function (pane, args) {
2831                 var     c               = _c[pane]
2832                 ,       panes   =  ["center"]
2833                 ,       z               = options.zIndexes
2834                 ,       a               = $.extend({
2835                                                 objectsOnly:    false
2836                                         ,       animation:              false
2837                                         ,       resizing:               true
2838                                         ,       sliding:                state[pane].isSliding
2839                                         },      args )
2840                 ,       o, s
2841                 ;
2842                 if (a.resizing)
2843                         panes.push( pane );
2844                 if (a.sliding)
2845                         panes.push( _c.oppositeEdge[pane] ); // ADD the oppositeEdge-pane
2846
2847                 if (c.dir === "horz") {
2848                         panes.push("west");
2849                         panes.push("east");
2850                 }
2851
2852                 $.each(panes, function(i,p){
2853                         s = state[p];
2854                         o = options[p];
2855                         if (s.isVisible && ( o.maskObjects || (!a.objectsOnly && o.maskContents) )) {
2856                                 getMasks(p).each(function(){
2857                                         sizeMask.call(this);
2858                                         this.style.zIndex = s.isSliding ? z.pane_sliding+1 : z.pane_normal+1
2859                                         this.style.display = "block";
2860                                 });
2861                         }
2862                 });
2863         }
2864
2865         /**
2866          * @param {boolean=}    force           Hide masks even if a pane is sliding
2867          */
2868 ,       hideMasks = function (force) {
2869                 // ensure no pane is resizing - could be a timing issue
2870                 if (force || !state.paneResizing) {
2871                         $Ms.hide(); // hide ALL masks
2872                 }
2873                 // if ANY pane is sliding, then DO NOT remove masks from panes with maskObjects enabled
2874                 else if (!force && !$.isEmptyObject( state.panesSliding )) {
2875                         var     i = $Ms.length - 1
2876                         ,       p, $M;
2877                         for (; i >= 0; i--) {
2878                                 $M      = $Ms.eq(i);
2879                                 p       = $M.data("layoutMask");
2880                                 if (!options[p].maskObjects) {
2881                                         $M.hide();
2882                                 }
2883                         }
2884                 }
2885         }
2886
2887         /**
2888          * @param {string}      pane
2889          */
2890 ,       getMasks = function (pane) {
2891                 var $Masks      = $([])
2892                 ,       $M, i = 0, c = $Ms.length
2893                 ;
2894                 for (; i<c; i++) {
2895                         $M = $Ms.eq(i);
2896                         if ($M.data("layoutMask") === pane)
2897                                 $Masks = $Masks.add( $M );
2898                 }
2899                 if ($Masks.length)
2900                         return $Masks;
2901                 else
2902                         return createMasks(pane);
2903         }
2904
2905         /**
2906          * createMasks
2907          *
2908          * Generates both DIV (ALWAYS used) and IFRAME (optional) elements as masks
2909          * An IFRAME mask is created *under* the DIV when maskObjects=true, because a DIV cannot mask an applet
2910          *
2911          * @param {string}      pane
2912          */
2913 ,       createMasks = function (pane) {
2914                 var
2915                         $P      = $Ps[pane]
2916                 ,       s       = state[pane]
2917                 ,       o       = options[pane]
2918                 ,       z       = options.zIndexes
2919                 ,       isIframe, el, $M, css, i
2920                 ;
2921                 if (!o.maskContents && !o.maskObjects) return $([]);
2922                 // if o.maskObjects=true, then loop TWICE to create BOTH kinds of mask, else only create a DIV
2923                 for (i=0; i < (o.maskObjects ? 2 : 1); i++) {
2924                         isIframe = o.maskObjects && i==0;
2925                         el = document.createElement( isIframe ? "iframe" : "div" );
2926                         $M = $(el).data("layoutMask", pane); // add data to relate mask to pane
2927                         el.className = "ui-layout-mask ui-layout-mask-"+ pane; // for user styling
2928                         css = el.style;
2929                         // Both DIVs and IFRAMES
2930                         css.background  = "#FFF";
2931                         css.position    = "absolute";
2932                         css.display             = "block";
2933                         if (isIframe) { // IFRAME-only props
2934                                 el.src          = "about:blank";
2935                                 el.frameborder = 0;
2936                                 css.border      = 0;
2937                                 css.opacity     = 0;
2938                                 css.filter      = "Alpha(Opacity='0')";
2939                                 //el.allowTransparency = true; - for IE, but breaks masking ability!
2940                         }
2941                         else { // DIV-only props
2942                                 css.opacity     = 0.001;
2943                                 css.filter      = "Alpha(Opacity='1')";
2944                         }
2945                         // if pane IS an IFRAME, then must mask the pane itself
2946                         if (s.tagName == "IFRAME") {
2947                                 // NOTE sizing done by a subroutine so can be called during live-resizing
2948                                 css.zIndex      = z.pane_normal+1; // 1-higher than pane
2949                                 $N.append( el ); // append to LAYOUT CONTAINER
2950                         }
2951                         // otherwise put masks *inside the pane* to mask its contents
2952                         else {
2953                                 $M.addClass("ui-layout-mask-inside-pane");
2954                                 css.zIndex      = o.maskZindex || z.content_mask; // usually 1, but customizable
2955                                 css.top         = 0;
2956                                 css.left        = 0;
2957                                 css.width       = "100%";
2958                                 css.height      = "100%";
2959                                 $P.append( el ); // append INSIDE pane element
2960                         }
2961                         // add Mask to cached array so can be resized & reused
2962                         $Ms = $Ms.add( el );
2963                 }
2964                 return $Ms;
2965         }
2966
2967
2968         /**
2969          * Destroy this layout and reset all elements
2970          *
2971          * @param {boolean=}    [destroyChildren=false]         Destory Child-Layouts first?
2972          */
2973 ,       destroy = function (evt_or_destroyChildren, destroyChildren) {
2974                 // UNBIND layout events and remove global object
2975                 $(window).unbind("."+ sID);             // resize & unload
2976                 $(document).unbind("."+ sID);   // keyDown (hotkeys)
2977
2978                 if (typeof evt_or_destroyChildren === "object")
2979                         // stopPropagation if called by trigger("layoutdestroy") - use evtPane utility 
2980                         evtPane(evt_or_destroyChildren);
2981                 else // no event, so transfer 1st param to destroyChildren param
2982                         destroyChildren = evt_or_destroyChildren;
2983
2984                 // need to look for parent layout BEFORE we remove the container data, else skips a level
2985                 //var parentPane = Instance.hasParentLayout ? $.layout.getParentPaneInstance( $N ) : null;
2986
2987                 // reset layout-container
2988                 $N      .clearQueue()
2989                         .removeData("layout")
2990                         .removeData("layoutContainer")
2991                         .removeClass(options.containerClass)
2992                         .unbind("."+ sID) // remove ALL Layout events
2993                 ;
2994
2995                 // remove all mask elements that have been created
2996                 $Ms.remove();
2997
2998                 // loop all panes to remove layout classes, attributes and bindings
2999                 $.each(_c.allPanes, function (i, pane) {
3000                         removePane( pane, false, true, destroyChildren ); // true = skipResize
3001                 });
3002
3003                 // do NOT reset container CSS if is a 'pane' (or 'content') in an outer-layout - ie, THIS layout is 'nested'
3004                 var css = "layoutCSS";
3005                 if ($N.data(css) && !$N.data("layoutRole")) // RESET CSS
3006                         $N.css( $N.data(css) ).removeData(css);
3007
3008                 // for full-page layouts, also reset the <HTML> CSS
3009                 if (sC.tagName === "BODY" && ($N = $("html")).data(css)) // RESET <HTML> CSS
3010                         $N.css( $N.data(css) ).removeData(css);
3011
3012                 // trigger plugins for this layout, if there are any
3013                 runPluginCallbacks( Instance, $.layout.onDestroy );
3014
3015                 // trigger state-management and onunload callback
3016                 unload();
3017
3018                 // clear the Instance of everything except for container & options (so could recreate)
3019                 // RE-CREATE: myLayout = myLayout.container.layout( myLayout.options );
3020                 for (var n in Instance)
3021                         if (!n.match(/^(container|options)$/)) delete Instance[ n ];
3022                 // add a 'destroyed' flag to make it easy to check
3023                 Instance.destroyed = true;
3024
3025                 // if this is a child layout, CLEAR the child-pointer in the parent
3026                 /* for now the pointer REMAINS, but with only container, options and destroyed keys
3027                 if (parentPane) {
3028                         var layout      = parentPane.pane.data("parentLayout")
3029                         ,       key             = layout.options.instanceKey || 'error';
3030                         // THIS SYNTAX MAY BE WRONG!
3031                         parentPane.children[key] = layout.children[ parentPane.name ].children[key] = null;
3032                 }
3033                 */
3034
3035                 return Instance; // for coding convenience
3036         }
3037
3038         /**
3039          * Remove a pane from the layout - subroutine of destroy()
3040          *
3041          * @see  destroy()
3042          * @param {(string|Object)}     evt_or_pane                     The pane to process
3043          * @param {boolean=}                    [remove=false]          Remove the DOM element?
3044          * @param {boolean=}                    [skipResize=false]      Skip calling resizeAll()?
3045          * @param {boolean=}                    [destroyChild=true]     Destroy Child-layouts? If not passed, obeys options setting
3046          */
3047 ,       removePane = function (evt_or_pane, remove, skipResize, destroyChild) {
3048                 if (!isInitialized()) return;
3049                 var     pane = evtPane.call(this, evt_or_pane)
3050                 ,       $P      = $Ps[pane]
3051                 ,       $C      = $Cs[pane]
3052                 ,       $R      = $Rs[pane]
3053                 ,       $T      = $Ts[pane]
3054                 ;
3055                 // NOTE: elements can still exist even after remove()
3056                 //              so check for missing data(), which is cleared by removed()
3057                 if ($P && $.isEmptyObject( $P.data() )) $P = false;
3058                 if ($C && $.isEmptyObject( $C.data() )) $C = false;
3059                 if ($R && $.isEmptyObject( $R.data() )) $R = false;
3060                 if ($T && $.isEmptyObject( $T.data() )) $T = false;
3061
3062                 if ($P) $P.stop(true, true);
3063
3064                 var     o       = options[pane]
3065                 ,       s       = state[pane]
3066                 ,       d       = "layout"
3067                 ,       css     = "layoutCSS"
3068                 ,       pC      = children[pane]
3069                 ,       hasChildren     = $.isPlainObject( pC ) && !$.isEmptyObject( pC )
3070                 ,       destroy         = destroyChild !== undefined ? destroyChild : o.destroyChildren
3071                 ;
3072                 // FIRST destroy the child-layout(s)
3073                 if (hasChildren && destroy) {
3074                         $.each( pC, function (key, child) {
3075                                 if (!child.destroyed)
3076                                         child.destroy(true);// tell child-layout to destroy ALL its child-layouts too
3077                                 if (child.destroyed)    // destroy was successful
3078                                         delete pC[key];
3079                         });
3080                         // if no more children, remove the children hash
3081                         if ($.isEmptyObject( pC )) {
3082                                 pC = children[pane] = null; // clear children hash
3083                                 hasChildren = false;
3084                         }
3085                 }
3086
3087                 // Note: can't 'remove' a pane element with non-destroyed children
3088                 if ($P && remove && !hasChildren)
3089                         $P.remove(); // remove the pane-element and everything inside it
3090                 else if ($P && $P[0]) {
3091                         //      create list of ALL pane-classes that need to be removed
3092                         var     root    = o.paneClass // default="ui-layout-pane"
3093                         ,       pRoot   = root +"-"+ pane // eg: "ui-layout-pane-west"
3094                         ,       _open   = "-open"
3095                         ,       _sliding= "-sliding"
3096                         ,       _closed = "-closed"
3097                         ,       classes = [     root, root+_open, root+_closed, root+_sliding,          // generic classes
3098                                                         pRoot, pRoot+_open, pRoot+_closed, pRoot+_sliding ]     // pane-specific classes
3099                         ;
3100                         $.merge(classes, getHoverClasses($P, true)); // ADD hover-classes
3101                         // remove all Layout classes from pane-element
3102                         $P      .removeClass( classes.join(" ") ) // remove ALL pane-classes
3103                                 .removeData("parentLayout")
3104                                 .removeData("layoutPane")
3105                                 .removeData("layoutRole")
3106                                 .removeData("layoutEdge")
3107                                 .removeData("autoHidden")       // in case set
3108                                 .unbind("."+ sID) // remove ALL Layout events
3109                                 // TODO: remove these extra unbind commands when jQuery is fixed
3110                                 //.unbind("mouseenter"+ sID)
3111                                 //.unbind("mouseleave"+ sID)
3112                         ;
3113                         // do NOT reset CSS if this pane/content is STILL the container of a nested layout!
3114                         // the nested layout will reset its 'container' CSS when/if it is destroyed
3115                         if (hasChildren && $C) {
3116                                 // a content-div may not have a specific width, so give it one to contain the Layout
3117                                 $C.width( $C.width() );
3118                                 $.each( pC, function (key, child) {
3119                                         child.resizeAll(); // resize the Layout
3120                                 });
3121                         }
3122                         else if ($C)
3123                                 $C.css( $C.data(css) ).removeData(css).removeData("layoutRole");
3124                         // remove pane AFTER content in case there was a nested layout
3125                         if (!$P.data(d))
3126                                 $P.css( $P.data(css) ).removeData(css);
3127                 }
3128
3129                 // REMOVE pane resizer and toggler elements
3130                 if ($T) $T.remove();
3131                 if ($R) $R.remove();
3132
3133                 // CLEAR all pointers and state data
3134                 Instance[pane] = $Ps[pane] = $Cs[pane] = $Rs[pane] = $Ts[pane] = false;
3135                 s = { removed: true };
3136
3137                 if (!skipResize)
3138                         resizeAll();
3139         }
3140
3141
3142 /*
3143  * ###########################
3144  *         ACTION METHODS
3145  * ###########################
3146  */
3147
3148         /**
3149          * @param {string}      pane
3150          */
3151 ,       _hidePane = function (pane) {
3152                 var $P  = $Ps[pane]
3153                 ,       o       = options[pane]
3154                 ,       s       = $P[0].style
3155                 ;
3156                 if (o.useOffscreenClose) {
3157                         if (!$P.data(_c.offscreenReset))
3158                                 $P.data(_c.offscreenReset, { left: s.left, right: s.right });
3159                         $P.css( _c.offscreenCSS );
3160                 }
3161                 else
3162                         $P.hide().removeData(_c.offscreenReset);
3163         }
3164
3165         /**
3166          * @param {string}      pane
3167          */
3168 ,       _showPane = function (pane) {
3169                 var $P  = $Ps[pane]
3170                 ,       o       = options[pane]
3171                 ,       off     = _c.offscreenCSS
3172                 ,       old     = $P.data(_c.offscreenReset)
3173                 ,       s       = $P[0].style
3174                 ;
3175                 $P      .show() // ALWAYS show, just in case
3176                         .removeData(_c.offscreenReset);
3177                 if (o.useOffscreenClose && old) {
3178                         if (s.left == off.left)
3179                                 s.left = old.left;
3180                         if (s.right == off.right)
3181                                 s.right = old.right;
3182                 }
3183         }
3184
3185
3186         /**
3187          * Completely 'hides' a pane, including its spacing - as if it does not exist
3188          * The pane is not actually 'removed' from the source, so can use 'show' to un-hide it
3189          *
3190          * @param {(string|Object)}     evt_or_pane                     The pane being hidden, ie: north, south, east, or west
3191          * @param {boolean=}                    [noAnimation=false]     
3192          */
3193 ,       hide = function (evt_or_pane, noAnimation) {
3194                 if (!isInitialized()) return;
3195                 var     pane = evtPane.call(this, evt_or_pane)
3196                 ,       o       = options[pane]
3197                 ,       s       = state[pane]
3198                 ,       $P      = $Ps[pane]
3199                 ,       $R      = $Rs[pane]
3200                 ;
3201                 if (pane === "center" || !$P || s.isHidden) return; // pane does not exist OR is already hidden
3202
3203                 // onhide_start callback - will CANCEL hide if returns false
3204                 if (state.initialized && false === _runCallbacks("onhide_start", pane)) return;
3205
3206                 s.isSliding = false; // just in case
3207                 delete state.panesSliding[pane];
3208
3209                 // now hide the elements
3210                 if ($R) $R.hide(); // hide resizer-bar
3211                 if (!state.initialized || s.isClosed) {
3212                         s.isClosed = true; // to trigger open-animation on show()
3213                         s.isHidden  = true;
3214                         s.isVisible = false;
3215                         if (!state.initialized)
3216                                 _hidePane(pane); // no animation when loading page
3217                         sizeMidPanes(_c[pane].dir === "horz" ? "" : "center");
3218                         if (state.initialized || o.triggerEventsOnLoad)
3219                                 _runCallbacks("onhide_end", pane);
3220                 }
3221                 else {
3222                         s.isHiding = true; // used by onclose
3223                         close(pane, false, noAnimation); // adjust all panes to fit
3224                 }
3225         }
3226
3227         /**
3228          * Show a hidden pane - show as 'closed' by default unless openPane = true
3229          *
3230          * @param {(string|Object)}     evt_or_pane                     The pane being opened, ie: north, south, east, or west
3231          * @param {boolean=}                    [openPane=false]
3232          * @param {boolean=}                    [noAnimation=false]
3233          * @param {boolean=}                    [noAlert=false]
3234          */
3235 ,       show = function (evt_or_pane, openPane, noAnimation, noAlert) {
3236                 if (!isInitialized()) return;
3237                 var     pane = evtPane.call(this, evt_or_pane)
3238                 ,       o       = options[pane]
3239                 ,       s       = state[pane]
3240                 ,       $P      = $Ps[pane]
3241                 ,       $R      = $Rs[pane]
3242                 ;
3243                 if (pane === "center" || !$P || !s.isHidden) return; // pane does not exist OR is not hidden
3244
3245                 // onshow_start callback - will CANCEL show if returns false
3246                 if (false === _runCallbacks("onshow_start", pane)) return;
3247
3248                 s.isShowing = true; // used by onopen/onclose
3249                 //s.isHidden  = false; - will be set by open/close - if not cancelled
3250                 s.isSliding = false; // just in case
3251                 delete state.panesSliding[pane];
3252
3253                 // now show the elements
3254                 //if ($R) $R.show(); - will be shown by open/close
3255                 if (openPane === false)
3256                         close(pane, true); // true = force
3257                 else
3258                         open(pane, false, noAnimation, noAlert); // adjust all panes to fit
3259         }
3260
3261
3262         /**
3263          * Toggles a pane open/closed by calling either open or close
3264          *
3265          * @param {(string|Object)}     evt_or_pane             The pane being toggled, ie: north, south, east, or west
3266          * @param {boolean=}                    [slide=false]
3267          */
3268 ,       toggle = function (evt_or_pane, slide) {
3269                 if (!isInitialized()) return;
3270                 var     evt             = evtObj(evt_or_pane)
3271                 ,       pane    = evtPane.call(this, evt_or_pane)
3272                 ,       s               = state[pane]
3273                 ;
3274                 if (evt) // called from to $R.dblclick OR triggerPaneEvent
3275                         evt.stopImmediatePropagation();
3276                 if (s.isHidden)
3277                         show(pane); // will call 'open' after unhiding it
3278                 else if (s.isClosed)
3279                         open(pane, !!slide);
3280                 else
3281                         close(pane);
3282         }
3283
3284
3285         /**
3286          * Utility method used during init or other auto-processes
3287          *
3288          * @param {string}      pane   The pane being closed
3289          * @param {boolean=}    [setHandles=false]
3290          */
3291 ,       _closePane = function (pane, setHandles) {
3292                 var
3293                         $P      = $Ps[pane]
3294                 ,       s       = state[pane]
3295                 ;
3296                 _hidePane(pane);
3297                 s.isClosed = true;
3298                 s.isVisible = false;
3299                 if (setHandles) setAsClosed(pane);
3300         }
3301
3302         /**
3303          * Close the specified pane (animation optional), and resize all other panes as needed
3304          *
3305          * @param {(string|Object)}     evt_or_pane                     The pane being closed, ie: north, south, east, or west
3306          * @param {boolean=}                    [force=false]
3307          * @param {boolean=}                    [noAnimation=false]
3308          * @param {boolean=}                    [skipCallback=false]
3309          */
3310 ,       close = function (evt_or_pane, force, noAnimation, skipCallback) {
3311                 var     pane = evtPane.call(this, evt_or_pane);
3312                 if (pane === "center") return; // validate
3313                 // if pane has been initialized, but NOT the complete layout, close pane instantly
3314                 if (!state.initialized && $Ps[pane]) {
3315                         _closePane(pane, true); // INIT pane as closed
3316                         return;
3317                 }
3318                 if (!isInitialized()) return;
3319
3320                 var
3321                         $P      = $Ps[pane]
3322                 ,       $R      = $Rs[pane]
3323                 ,       $T      = $Ts[pane]
3324                 ,       o       = options[pane]
3325                 ,       s       = state[pane]
3326                 ,       c       = _c[pane]
3327                 ,       doFX, isShowing, isHiding, wasSliding;
3328
3329                 // QUEUE in case another action/animation is in progress
3330                 $N.queue(function( queueNext ){
3331
3332                         if ( !$P
3333                         ||      (!o.closable && !s.isShowing && !s.isHiding)    // invalid request // (!o.resizable && !o.closable) ???
3334                         ||      (!force && s.isClosed && !s.isShowing)                  // already closed
3335                         ) return queueNext();
3336
3337                         // onclose_start callback - will CANCEL hide if returns false
3338                         // SKIP if just 'showing' a hidden pane as 'closed'
3339                         var abort = !s.isShowing && false === _runCallbacks("onclose_start", pane);
3340
3341                         // transfer logic vars to temp vars
3342                         isShowing       = s.isShowing;
3343                         isHiding        = s.isHiding;
3344                         wasSliding      = s.isSliding;
3345                         // now clear the logic vars (REQUIRED before aborting)
3346                         delete s.isShowing;
3347                         delete s.isHiding;
3348
3349                         if (abort) return queueNext();
3350
3351                         doFX            = !noAnimation && !s.isClosed && (o.fxName_close != "none");
3352                         s.isMoving      = true;
3353                         s.isClosed      = true;
3354                         s.isVisible     = false;
3355                         // update isHidden BEFORE sizing panes
3356                         if (isHiding) s.isHidden = true;
3357                         else if (isShowing) s.isHidden = false;
3358
3359                         if (s.isSliding) // pane is being closed, so UNBIND trigger events
3360                                 bindStopSlidingEvents(pane, false); // will set isSliding=false
3361                         else // resize panes adjacent to this one
3362                                 sizeMidPanes(_c[pane].dir === "horz" ? "" : "center", false); // false = NOT skipCallback
3363
3364                         // if this pane has a resizer bar, move it NOW - before animation
3365                         setAsClosed(pane);
3366
3367                         // CLOSE THE PANE
3368                         if (doFX) { // animate the close
3369                                 lockPaneForFX(pane, true);      // need to set left/top so animation will work
3370                                 $P.hide( o.fxName_close, o.fxSettings_close, o.fxSpeed_close, function () {
3371                                         lockPaneForFX(pane, false); // undo
3372                                         if (s.isClosed) close_2();
3373                                         queueNext();
3374                                 });
3375                         }
3376                         else { // hide the pane without animation
3377                                 _hidePane(pane);
3378                                 close_2();
3379                                 queueNext();
3380                         };
3381                 });
3382
3383                 // SUBROUTINE
3384                 function close_2 () {
3385                         s.isMoving      = false;
3386                         bindStartSlidingEvents(pane, true); // will enable if o.slidable = true
3387
3388                         // if opposite-pane was autoClosed, see if it can be autoOpened now
3389                         var altPane = _c.oppositeEdge[pane];
3390                         if (state[ altPane ].noRoom) {
3391                                 setSizeLimits( altPane );
3392                                 makePaneFit( altPane );
3393                         }
3394
3395                         if (!skipCallback && (state.initialized || o.triggerEventsOnLoad)) {
3396                                 // onclose callback - UNLESS just 'showing' a hidden pane as 'closed'
3397                                 if (!isShowing) _runCallbacks("onclose_end", pane);
3398                                 // onhide OR onshow callback
3399                                 if (isShowing)  _runCallbacks("onshow_end", pane);
3400                                 if (isHiding)   _runCallbacks("onhide_end", pane);
3401                         }
3402                 }
3403         }
3404
3405         /**
3406          * @param {string}      pane    The pane just closed, ie: north, south, east, or west
3407          */
3408 ,       setAsClosed = function (pane) {
3409                 if (!$Rs[pane]) return; // handles not initialized yet!
3410                 var
3411                         $P              = $Ps[pane]
3412                 ,       $R              = $Rs[pane]
3413                 ,       $T              = $Ts[pane]
3414                 ,       o               = options[pane]
3415                 ,       s               = state[pane]
3416                 ,       side    = _c[pane].side
3417                 ,       rClass  = o.resizerClass
3418                 ,       tClass  = o.togglerClass
3419                 ,       _pane   = "-"+ pane // used for classNames
3420                 ,       _open   = "-open"
3421                 ,       _sliding= "-sliding"
3422                 ,       _closed = "-closed"
3423                 ;
3424                 $R
3425                         .css(side, sC.inset[side]) // move the resizer
3426                         .removeClass( rClass+_open +" "+ rClass+_pane+_open )
3427                         .removeClass( rClass+_sliding +" "+ rClass+_pane+_sliding )
3428                         .addClass( rClass+_closed +" "+ rClass+_pane+_closed )
3429                 ;
3430                 // handle already-hidden panes in case called by swap() or a similar method 
3431                 if (s.isHidden) $R.hide(); // hide resizer-bar 
3432
3433                 // DISABLE 'resizing' when closed - do this BEFORE bindStartSlidingEvents?
3434                 if (o.resizable && $.layout.plugins.draggable)
3435                         $R
3436                                 .draggable("disable")
3437                                 .removeClass("ui-state-disabled") // do NOT apply disabled styling - not suitable here
3438                                 .css("cursor", "default")
3439                                 .attr("title","")
3440                         ;
3441
3442                 // if pane has a toggler button, adjust that too
3443                 if ($T) {
3444                         $T
3445                                 .removeClass( tClass+_open +" "+ tClass+_pane+_open )
3446                                 .addClass( tClass+_closed +" "+ tClass+_pane+_closed )
3447                                 .attr("title", o.tips.Open) // may be blank
3448                         ;
3449                         // toggler-content - if exists
3450                         $T.children(".content-open").hide();
3451                         $T.children(".content-closed").css("display","block");
3452                 }
3453
3454                 // sync any 'pin buttons'
3455                 syncPinBtns(pane, false);
3456
3457                 if (state.initialized) {
3458                         // resize 'length' and position togglers for adjacent panes
3459                         sizeHandles();
3460                 }
3461         }
3462
3463         /**
3464          * Open the specified pane (animation optional), and resize all other panes as needed
3465          *
3466          * @param {(string|Object)}     evt_or_pane                     The pane being opened, ie: north, south, east, or west
3467          * @param {boolean=}                    [slide=false]
3468          * @param {boolean=}                    [noAnimation=false]
3469          * @param {boolean=}                    [noAlert=false]
3470          */
3471 ,       open = function (evt_or_pane, slide, noAnimation, noAlert) {
3472                 if (!isInitialized()) return;
3473                 var     pane = evtPane.call(this, evt_or_pane)
3474                 ,       $P      = $Ps[pane]
3475                 ,       $R      = $Rs[pane]
3476                 ,       $T      = $Ts[pane]
3477                 ,       o       = options[pane]
3478                 ,       s       = state[pane]
3479                 ,       c       = _c[pane]
3480                 ,       doFX, isShowing
3481                 ;
3482                 if (pane === "center") return; // validate
3483                 // QUEUE in case another action/animation is in progress
3484                 $N.queue(function( queueNext ){
3485
3486                         if ( !$P
3487                         ||      (!o.resizable && !o.closable && !s.isShowing)   // invalid request
3488                         ||      (s.isVisible && !s.isSliding)                                   // already open
3489                         ) return queueNext();
3490
3491                         // pane can ALSO be unhidden by just calling show(), so handle this scenario
3492                         if (s.isHidden && !s.isShowing) {
3493                                 queueNext(); // call before show() because it needs the queue free
3494                                 show(pane, true);
3495                                 return;
3496                         }
3497
3498                         if (s.autoResize && s.size != o.size) // resize pane to original size set in options
3499                                 sizePane(pane, o.size, true, true, true); // true=skipCallback/noAnimation/forceResize
3500                         else
3501                                 // make sure there is enough space available to open the pane
3502                                 setSizeLimits(pane, slide);
3503
3504                         // onopen_start callback - will CANCEL open if returns false
3505                         var cbReturn = _runCallbacks("onopen_start", pane);
3506
3507                         if (cbReturn === "abort")
3508                                 return queueNext();
3509
3510                         // update pane-state again in case options were changed in onopen_start
3511                         if (cbReturn !== "NC") // NC = "No Callback"
3512                                 setSizeLimits(pane, slide);
3513
3514                         if (s.minSize > s.maxSize) { // INSUFFICIENT ROOM FOR PANE TO OPEN!
3515                                 syncPinBtns(pane, false); // make sure pin-buttons are reset
3516                                 if (!noAlert && o.tips.noRoomToOpen)
3517                                         alert(o.tips.noRoomToOpen);
3518                                 return queueNext(); // ABORT
3519                         }
3520
3521                         if (slide) // START Sliding - will set isSliding=true
3522                                 bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane
3523                         else if (s.isSliding) // PIN PANE (stop sliding) - open pane 'normally' instead
3524                                 bindStopSlidingEvents(pane, false); // UNBIND trigger events - will set isSliding=false
3525                         else if (o.slidable)
3526                                 bindStartSlidingEvents(pane, false); // UNBIND trigger events
3527
3528                         s.noRoom = false; // will be reset by makePaneFit if 'noRoom'
3529                         makePaneFit(pane);
3530
3531                         // transfer logic var to temp var
3532                         isShowing = s.isShowing;
3533                         // now clear the logic var
3534                         delete s.isShowing;
3535
3536                         doFX            = !noAnimation && s.isClosed && (o.fxName_open != "none");
3537                         s.isMoving      = true;
3538                         s.isVisible     = true;
3539                         s.isClosed      = false;
3540                         // update isHidden BEFORE sizing panes - WHY??? Old?
3541                         if (isShowing) s.isHidden = false;
3542
3543                         if (doFX) { // ANIMATE
3544                                 // mask adjacent panes with objects
3545                                 lockPaneForFX(pane, true);      // need to set left/top so animation will work
3546                                         $P.show( o.fxName_open, o.fxSettings_open, o.fxSpeed_open, function() {
3547                                         lockPaneForFX(pane, false); // undo
3548                                         if (s.isVisible) open_2(); // continue
3549                                         queueNext();
3550                                 });
3551                         }
3552                         else { // no animation
3553                                 _showPane(pane);// just show pane and...
3554                                 open_2();               // continue
3555                                 queueNext();
3556                         };
3557                 });
3558
3559                 // SUBROUTINE
3560                 function open_2 () {
3561                         s.isMoving      = false;
3562
3563                         // cure iframe display issues
3564                         _fixIframe(pane);
3565
3566                         // NOTE: if isSliding, then other panes are NOT 'resized'
3567                         if (!s.isSliding) { // resize all panes adjacent to this one
3568                                 sizeMidPanes(_c[pane].dir=="vert" ? "center" : "", false); // false = NOT skipCallback
3569                         }
3570
3571                         // set classes, position handles and execute callbacks...
3572                         setAsOpen(pane);
3573                 };
3574         
3575         }
3576
3577         /**
3578          * @param {string}      pane            The pane just opened, ie: north, south, east, or west
3579          * @param {boolean=}    [skipCallback=false]
3580          */
3581 ,       setAsOpen = function (pane, skipCallback) {
3582                 var 
3583                         $P              = $Ps[pane]
3584                 ,       $R              = $Rs[pane]
3585                 ,       $T              = $Ts[pane]
3586                 ,       o               = options[pane]
3587                 ,       s               = state[pane]
3588                 ,       side    = _c[pane].side
3589                 ,       rClass  = o.resizerClass
3590                 ,       tClass  = o.togglerClass
3591                 ,       _pane   = "-"+ pane // used for classNames
3592                 ,       _open   = "-open"
3593                 ,       _closed = "-closed"
3594                 ,       _sliding= "-sliding"
3595                 ;
3596                 $R
3597                         .css(side, sC.inset[side] + getPaneSize(pane)) // move the resizer
3598                         .removeClass( rClass+_closed +" "+ rClass+_pane+_closed )
3599                         .addClass( rClass+_open +" "+ rClass+_pane+_open )
3600                 ;
3601                 if (s.isSliding)
3602                         $R.addClass( rClass+_sliding +" "+ rClass+_pane+_sliding )
3603                 else // in case 'was sliding'
3604                         $R.removeClass( rClass+_sliding +" "+ rClass+_pane+_sliding )
3605
3606                 removeHover( 0, $R ); // remove hover classes
3607                 if (o.resizable && $.layout.plugins.draggable)
3608                         $R      .draggable("enable")
3609                                 .css("cursor", o.resizerCursor)
3610                                 .attr("title", o.tips.Resize);
3611                 else if (!s.isSliding)
3612                         $R.css("cursor", "default"); // n-resize, s-resize, etc
3613
3614                 // if pane also has a toggler button, adjust that too
3615                 if ($T) {
3616                         $T      .removeClass( tClass+_closed +" "+ tClass+_pane+_closed )
3617                                 .addClass( tClass+_open +" "+ tClass+_pane+_open )
3618                                 .attr("title", o.tips.Close); // may be blank
3619                         removeHover( 0, $T ); // remove hover classes
3620                         // toggler-content - if exists
3621                         $T.children(".content-closed").hide();
3622                         $T.children(".content-open").css("display","block");
3623                 }
3624
3625                 // sync any 'pin buttons'
3626                 syncPinBtns(pane, !s.isSliding);
3627
3628                 // update pane-state dimensions - BEFORE resizing content
3629                 $.extend(s, elDims($P));
3630
3631                 if (state.initialized) {
3632                         // resize resizer & toggler sizes for all panes
3633                         sizeHandles();
3634                         // resize content every time pane opens - to be sure
3635                         sizeContent(pane, true); // true = remeasure headers/footers, even if 'pane.isMoving'
3636                 }
3637
3638                 if (!skipCallback && (state.initialized || o.triggerEventsOnLoad) && $P.is(":visible")) {
3639                         // onopen callback
3640                         _runCallbacks("onopen_end", pane);
3641                         // onshow callback - TODO: should this be here?
3642                         if (s.isShowing) _runCallbacks("onshow_end", pane);
3643
3644                         // ALSO call onresize because layout-size *may* have changed while pane was closed
3645                         if (state.initialized)
3646                                 _runCallbacks("onresize_end", pane);
3647                 }
3648
3649                 // TODO: Somehow sizePane("north") is being called after this point???
3650         }
3651
3652
3653         /**
3654          * slideOpen / slideClose / slideToggle
3655          *
3656          * Pass-though methods for sliding
3657          */
3658 ,       slideOpen = function (evt_or_pane) {
3659                 if (!isInitialized()) return;
3660                 var     evt             = evtObj(evt_or_pane)
3661                 ,       pane    = evtPane.call(this, evt_or_pane)
3662                 ,       s               = state[pane]
3663                 ,       delay   = options[pane].slideDelay_open
3664                 ;
3665                 if (pane === "center") return; // validate
3666                 // prevent event from triggering on NEW resizer binding created below
3667                 if (evt) evt.stopImmediatePropagation();
3668
3669                 if (s.isClosed && evt && evt.type === "mouseenter" && delay > 0)
3670                         // trigger = mouseenter - use a delay
3671                         timer.set(pane+"_openSlider", open_NOW, delay);
3672                 else
3673                         open_NOW(); // will unbind events if is already open
3674
3675                 /**
3676                  * SUBROUTINE for timed open
3677                  */
3678                 function open_NOW () {
3679                         if (!s.isClosed) // skip if no longer closed!
3680                                 bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane
3681                         else if (!s.isMoving)
3682                                 open(pane, true); // true = slide - open() will handle binding
3683                 };
3684         }
3685
3686 ,       slideClose = function (evt_or_pane) {
3687                 if (!isInitialized()) return;
3688                 var     evt             = evtObj(evt_or_pane)
3689                 ,       pane    = evtPane.call(this, evt_or_pane)
3690                 ,       o               = options[pane]
3691                 ,       s               = state[pane]
3692                 ,       delay   = s.isMoving ? 1000 : 300 // MINIMUM delay - option may override
3693                 ;
3694                 if (pane === "center") return; // validate
3695                 if (s.isClosed || s.isResizing)
3696                         return; // skip if already closed OR in process of resizing
3697                 else if (o.slideTrigger_close === "click")
3698                         close_NOW(); // close immediately onClick
3699                 else if (o.preventQuickSlideClose && s.isMoving)
3700                         return; // handle Chrome quick-close on slide-open
3701                 else if (o.preventPrematureSlideClose && evt && $.layout.isMouseOverElem(evt, $Ps[pane]))
3702                         return; // handle incorrect mouseleave trigger, like when over a SELECT-list in IE
3703                 else if (evt) // trigger = mouseleave - use a delay
3704                         // 1 sec delay if 'opening', else .3 sec
3705                         timer.set(pane+"_closeSlider", close_NOW, max(o.slideDelay_close, delay));
3706                 else // called programically
3707                         close_NOW();
3708
3709                 /**
3710                  * SUBROUTINE for timed close
3711                  */
3712                 function close_NOW () {
3713                         if (s.isClosed) // skip 'close' if already closed!
3714                                 bindStopSlidingEvents(pane, false); // UNBIND trigger events - TODO: is this needed here?
3715                         else if (!s.isMoving)
3716                                 close(pane); // close will handle unbinding
3717                 };
3718         }
3719
3720         /**
3721          * @param {(string|Object)}     evt_or_pane             The pane being opened, ie: north, south, east, or west
3722          */
3723 ,       slideToggle = function (evt_or_pane) {
3724                 var pane = evtPane.call(this, evt_or_pane);
3725                 toggle(pane, true);
3726         }
3727
3728
3729         /**
3730          * Must set left/top on East/South panes so animation will work properly
3731          *
3732          * @param {string}      pane    The pane to lock, 'east' or 'south' - any other is ignored!
3733          * @param {boolean}     doLock  true = set left/top, false = remove
3734          */
3735 ,       lockPaneForFX = function (pane, doLock) {
3736                 var $P  = $Ps[pane]
3737                 ,       s       = state[pane]
3738                 ,       o       = options[pane]
3739                 ,       z       = options.zIndexes
3740                 ;
3741                 if (doLock) {
3742                         showMasks( pane, { animation: true, objectsOnly: true });
3743                         $P.css({ zIndex: z.pane_animate }); // overlay all elements during animation
3744                         if (pane=="south")
3745                                 $P.css({ top: sC.inset.top + sC.innerHeight - $P.outerHeight() });
3746                         else if (pane=="east")
3747                                 $P.css({ left: sC.inset.left + sC.innerWidth - $P.outerWidth() });
3748                 }
3749                 else { // animation DONE - RESET CSS
3750                         hideMasks();
3751                         $P.css({ zIndex: (s.isSliding ? z.pane_sliding : z.pane_normal) });
3752                         if (pane=="south")
3753                                 $P.css({ top: "auto" });
3754                         // if pane is positioned 'off-screen', then DO NOT screw with it!
3755                         else if (pane=="east" && !$P.css("left").match(/\-99999/))
3756                                 $P.css({ left: "auto" });
3757                         // fix anti-aliasing in IE - only needed for animations that change opacity
3758                         if (browser.msie && o.fxOpacityFix && o.fxName_open != "slide" && $P.css("filter") && $P.css("opacity") == 1)
3759                                 $P[0].style.removeAttribute('filter');
3760                 }
3761         }
3762
3763
3764         /**
3765          * Toggle sliding functionality of a specific pane on/off by adding removing 'slide open' trigger
3766          *
3767          * @see  open(), close()
3768          * @param {string}      pane    The pane to enable/disable, 'north', 'south', etc.
3769          * @param {boolean}     enable  Enable or Disable sliding?
3770          */
3771 ,       bindStartSlidingEvents = function (pane, enable) {
3772                 var o           = options[pane]
3773                 ,       $P              = $Ps[pane]
3774                 ,       $R              = $Rs[pane]
3775                 ,       evtName = o.slideTrigger_open.toLowerCase()
3776                 ;
3777                 if (!$R || (enable && !o.slidable)) return;
3778
3779                 // make sure we have a valid event
3780                 if (evtName.match(/mouseover/))
3781                         evtName = o.slideTrigger_open = "mouseenter";
3782                 else if (!evtName.match(/(click|dblclick|mouseenter)/)) 
3783                         evtName = o.slideTrigger_open = "click";
3784
3785                 // must remove double-click-toggle when using dblclick-slide
3786                 if (o.resizerDblClickToggle && evtName.match(/click/)) {
3787                         $R[enable ? "unbind" : "bind"]('dblclick.'+ sID, toggle)
3788                 }
3789
3790                 $R
3791                         // add or remove event
3792                         [enable ? "bind" : "unbind"](evtName +'.'+ sID, slideOpen)
3793                         // set the appropriate cursor & title/tip
3794                         .css("cursor", enable ? o.sliderCursor : "default")
3795                         .attr("title", enable ? o.tips.Slide : "")
3796                 ;
3797         }
3798
3799         /**
3800          * Add or remove 'mouseleave' events to 'slide close' when pane is 'sliding' open or closed
3801          * Also increases zIndex when pane is sliding open
3802          * See bindStartSlidingEvents for code to control 'slide open'
3803          *
3804          * @see  slideOpen(), slideClose()
3805          * @param {string}      pane    The pane to process, 'north', 'south', etc.
3806          * @param {boolean}     enable  Enable or Disable events?
3807          */
3808 ,       bindStopSlidingEvents = function (pane, enable) {
3809                 var     o               = options[pane]
3810                 ,       s               = state[pane]
3811                 ,       c               = _c[pane]
3812                 ,       z               = options.zIndexes
3813                 ,       evtName = o.slideTrigger_close.toLowerCase()
3814                 ,       action  = (enable ? "bind" : "unbind")
3815                 ,       $P              = $Ps[pane]
3816                 ,       $R              = $Rs[pane]
3817                 ;
3818                 timer.clear(pane+"_closeSlider"); // just in case
3819
3820                 if (enable) {
3821                         s.isSliding = true;
3822                         state.panesSliding[pane] = true;
3823                         // remove 'slideOpen' event from resizer
3824                         // ALSO will raise the zIndex of the pane & resizer
3825                         bindStartSlidingEvents(pane, false);
3826                 }
3827                 else {
3828                         s.isSliding = false;
3829                         delete state.panesSliding[pane];
3830                 }
3831
3832                 // RE/SET zIndex - increases when pane is sliding-open, resets to normal when not
3833                 $P.css("zIndex", enable ? z.pane_sliding : z.pane_normal);
3834                 $R.css("zIndex", enable ? z.pane_sliding+2 : z.resizer_normal); // NOTE: mask = pane_sliding+1
3835
3836                 // make sure we have a valid event
3837                 if (!evtName.match(/(click|mouseleave)/))
3838                         evtName = o.slideTrigger_close = "mouseleave"; // also catches 'mouseout'
3839
3840                 // add/remove slide triggers
3841                 $R[action](evtName, slideClose); // base event on resize
3842                 // need extra events for mouseleave
3843                 if (evtName === "mouseleave") {
3844                         // also close on pane.mouseleave
3845                         $P[action]("mouseleave."+ sID, slideClose);
3846                         // cancel timer when mouse moves between 'pane' and 'resizer'
3847                         $R[action]("mouseenter."+ sID, cancelMouseOut);
3848                         $P[action]("mouseenter."+ sID, cancelMouseOut);
3849                 }
3850
3851                 if (!enable)
3852                         timer.clear(pane+"_closeSlider");
3853                 else if (evtName === "click" && !o.resizable) {
3854                         // IF pane is not resizable (which already has a cursor and tip) 
3855                         // then set the a cursor & title/tip on resizer when sliding
3856                         $R.css("cursor", enable ? o.sliderCursor : "default");
3857                         $R.attr("title", enable ? o.tips.Close : ""); // use Toggler-tip, eg: "Close Pane"
3858                 }
3859
3860                 // SUBROUTINE for mouseleave timer clearing
3861                 function cancelMouseOut (evt) {
3862                         timer.clear(pane+"_closeSlider");
3863                         evt.stopPropagation();
3864                 }
3865         }
3866
3867
3868         /**
3869          * Hides/closes a pane if there is insufficient room - reverses this when there is room again
3870          * MUST have already called setSizeLimits() before calling this method
3871          *
3872          * @param {string}      pane                                    The pane being resized
3873          * @param {boolean=}    [isOpening=false]               Called from onOpen?
3874          * @param {boolean=}    [skipCallback=false]    Should the onresize callback be run?
3875          * @param {boolean=}    [force=false]
3876          */
3877 ,       makePaneFit = function (pane, isOpening, skipCallback, force) {
3878                 var     o       = options[pane]
3879                 ,       s       = state[pane]
3880                 ,       c       = _c[pane]
3881                 ,       $P      = $Ps[pane]
3882                 ,       $R      = $Rs[pane]
3883                 ,       isSidePane      = c.dir==="vert"
3884                 ,       hasRoom         = false
3885                 ;
3886                 // special handling for center & east/west panes
3887                 if (pane === "center" || (isSidePane && s.noVerticalRoom)) {
3888                         // see if there is enough room to display the pane
3889                         // ERROR: hasRoom = s.minHeight <= s.maxHeight && (isSidePane || s.minWidth <= s.maxWidth);
3890                         hasRoom = (s.maxHeight >= 0);
3891                         if (hasRoom && s.noRoom) { // previously hidden due to noRoom, so show now
3892                                 _showPane(pane);
3893                                 if ($R) $R.show();
3894                                 s.isVisible = true;
3895                                 s.noRoom = false;
3896                                 if (isSidePane) s.noVerticalRoom = false;
3897                                 _fixIframe(pane);
3898                         }
3899                         else if (!hasRoom && !s.noRoom) { // not currently hidden, so hide now
3900                                 _hidePane(pane);
3901                                 if ($R) $R.hide();
3902                                 s.isVisible = false;
3903                                 s.noRoom = true;
3904                         }
3905                 }
3906
3907                 // see if there is enough room to fit the border-pane
3908                 if (pane === "center") {
3909                         // ignore center in this block
3910                 }
3911                 else if (s.minSize <= s.maxSize) { // pane CAN fit
3912                         hasRoom = true;
3913                         if (s.size > s.maxSize) // pane is too big - shrink it
3914                                 sizePane(pane, s.maxSize, skipCallback, true, force); // true = noAnimation
3915                         else if (s.size < s.minSize) // pane is too small - enlarge it
3916                                 sizePane(pane, s.minSize, skipCallback, true, force); // true = noAnimation
3917                         // need s.isVisible because new pseudoClose method keeps pane visible, but off-screen
3918                         else if ($R && s.isVisible && $P.is(":visible")) {
3919                                 // make sure resizer-bar is positioned correctly
3920                                 // handles situation where nested layout was 'hidden' when initialized
3921                                 var     pos = s.size + sC.inset[c.side];
3922                                 if ($.layout.cssNum( $R, c.side ) != pos) $R.css( c.side, pos );
3923                         }
3924
3925                         // if was previously hidden due to noRoom, then RESET because NOW there is room
3926                         if (s.noRoom) {
3927                                 // s.noRoom state will be set by open or show
3928                                 if (s.wasOpen && o.closable) {
3929                                         if (o.autoReopen)
3930                                                 open(pane, false, true, true); // true = noAnimation, true = noAlert
3931                                         else // leave the pane closed, so just update state
3932                                                 s.noRoom = false;
3933                                 }
3934                                 else
3935                                         show(pane, s.wasOpen, true, true); // true = noAnimation, true = noAlert
3936                         }
3937                 }
3938                 else { // !hasRoom - pane CANNOT fit
3939                         if (!s.noRoom) { // pane not set as noRoom yet, so hide or close it now...
3940                                 s.noRoom = true; // update state
3941                                 s.wasOpen = !s.isClosed && !s.isSliding;
3942                                 if (s.isClosed){} // SKIP
3943                                 else if (o.closable) // 'close' if possible
3944                                         close(pane, true, true); // true = force, true = noAnimation
3945                                 else // 'hide' pane if cannot just be closed
3946                                         hide(pane, true); // true = noAnimation
3947                         }
3948                 }
3949         }
3950
3951
3952         /**
3953          * manualSizePane is an exposed flow-through method allowing extra code when pane is 'manually resized'
3954          *
3955          * @param {(string|Object)}     evt_or_pane                             The pane being resized
3956          * @param {number}                      size                                    The *desired* new size for this pane - will be validated
3957          * @param {boolean=}                    [skipCallback=false]    Should the onresize callback be run?
3958          * @param {boolean=}                    [noAnimation=false]
3959          * @param {boolean=}                    [force=false]                   Force resizing even if does not seem necessary
3960          */
3961 ,       manualSizePane = function (evt_or_pane, size, skipCallback, noAnimation, force) {
3962                 if (!isInitialized()) return;
3963                 var     pane = evtPane.call(this, evt_or_pane)
3964                 ,       o       = options[pane]
3965                 ,       s       = state[pane]
3966                 //      if resizing callbacks have been delayed and resizing is now DONE, force resizing to complete...
3967                 ,       forceResize = force || (o.livePaneResizing && !s.isResizing)
3968                 ;
3969                 if (pane === "center") return; // validate
3970                 // ANY call to manualSizePane disables autoResize - ie, percentage sizing
3971                 s.autoResize = false;
3972                 // flow-through...
3973                 sizePane(pane, size, skipCallback, noAnimation, forceResize); // will animate resize if option enabled
3974         }
3975
3976         /**
3977          * sizePane is called only by internal methods whenever a pane needs to be resized
3978          *
3979          * @param {(string|Object)}     evt_or_pane                             The pane being resized
3980          * @param {number}                      size                                    The *desired* new size for this pane - will be validated
3981          * @param {boolean=}                    [skipCallback=false]    Should the onresize callback be run?
3982          * @param {boolean=}                    [noAnimation=false]
3983          * @param {boolean=}                    [force=false]                   Force resizing even if does not seem necessary
3984          */
3985 ,       sizePane = function (evt_or_pane, size, skipCallback, noAnimation, force) {
3986                 if (!isInitialized()) return;
3987                 var     pane    = evtPane.call(this, evt_or_pane) // probably NEVER called from event?
3988                 ,       o               = options[pane]
3989                 ,       s               = state[pane]
3990                 ,       $P              = $Ps[pane]
3991                 ,       $R              = $Rs[pane]
3992                 ,       side    = _c[pane].side
3993                 ,       dimName = _c[pane].sizeType.toLowerCase()
3994                 ,       skipResizeWhileDragging = s.isResizing && !o.triggerEventsDuringLiveResize
3995                 ,       doFX    = noAnimation !== true && o.animatePaneSizing
3996                 ,       oldSize, newSize
3997                 ;
3998                 if (pane === "center") return; // validate
3999                 // QUEUE in case another action/animation is in progress
4000                 $N.queue(function( queueNext ){
4001                         // calculate 'current' min/max sizes
4002                         setSizeLimits(pane); // update pane-state
4003                         oldSize = s.size;
4004                         size = _parseSize(pane, size); // handle percentages & auto
4005                         size = max(size, _parseSize(pane, o.minSize));
4006                         size = min(size, s.maxSize);
4007                         if (size < s.minSize) { // not enough room for pane!
4008                                 queueNext(); // call before makePaneFit() because it needs the queue free
4009                                 makePaneFit(pane, false, skipCallback); // will hide or close pane
4010                                 return;
4011                         }
4012
4013                         // IF newSize is same as oldSize, then nothing to do - abort
4014                         if (!force && size === oldSize)
4015                                 return queueNext();
4016
4017                         s.newSize = size;
4018
4019                         // onresize_start callback CANNOT cancel resizing because this would break the layout!
4020                         if (!skipCallback && state.initialized && s.isVisible)
4021                                 _runCallbacks("onresize_start", pane);
4022
4023                         // resize the pane, and make sure its visible
4024                         newSize = cssSize(pane, size);
4025
4026                         if (doFX && $P.is(":visible")) { // ANIMATE
4027                                 var fx          = $.layout.effects.size[pane] || $.layout.effects.size.all
4028                                 ,       easing  = o.fxSettings_size.easing || fx.easing
4029                                 ,       z               = options.zIndexes
4030                                 ,       props   = {};
4031                                 props[ dimName ] = newSize +'px';
4032                                 s.isMoving = true;
4033                                 // overlay all elements during animation
4034                                 $P.css({ zIndex: z.pane_animate })
4035                                   .show().animate( props, o.fxSpeed_size, easing, function(){
4036                                         // reset zIndex after animation
4037                                         $P.css({ zIndex: (s.isSliding ? z.pane_sliding : z.pane_normal) });
4038                                         s.isMoving = false;
4039                                         delete s.newSize;
4040                                         sizePane_2(); // continue
4041                                         queueNext();
4042                                 });
4043                         }
4044                         else { // no animation
4045                                 $P.css( dimName, newSize );     // resize pane
4046                                 delete s.newSize;
4047                                 // if pane is visible, then 
4048                                 if ($P.is(":visible"))
4049                                         sizePane_2(); // continue
4050                                 else {
4051                                         // pane is NOT VISIBLE, so just update state data...
4052                                         // when pane is *next opened*, it will have the new size
4053                                         s.size = size;                          // update state.size
4054                                         //$.extend(s, elDims($P));      // update state dimensions - CANNOT do this when not visible!                           }
4055                                 }
4056                                 queueNext();
4057                         };
4058
4059                 });
4060
4061                 // SUBROUTINE
4062                 function sizePane_2 () {
4063                         /*      Panes are sometimes not sized precisely in some browsers!?
4064                          *      This code will resize the pane up to 3 times to nudge the pane to the correct size
4065                          */
4066                         var     actual  = dimName==='width' ? $P.outerWidth() : $P.outerHeight()
4067                         ,       tries   = [{
4068                                                         pane:           pane
4069                                                 ,       count:          1
4070                                                 ,       target:         size
4071                                                 ,       actual:         actual
4072                                                 ,       correct:        (size === actual)
4073                                                 ,       attempt:        size
4074                                                 ,       cssSize:        newSize
4075                                                 }]
4076                         ,       lastTry = tries[0]
4077                         ,       thisTry = {}
4078                         ,       msg             = 'Inaccurate size after resizing the '+ pane +'-pane.'
4079                         ;
4080                         while ( !lastTry.correct ) {
4081                                 thisTry = { pane: pane, count: lastTry.count+1, target: size };
4082
4083                                 if (lastTry.actual > size)
4084                                         thisTry.attempt = max(0, lastTry.attempt - (lastTry.actual - size));
4085                                 else // lastTry.actual < size
4086                                         thisTry.attempt = max(0, lastTry.attempt + (size - lastTry.actual));
4087
4088                                 thisTry.cssSize = cssSize(pane, thisTry.attempt);
4089                                 $P.css( dimName, thisTry.cssSize );
4090
4091                                 thisTry.actual  = dimName=='width' ? $P.outerWidth() : $P.outerHeight();
4092                                 thisTry.correct = (size === thisTry.actual);
4093
4094                                 // log attempts and alert the user of this *non-fatal error* (if showDebugMessages)
4095                                 if ( tries.length === 1) {
4096                                         _log(msg, false, true);
4097                                         _log(lastTry, false, true);
4098                                 }
4099                                 _log(thisTry, false, true);
4100                                 // after 4 tries, is as close as its gonna get!
4101                                 if (tries.length > 3) break;
4102
4103                                 tries.push( thisTry );
4104                                 lastTry = tries[ tries.length - 1 ];
4105                         }
4106                         // END TESTING CODE
4107
4108                         // update pane-state dimensions
4109                         s.size  = size;
4110                         $.extend(s, elDims($P));
4111
4112                         if (s.isVisible && $P.is(":visible")) {
4113                                 // reposition the resizer-bar
4114                                 if ($R) $R.css( side, size + sC.inset[side] );
4115                                 // resize the content-div
4116                                 sizeContent(pane);
4117                         }
4118
4119                         if (!skipCallback && !skipResizeWhileDragging && state.initialized && s.isVisible)
4120                                 _runCallbacks("onresize_end", pane);
4121
4122                         // resize all the adjacent panes, and adjust their toggler buttons
4123                         // when skipCallback passed, it means the controlling method will handle 'other panes'
4124                         if (!skipCallback) {
4125                                 // also no callback if live-resize is in progress and NOT triggerEventsDuringLiveResize
4126                                 if (!s.isSliding) sizeMidPanes(_c[pane].dir=="horz" ? "" : "center", skipResizeWhileDragging, force);
4127                                 sizeHandles();
4128                         }
4129
4130                         // if opposite-pane was autoClosed, see if it can be autoOpened now
4131                         var altPane = _c.oppositeEdge[pane];
4132                         if (size < oldSize && state[ altPane ].noRoom) {
4133                                 setSizeLimits( altPane );
4134                                 makePaneFit( altPane, false, skipCallback );
4135                         }
4136
4137                         // DEBUG - ALERT user/developer so they know there was a sizing problem
4138                         if (tries.length > 1)
4139                                 _log(msg +'\nSee the Error Console for details.', true, true);
4140                 }
4141         }
4142
4143         /**
4144          * @see  initPanes(), sizePane(),       resizeAll(), open(), close(), hide()
4145          * @param {(Array.<string>|string)}     panes                                   The pane(s) being resized, comma-delmited string
4146          * @param {boolean=}                                    [skipCallback=false]    Should the onresize callback be run?
4147          * @param {boolean=}                                    [force=false]
4148          */
4149 ,       sizeMidPanes = function (panes, skipCallback, force) {
4150                 panes = (panes ? panes : "east,west,center").split(",");
4151
4152                 $.each(panes, function (i, pane) {
4153                         if (!$Ps[pane]) return; // NO PANE - skip
4154                         var 
4155                                 o               = options[pane]
4156                         ,       s               = state[pane]
4157                         ,       $P              = $Ps[pane]
4158                         ,       $R              = $Rs[pane]
4159                         ,       isCenter= (pane=="center")
4160                         ,       hasRoom = true
4161                         ,       CSS             = {}
4162                         //      if pane is not visible, show it invisibly NOW rather than for *each call* in this script
4163                         ,       visCSS  = $.layout.showInvisibly($P)
4164
4165                         ,       newCenter       = calcNewCenterPaneDims()
4166                         ;
4167
4168                         // update pane-state dimensions
4169                         $.extend(s, elDims($P));
4170
4171                         if (pane === "center") {
4172                                 if (!force && s.isVisible && newCenter.width === s.outerWidth && newCenter.height === s.outerHeight) {
4173                                         $P.css(visCSS);
4174                                         return true; // SKIP - pane already the correct size
4175                                 }
4176                                 // set state for makePaneFit() logic
4177                                 $.extend(s, cssMinDims(pane), {
4178                                         maxWidth:       newCenter.width
4179                                 ,       maxHeight:      newCenter.height
4180                                 });
4181                                 CSS = newCenter;
4182                                 s.newWidth      = CSS.width;
4183                                 s.newHeight     = CSS.height;
4184                                 // convert OUTER width/height to CSS width/height 
4185                                 CSS.width       = cssW($P, CSS.width);
4186                                 // NEW - allow pane to extend 'below' visible area rather than hide it
4187                                 CSS.height      = cssH($P, CSS.height);
4188                                 hasRoom         = CSS.width >= 0 && CSS.height >= 0; // height >= 0 = ALWAYS TRUE NOW
4189
4190                                 // during layout init, try to shrink east/west panes to make room for center
4191                                 if (!state.initialized && o.minWidth > newCenter.width) {
4192                                         var
4193                                                 reqPx   = o.minWidth - s.outerWidth
4194                                         ,       minE    = options.east.minSize || 0
4195                                         ,       minW    = options.west.minSize || 0
4196                                         ,       sizeE   = state.east.size
4197                                         ,       sizeW   = state.west.size
4198                                         ,       newE    = sizeE
4199                                         ,       newW    = sizeW
4200                                         ;
4201                                         if (reqPx > 0 && state.east.isVisible && sizeE > minE) {
4202                                                 newE = max( sizeE-minE, sizeE-reqPx );
4203                                                 reqPx -= sizeE-newE;
4204                                         }
4205                                         if (reqPx > 0 && state.west.isVisible && sizeW > minW) {
4206                                                 newW = max( sizeW-minW, sizeW-reqPx );
4207                                                 reqPx -= sizeW-newW;
4208                                         }
4209                                         // IF we found enough extra space, then resize the border panes as calculated
4210                                         if (reqPx === 0) {
4211                                                 if (sizeE && sizeE != minE)
4212                                                         sizePane('east', newE, true, true, force); // true = skipCallback/noAnimation - initPanes will handle when done
4213                                                 if (sizeW && sizeW != minW)
4214                                                         sizePane('west', newW, true, true, force); // true = skipCallback/noAnimation
4215                                                 // now start over!
4216                                                 sizeMidPanes('center', skipCallback, force);
4217                                                 $P.css(visCSS);
4218                                                 return; // abort this loop
4219                                         }
4220                                 }
4221                         }
4222                         else { // for east and west, set only the height, which is same as center height
4223                                 // set state.min/maxWidth/Height for makePaneFit() logic
4224                                 if (s.isVisible && !s.noVerticalRoom)
4225                                         $.extend(s, elDims($P), cssMinDims(pane))
4226                                 if (!force && !s.noVerticalRoom && newCenter.height === s.outerHeight) {
4227                                         $P.css(visCSS);
4228                                         return true; // SKIP - pane already the correct size
4229                                 }
4230                                 // east/west have same top, bottom & height as center
4231                                 CSS.top         = newCenter.top;
4232                                 CSS.bottom      = newCenter.bottom;
4233                                 s.newSize       = newCenter.height
4234                                 // NEW - allow pane to extend 'below' visible area rather than hide it
4235                                 CSS.height      = cssH($P, newCenter.height);
4236                                 s.maxHeight     = CSS.height;
4237                                 hasRoom         = (s.maxHeight >= 0); // ALWAYS TRUE NOW
4238                                 if (!hasRoom) s.noVerticalRoom = true; // makePaneFit() logic
4239                         }
4240
4241                         if (hasRoom) {
4242                                 // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized
4243                                 if (!skipCallback && state.initialized)
4244                                         _runCallbacks("onresize_start", pane);
4245
4246                                 $P.css(CSS); // apply the CSS to pane
4247                                 if (pane !== "center")
4248                                         sizeHandles(pane); // also update resizer length
4249                                 if (s.noRoom && !s.isClosed && !s.isHidden)
4250                                         makePaneFit(pane); // will re-open/show auto-closed/hidden pane
4251                                 if (s.isVisible) {
4252                                         $.extend(s, elDims($P)); // update pane dimensions
4253                                         if (state.initialized) sizeContent(pane); // also resize the contents, if exists
4254                                 }
4255                         }
4256                         else if (!s.noRoom && s.isVisible) // no room for pane
4257                                 makePaneFit(pane); // will hide or close pane
4258
4259                         // reset visibility, if necessary
4260                         $P.css(visCSS);
4261
4262                         delete s.newSize;
4263                         delete s.newWidth;
4264                         delete s.newHeight;
4265
4266                         if (!s.isVisible)
4267                                 return true; // DONE - next pane
4268
4269                         /*
4270                          * Extra CSS for IE6 or IE7 in Quirks-mode - add 'width' to NORTH/SOUTH panes
4271                          * Normally these panes have only 'left' & 'right' positions so pane auto-sizes
4272                          * ALSO required when pane is an IFRAME because will NOT default to 'full width'
4273                          *      TODO: Can I use width:100% for a north/south iframe?
4274                          *      TODO: Sounds like a job for $P.outerWidth( sC.innerWidth ) SETTER METHOD
4275                          */
4276                         if (pane === "center") { // finished processing midPanes
4277                                 var fix = browser.isIE6 || !browser.boxModel;
4278                                 if ($Ps.north && (fix || state.north.tagName=="IFRAME")) 
4279                                         $Ps.north.css("width", cssW($Ps.north, sC.innerWidth));
4280                                 if ($Ps.south && (fix || state.south.tagName=="IFRAME"))
4281                                         $Ps.south.css("width", cssW($Ps.south, sC.innerWidth));
4282                         }
4283
4284                         // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized
4285                         if (!skipCallback && state.initialized)
4286                                 _runCallbacks("onresize_end", pane);
4287                 });
4288         }
4289
4290
4291         /**
4292          * @see  window.onresize(), callbacks or custom code
4293          * @param {(Object|boolean)=}   evt_or_refresh  If 'true', then also reset pane-positioning
4294          */
4295 ,       resizeAll = function (evt_or_refresh) {
4296                 var     oldW    = sC.innerWidth
4297                 ,       oldH    = sC.innerHeight
4298                 ;
4299                 // stopPropagation if called by trigger("layoutdestroy") - use evtPane utility 
4300                 evtPane(evt_or_refresh);
4301
4302                 // cannot size layout when 'container' is hidden or collapsed
4303                 if (!$N.is(":visible")) return;
4304
4305                 if (!state.initialized) {
4306                         _initLayoutElements();
4307                         return; // no need to resize since we just initialized!
4308                 }
4309
4310                 if (evt_or_refresh === true && $.isPlainObject(options.outset)) {
4311                         // update container CSS in case outset option has changed
4312                         $N.css( options.outset );
4313                 }
4314                 // UPDATE container dimensions
4315                 $.extend(sC, elDims( $N, options.inset ));
4316                 if (!sC.outerHeight) return;
4317
4318                 // if 'true' passed, refresh pane & handle positioning too
4319                 if (evt_or_refresh === true) {
4320                         setPanePosition();
4321                 }
4322
4323                 // onresizeall_start will CANCEL resizing if returns false
4324                 // state.container has already been set, so user can access this info for calcuations
4325                 if (false === _runCallbacks("onresizeall_start")) return false;
4326
4327                 var     // see if container is now 'smaller' than before
4328                         shrunkH = (sC.innerHeight < oldH)
4329                 ,       shrunkW = (sC.innerWidth < oldW)
4330                 ,       $P, o, s
4331                 ;
4332                 // NOTE special order for sizing: S-N-E-W
4333                 $.each(["south","north","east","west"], function (i, pane) {
4334                         if (!$Ps[pane]) return; // no pane - SKIP
4335                         o = options[pane];
4336                         s = state[pane];
4337                         if (s.autoResize && s.size != o.size) // resize pane to original size set in options
4338                                 sizePane(pane, o.size, true, true, true); // true=skipCallback/noAnimation/forceResize
4339                         else {
4340                                 setSizeLimits(pane);
4341                                 makePaneFit(pane, false, true, true); // true=skipCallback/forceResize
4342                         }
4343                 });
4344
4345                 sizeMidPanes("", true, true); // true=skipCallback/forceResize
4346                 sizeHandles(); // reposition the toggler elements
4347
4348                 // trigger all individual pane callbacks AFTER layout has finished resizing
4349                 $.each(_c.allPanes, function (i, pane) {
4350                         $P = $Ps[pane];
4351                         if (!$P) return; // SKIP
4352                         if (state[pane].isVisible) // undefined for non-existent panes
4353                                 _runCallbacks("onresize_end", pane); // callback - if exists
4354                 });
4355
4356                 _runCallbacks("onresizeall_end");
4357                 //_triggerLayoutEvent(pane, 'resizeall');
4358         }
4359
4360         /**
4361          * Whenever a pane resizes or opens that has a nested layout, trigger resizeAll
4362          *
4363          * @param {(string|Object)}     evt_or_pane             The pane just resized or opened
4364          */
4365 ,       resizeChildren = function (evt_or_pane, skipRefresh) {
4366                 var     pane = evtPane.call(this, evt_or_pane);
4367
4368                 if (!options[pane].resizeChildren) return;
4369
4370                 // ensure the pane-children are up-to-date
4371                 if (!skipRefresh) refreshChildren( pane );
4372                 var pC = children[pane];
4373                 if ($.isPlainObject( pC )) {
4374                         // resize one or more children
4375                         $.each( pC, function (key, child) {
4376                                 if (!child.destroyed) child.resizeAll();
4377                         });
4378                 }
4379         }
4380
4381         /**
4382          * IF pane has a content-div, then resize all elements inside pane to fit pane-height
4383          *
4384          * @param {(string|Object)}     evt_or_panes            The pane(s) being resized
4385          * @param {boolean=}                    [remeasure=false]       Should the content (header/footer) be remeasured?
4386          */
4387 ,       sizeContent = function (evt_or_panes, remeasure) {
4388                 if (!isInitialized()) return;
4389
4390                 var panes = evtPane.call(this, evt_or_panes);
4391                 panes = panes ? panes.split(",") : _c.allPanes;
4392
4393                 $.each(panes, function (idx, pane) {
4394                         var
4395                                 $P      = $Ps[pane]
4396                         ,       $C      = $Cs[pane]
4397                         ,       o       = options[pane]
4398                         ,       s       = state[pane]
4399                         ,       m       = s.content // m = measurements
4400                         ;
4401                         if (!$P || !$C || !$P.is(":visible")) return true; // NOT VISIBLE - skip
4402
4403                         // if content-element was REMOVED, update OR remove the pointer
4404                         if (!$C.length) {
4405                                 initContent(pane, false);       // false = do NOT sizeContent() - already there!
4406                                 if (!$C) return;                        // no replacement element found - pointer have been removed
4407                         }
4408
4409                         // onsizecontent_start will CANCEL resizing if returns false
4410                         if (false === _runCallbacks("onsizecontent_start", pane)) return;
4411
4412                         // skip re-measuring offsets if live-resizing
4413                         if ((!s.isMoving && !s.isResizing) || o.liveContentResizing || remeasure || m.top == undefined) {
4414                                 _measure();
4415                                 // if any footers are below pane-bottom, they may not measure correctly,
4416                                 // so allow pane overflow and re-measure
4417                                 if (m.hiddenFooters > 0 && $P.css("overflow") === "hidden") {
4418                                         $P.css("overflow", "visible");
4419                                         _measure(); // remeasure while overflowing
4420                                         $P.css("overflow", "hidden");
4421                                 }
4422                         }
4423                         // NOTE: spaceAbove/Below *includes* the pane paddingTop/Bottom, but not pane.borders
4424                         var newH = s.innerHeight - (m.spaceAbove - s.css.paddingTop) - (m.spaceBelow - s.css.paddingBottom);
4425
4426                         if (!$C.is(":visible") || m.height != newH) {
4427                                 // size the Content element to fit new pane-size - will autoHide if not enough room
4428                                 setOuterHeight($C, newH, true); // true=autoHide
4429                                 m.height = newH; // save new height
4430                         };
4431
4432                         if (state.initialized)
4433                                 _runCallbacks("onsizecontent_end", pane);
4434
4435                         function _below ($E) {
4436                                 return max(s.css.paddingBottom, (parseInt($E.css("marginBottom"), 10) || 0));
4437                         };
4438
4439                         function _measure () {
4440                                 var
4441                                         ignore  = options[pane].contentIgnoreSelector
4442                                 ,       $Fs             = $C.nextAll().not(".ui-layout-mask").not(ignore || ":lt(0)") // not :lt(0) = ALL
4443                                 ,       $Fs_vis = $Fs.filter(':visible')
4444                                 ,       $F              = $Fs_vis.filter(':last')
4445                                 ;
4446                                 m = {
4447                                         top:                    $C[0].offsetTop
4448                                 ,       height:                 $C.outerHeight()
4449                                 ,       numFooters:             $Fs.length
4450                                 ,       hiddenFooters:  $Fs.length - $Fs_vis.length
4451                                 ,       spaceBelow:             0 // correct if no content footer ($E)
4452                                 }
4453                                         m.spaceAbove    = m.top; // just for state - not used in calc
4454                                         m.bottom                = m.top + m.height;
4455                                 if ($F.length)
4456                                         //spaceBelow = (LastFooter.top + LastFooter.height) [footerBottom] - Content.bottom + max(LastFooter.marginBottom, pane.paddingBotom)
4457                                         m.spaceBelow = ($F[0].offsetTop + $F.outerHeight()) - m.bottom + _below($F);
4458                                 else // no footer - check marginBottom on Content element itself
4459                                         m.spaceBelow = _below($C);
4460                         };
4461                 });
4462         }
4463
4464
4465         /**
4466          * Called every time a pane is opened, closed, or resized to slide the togglers to 'center' and adjust their length if necessary
4467          *
4468          * @see  initHandles(), open(), close(), resizeAll()
4469          * @param {(string|Object)=}            evt_or_panes    The pane(s) being resized
4470          */
4471 ,       sizeHandles = function (evt_or_panes) {
4472                 var panes = evtPane.call(this, evt_or_panes)
4473                 panes = panes ? panes.split(",") : _c.borderPanes;
4474
4475                 $.each(panes, function (i, pane) {
4476                         var 
4477                                 o       = options[pane]
4478                         ,       s       = state[pane]
4479                         ,       $P      = $Ps[pane]
4480                         ,       $R      = $Rs[pane]
4481                         ,       $T      = $Ts[pane]
4482                         ,       $TC
4483                         ;
4484                         if (!$P || !$R) return;
4485
4486                         var
4487                                 dir                     = _c[pane].dir
4488                         ,       _state          = (s.isClosed ? "_closed" : "_open")
4489                         ,       spacing         = o["spacing"+ _state]
4490                         ,       togAlign        = o["togglerAlign"+ _state]
4491                         ,       togLen          = o["togglerLength"+ _state]
4492                         ,       paneLen
4493                         ,       left
4494                         ,       offset
4495                         ,       CSS = {}
4496                         ;
4497
4498                         if (spacing === 0) {
4499                                 $R.hide();
4500                                 return;
4501                         }
4502                         else if (!s.noRoom && !s.isHidden) // skip if resizer was hidden for any reason
4503                                 $R.show(); // in case was previously hidden
4504
4505                         // Resizer Bar is ALWAYS same width/height of pane it is attached to
4506                         if (dir === "horz") { // north/south
4507                                 //paneLen = $P.outerWidth(); // s.outerWidth || 
4508                                 paneLen = sC.innerWidth; // handle offscreen-panes
4509                                 s.resizerLength = paneLen;
4510                                 left = $.layout.cssNum($P, "left")
4511                                 $R.css({
4512                                         width:  cssW($R, paneLen) // account for borders & padding
4513                                 ,       height: cssH($R, spacing) // ditto
4514                                 ,       left:   left > -9999 ? left : sC.inset.left // handle offscreen-panes
4515                                 });
4516                         }
4517                         else { // east/west
4518                                 paneLen = $P.outerHeight(); // s.outerHeight || 
4519                                 s.resizerLength = paneLen;
4520                                 $R.css({
4521                                         height: cssH($R, paneLen) // account for borders & padding
4522                                 ,       width:  cssW($R, spacing) // ditto
4523                                 ,       top:    sC.inset.top + getPaneSize("north", true) // TODO: what if no North pane?
4524                                 //,     top:    $.layout.cssNum($Ps["center"], "top")
4525                                 });
4526                         }
4527
4528                         // remove hover classes
4529                         removeHover( o, $R );
4530
4531                         if ($T) {
4532                                 if (togLen === 0 || (s.isSliding && o.hideTogglerOnSlide)) {
4533                                         $T.hide(); // always HIDE the toggler when 'sliding'
4534                                         return;
4535                                 }
4536                                 else
4537                                         $T.show(); // in case was previously hidden
4538
4539                                 if (!(togLen > 0) || togLen === "100%" || togLen > paneLen) {
4540                                         togLen = paneLen;
4541                                         offset = 0;
4542                                 }
4543                                 else { // calculate 'offset' based on options.PANE.togglerAlign_open/closed
4544                                         if (isStr(togAlign)) {
4545                                                 switch (togAlign) {
4546                                                         case "top":
4547                                                         case "left":    offset = 0;
4548                                                                                         break;
4549                                                         case "bottom":
4550                                                         case "right":   offset = paneLen - togLen;
4551                                                                                         break;
4552                                                         case "middle":
4553                                                         case "center":
4554                                                         default:                offset = round((paneLen - togLen) / 2); // 'default' catches typos
4555                                                 }
4556                                         }
4557                                         else { // togAlign = number
4558                                                 var x = parseInt(togAlign, 10); //
4559                                                 if (togAlign >= 0) offset = x;
4560                                                 else offset = paneLen - togLen + x; // NOTE: x is negative!
4561                                         }
4562                                 }
4563
4564                                 if (dir === "horz") { // north/south
4565                                         var width = cssW($T, togLen);
4566                                         $T.css({
4567                                                 width:  width  // account for borders & padding
4568                                         ,       height: cssH($T, spacing) // ditto
4569                                         ,       left:   offset // TODO: VERIFY that toggler  positions correctly for ALL values
4570                                         ,       top:    0
4571                                         });
4572                                         // CENTER the toggler content SPAN
4573                                         $T.children(".content").each(function(){
4574                                                 $TC = $(this);
4575                                                 $TC.css("marginLeft", round((width-$TC.outerWidth())/2)); // could be negative
4576                                         });
4577                                 }
4578                                 else { // east/west
4579                                         var height = cssH($T, togLen);
4580                                         $T.css({
4581                                                 height: height // account for borders & padding
4582                                         ,       width:  cssW($T, spacing) // ditto
4583                                         ,       top:    offset // POSITION the toggler
4584                                         ,       left:   0
4585                                         });
4586                                         // CENTER the toggler content SPAN
4587                                         $T.children(".content").each(function(){
4588                                                 $TC = $(this);
4589                                                 $TC.css("marginTop", round((height-$TC.outerHeight())/2)); // could be negative
4590                                         });
4591                                 }
4592
4593                                 // remove ALL hover classes
4594                                 removeHover( 0, $T );
4595                         }
4596
4597                         // DONE measuring and sizing this resizer/toggler, so can be 'hidden' now
4598                         if (!state.initialized && (o.initHidden || s.isHidden)) {
4599                                 $R.hide();
4600                                 if ($T) $T.hide();
4601                         }
4602                 });
4603         }
4604
4605
4606         /**
4607          * @param {(string|Object)}     evt_or_pane
4608          */
4609 ,       enableClosable = function (evt_or_pane) {
4610                 if (!isInitialized()) return;
4611                 var     pane = evtPane.call(this, evt_or_pane)
4612                 ,       $T      = $Ts[pane]
4613                 ,       o       = options[pane]
4614                 ;
4615                 if (!$T) return;
4616                 o.closable = true;
4617                 $T      .bind("click."+ sID, function(evt){ evt.stopPropagation(); toggle(pane); })
4618                         .css("visibility", "visible")
4619                         .css("cursor", "pointer")
4620                         .attr("title", state[pane].isClosed ? o.tips.Open : o.tips.Close) // may be blank
4621                         .show();
4622         }
4623         /**
4624          * @param {(string|Object)}     evt_or_pane
4625          * @param {boolean=}                    [hide=false]
4626          */
4627 ,       disableClosable = function (evt_or_pane, hide) {
4628                 if (!isInitialized()) return;
4629                 var     pane = evtPane.call(this, evt_or_pane)
4630                 ,       $T      = $Ts[pane]
4631                 ;
4632                 if (!$T) return;
4633                 options[pane].closable = false;
4634                 // is closable is disable, then pane MUST be open!
4635                 if (state[pane].isClosed) open(pane, false, true);
4636                 $T      .unbind("."+ sID)
4637                         .css("visibility", hide ? "hidden" : "visible") // instead of hide(), which creates logic issues
4638                         .css("cursor", "default")
4639                         .attr("title", "");
4640         }
4641
4642
4643         /**
4644          * @param {(string|Object)}     evt_or_pane
4645          */
4646 ,       enableSlidable = function (evt_or_pane) {
4647                 if (!isInitialized()) return;
4648                 var     pane = evtPane.call(this, evt_or_pane)
4649                 ,       $R      = $Rs[pane]
4650                 ;
4651                 if (!$R || !$R.data('draggable')) return;
4652                 options[pane].slidable = true; 
4653                 if (state[pane].isClosed)
4654                         bindStartSlidingEvents(pane, true);
4655         }
4656         /**
4657          * @param {(string|Object)}     evt_or_pane
4658          */
4659 ,       disableSlidable = function (evt_or_pane) {
4660                 if (!isInitialized()) return;
4661                 var     pane = evtPane.call(this, evt_or_pane)
4662                 ,       $R      = $Rs[pane]
4663                 ;
4664                 if (!$R) return;
4665                 options[pane].slidable = false; 
4666                 if (state[pane].isSliding)
4667                         close(pane, false, true);
4668                 else {
4669                         bindStartSlidingEvents(pane, false);
4670                         $R      .css("cursor", "default")
4671                                 .attr("title", "");
4672                         removeHover(null, $R[0]); // in case currently hovered
4673                 }
4674         }
4675
4676
4677         /**
4678          * @param {(string|Object)}     evt_or_pane
4679          */
4680 ,       enableResizable = function (evt_or_pane) {
4681                 if (!isInitialized()) return;
4682                 var     pane = evtPane.call(this, evt_or_pane)
4683                 ,       $R      = $Rs[pane]
4684                 ,       o       = options[pane]
4685                 ;
4686                 if (!$R || !$R.data('draggable')) return;
4687                 o.resizable = true; 
4688                 $R.draggable("enable");
4689                 if (!state[pane].isClosed)
4690                         $R      .css("cursor", o.resizerCursor)
4691                                 .attr("title", o.tips.Resize);
4692         }
4693         /**
4694          * @param {(string|Object)}     evt_or_pane
4695          */
4696 ,       disableResizable = function (evt_or_pane) {
4697                 if (!isInitialized()) return;
4698                 var     pane = evtPane.call(this, evt_or_pane)
4699                 ,       $R      = $Rs[pane]
4700                 ;
4701                 if (!$R || !$R.data('draggable')) return;
4702                 options[pane].resizable = false; 
4703                 $R      .draggable("disable")
4704                         .css("cursor", "default")
4705                         .attr("title", "");
4706                 removeHover(null, $R[0]); // in case currently hovered
4707         }
4708
4709
4710         /**
4711          * Move a pane from source-side (eg, west) to target-side (eg, east)
4712          * If pane exists on target-side, move that to source-side, ie, 'swap' the panes
4713          *
4714          * @param {(string|Object)}     evt_or_pane1    The pane/edge being swapped
4715          * @param {string}                      pane2                   ditto
4716          */
4717 ,       swapPanes = function (evt_or_pane1, pane2) {
4718                 if (!isInitialized()) return;
4719                 var pane1 = evtPane.call(this, evt_or_pane1);
4720                 // change state.edge NOW so callbacks can know where pane is headed...
4721                 state[pane1].edge = pane2;
4722                 state[pane2].edge = pane1;
4723                 // run these even if NOT state.initialized
4724                 if (false === _runCallbacks("onswap_start", pane1)
4725                  ||     false === _runCallbacks("onswap_start", pane2)
4726                 ) {
4727                         state[pane1].edge = pane1; // reset
4728                         state[pane2].edge = pane2;
4729                         return;
4730                 }
4731
4732                 var
4733                         oPane1  = copy( pane1 )
4734                 ,       oPane2  = copy( pane2 )
4735                 ,       sizes   = {}
4736                 ;
4737                 sizes[pane1] = oPane1 ? oPane1.state.size : 0;
4738                 sizes[pane2] = oPane2 ? oPane2.state.size : 0;
4739
4740                 // clear pointers & state
4741                 $Ps[pane1] = false; 
4742                 $Ps[pane2] = false;
4743                 state[pane1] = {};
4744                 state[pane2] = {};
4745                 
4746                 // ALWAYS remove the resizer & toggler elements
4747                 if ($Ts[pane1]) $Ts[pane1].remove();
4748                 if ($Ts[pane2]) $Ts[pane2].remove();
4749                 if ($Rs[pane1]) $Rs[pane1].remove();
4750                 if ($Rs[pane2]) $Rs[pane2].remove();
4751                 $Rs[pane1] = $Rs[pane2] = $Ts[pane1] = $Ts[pane2] = false;
4752
4753                 // transfer element pointers and data to NEW Layout keys
4754                 move( oPane1, pane2 );
4755                 move( oPane2, pane1 );
4756
4757                 // cleanup objects
4758                 oPane1 = oPane2 = sizes = null;
4759
4760                 // make panes 'visible' again
4761                 if ($Ps[pane1]) $Ps[pane1].css(_c.visible);
4762                 if ($Ps[pane2]) $Ps[pane2].css(_c.visible);
4763
4764                 // fix any size discrepancies caused by swap
4765                 resizeAll();
4766
4767                 // run these even if NOT state.initialized
4768                 _runCallbacks("onswap_end", pane1);
4769                 _runCallbacks("onswap_end", pane2);
4770
4771                 return;
4772
4773                 function copy (n) { // n = pane
4774                         var
4775                                 $P      = $Ps[n]
4776                         ,       $C      = $Cs[n]
4777                         ;
4778                         return !$P ? false : {
4779                                 pane:           n
4780                         ,       P:                      $P ? $P[0] : false
4781                         ,       C:                      $C ? $C[0] : false
4782                         ,       state:          $.extend(true, {}, state[n])
4783                         ,       options:        $.extend(true, {}, options[n])
4784                         }
4785                 };
4786
4787                 function move (oPane, pane) {
4788                         if (!oPane) return;
4789                         var
4790                                 P               = oPane.P
4791                         ,       C               = oPane.C
4792                         ,       oldPane = oPane.pane
4793                         ,       c               = _c[pane]
4794                         //      save pane-options that should be retained
4795                         ,       s               = $.extend(true, {}, state[pane])
4796                         ,       o               = options[pane]
4797                         //      RETAIN side-specific FX Settings - more below
4798                         ,       fx              = { resizerCursor: o.resizerCursor }
4799                         ,       re, size, pos
4800                         ;
4801                         $.each("fxName,fxSpeed,fxSettings".split(","), function (i, k) {
4802                                 fx[k +"_open"]  = o[k +"_open"];
4803                                 fx[k +"_close"] = o[k +"_close"];
4804                                 fx[k +"_size"]  = o[k +"_size"];
4805                         });
4806
4807                         // update object pointers and attributes
4808                         $Ps[pane] = $(P)
4809                                 .data({
4810                                         layoutPane:             Instance[pane]  // NEW pointer to pane-alias-object
4811                                 ,       layoutEdge:             pane
4812                                 })
4813                                 .css(_c.hidden)
4814                                 .css(c.cssReq)
4815                         ;
4816                         $Cs[pane] = C ? $(C) : false;
4817
4818                         // set options and state
4819                         options[pane]   = $.extend(true, {}, oPane.options, fx);
4820                         state[pane]             = $.extend(true, {}, oPane.state);
4821
4822                         // change classNames on the pane, eg: ui-layout-pane-east ==> ui-layout-pane-west
4823                         re = new RegExp(o.paneClass +"-"+ oldPane, "g");
4824                         P.className = P.className.replace(re, o.paneClass +"-"+ pane);
4825
4826                         // ALWAYS regenerate the resizer & toggler elements
4827                         initHandles(pane); // create the required resizer & toggler
4828
4829                         // if moving to different orientation, then keep 'target' pane size
4830                         if (c.dir != _c[oldPane].dir) {
4831                                 size = sizes[pane] || 0;
4832                                 setSizeLimits(pane); // update pane-state
4833                                 size = max(size, state[pane].minSize);
4834                                 // use manualSizePane to disable autoResize - not useful after panes are swapped
4835                                 manualSizePane(pane, size, true, true); // true/true = skipCallback/noAnimation
4836                         }
4837                         else // move the resizer here
4838                                 $Rs[pane].css(c.side, sC.inset[c.side] + (state[pane].isVisible ? getPaneSize(pane) : 0));
4839
4840
4841                         // ADD CLASSNAMES & SLIDE-BINDINGS
4842                         if (oPane.state.isVisible && !s.isVisible)
4843                                 setAsOpen(pane, true); // true = skipCallback
4844                         else {
4845                                 setAsClosed(pane);
4846                                 bindStartSlidingEvents(pane, true); // will enable events IF option is set
4847                         }
4848
4849                         // DESTROY the object
4850                         oPane = null;
4851                 };
4852         }
4853
4854
4855         /**
4856          * INTERNAL method to sync pin-buttons when pane is opened or closed
4857          * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes
4858          *
4859          * @see  open(), setAsOpen(), setAsClosed()
4860          * @param {string}      pane   These are the params returned to callbacks by layout()
4861          * @param {boolean}     doPin  True means set the pin 'down', False means 'up'
4862          */
4863 ,       syncPinBtns = function (pane, doPin) {
4864                 if ($.layout.plugins.buttons)
4865                         $.each(state[pane].pins, function (i, selector) {
4866                                 $.layout.buttons.setPinState(Instance, $(selector), pane, doPin);
4867                         });
4868         }
4869
4870 ;       // END var DECLARATIONS
4871
4872         /**
4873          * Capture keys when enableCursorHotkey - toggle pane if hotkey pressed
4874          *
4875          * @see  document.keydown()
4876          */
4877         function keyDown (evt) {
4878                 if (!evt) return true;
4879                 var code = evt.keyCode;
4880                 if (code < 33) return true; // ignore special keys: ENTER, TAB, etc
4881
4882                 var
4883                         PANE = {
4884                                 38: "north" // Up Cursor        - $.ui.keyCode.UP
4885                         ,       40: "south" // Down Cursor      - $.ui.keyCode.DOWN
4886                         ,       37: "west"  // Left Cursor      - $.ui.keyCode.LEFT
4887                         ,       39: "east"  // Right Cursor     - $.ui.keyCode.RIGHT
4888                         }
4889                 ,       ALT             = evt.altKey // no worky!
4890                 ,       SHIFT   = evt.shiftKey
4891                 ,       CTRL    = evt.ctrlKey
4892                 ,       CURSOR  = (CTRL && code >= 37 && code <= 40)
4893                 ,       o, k, m, pane
4894                 ;
4895
4896                 if (CURSOR && options[PANE[code]].enableCursorHotkey) // valid cursor-hotkey
4897                         pane = PANE[code];
4898                 else if (CTRL || SHIFT) // check to see if this matches a custom-hotkey
4899                         $.each(_c.borderPanes, function (i, p) { // loop each pane to check its hotkey
4900                                 o = options[p];
4901                                 k = o.customHotkey;
4902                                 m = o.customHotkeyModifier; // if missing or invalid, treated as "CTRL+SHIFT"
4903                                 if ((SHIFT && m=="SHIFT") || (CTRL && m=="CTRL") || (CTRL && SHIFT)) { // Modifier matches
4904                                         if (k && code === (isNaN(k) || k <= 9 ? k.toUpperCase().charCodeAt(0) : k)) { // Key matches
4905                                                 pane = p;
4906                                                 return false; // BREAK
4907                                         }
4908                                 }
4909                         });
4910
4911                 // validate pane
4912                 if (!pane || !$Ps[pane] || !options[pane].closable || state[pane].isHidden)
4913                         return true;
4914
4915                 toggle(pane);
4916
4917                 evt.stopPropagation();
4918                 evt.returnValue = false; // CANCEL key
4919                 return false;
4920         };
4921
4922
4923 /*
4924  * ######################################
4925  *      UTILITY METHODS
4926  *      called externally or by initButtons
4927  * ######################################
4928  */
4929
4930         /**
4931          * Change/reset a pane overflow setting & zIndex to allow popups/drop-downs to work
4932          *
4933          * @param {Object=}   [el]      (optional) Can also be 'bound' to a click, mouseOver, or other event
4934          */
4935         function allowOverflow (el) {
4936                 if (!isInitialized()) return;
4937                 if (this && this.tagName) el = this; // BOUND to element
4938                 var $P;
4939                 if (isStr(el))
4940                         $P = $Ps[el];
4941                 else if ($(el).data("layoutRole"))
4942                         $P = $(el);
4943                 else
4944                         $(el).parents().each(function(){
4945                                 if ($(this).data("layoutRole")) {
4946                                         $P = $(this);
4947                                         return false; // BREAK
4948                                 }
4949                         });
4950                 if (!$P || !$P.length) return; // INVALID
4951
4952                 var
4953                         pane    = $P.data("layoutEdge")
4954                 ,       s               = state[pane]
4955                 ;
4956
4957                 // if pane is already raised, then reset it before doing it again!
4958                 // this would happen if allowOverflow is attached to BOTH the pane and an element 
4959                 if (s.cssSaved)
4960                         resetOverflow(pane); // reset previous CSS before continuing
4961
4962                 // if pane is raised by sliding or resizing, or its closed, then abort
4963                 if (s.isSliding || s.isResizing || s.isClosed) {
4964                         s.cssSaved = false;
4965                         return;
4966                 }
4967
4968                 var
4969                         newCSS  = { zIndex: (options.zIndexes.resizer_normal + 1) }
4970                 ,       curCSS  = {}
4971                 ,       of              = $P.css("overflow")
4972                 ,       ofX             = $P.css("overflowX")
4973                 ,       ofY             = $P.css("overflowY")
4974                 ;
4975                 // determine which, if any, overflow settings need to be changed
4976                 if (of != "visible") {
4977                         curCSS.overflow = of;
4978                         newCSS.overflow = "visible";
4979                 }
4980                 if (ofX && !ofX.match(/(visible|auto)/)) {
4981                         curCSS.overflowX = ofX;
4982                         newCSS.overflowX = "visible";
4983                 }
4984                 if (ofY && !ofY.match(/(visible|auto)/)) {
4985                         curCSS.overflowY = ofX;
4986                         newCSS.overflowY = "visible";
4987                 }
4988
4989                 // save the current overflow settings - even if blank!
4990                 s.cssSaved = curCSS;
4991
4992                 // apply new CSS to raise zIndex and, if necessary, make overflow 'visible'
4993                 $P.css( newCSS );
4994
4995                 // make sure the zIndex of all other panes is normal
4996                 $.each(_c.allPanes, function(i, p) {
4997                         if (p != pane) resetOverflow(p);
4998                 });
4999
5000         };
5001         /**
5002          * @param {Object=}   [el]      (optional) Can also be 'bound' to a click, mouseOver, or other event
5003          */
5004         function resetOverflow (el) {
5005                 if (!isInitialized()) return;
5006                 if (this && this.tagName) el = this; // BOUND to element
5007                 var $P;
5008                 if (isStr(el))
5009                         $P = $Ps[el];
5010                 else if ($(el).data("layoutRole"))
5011                         $P = $(el);
5012                 else
5013                         $(el).parents().each(function(){
5014                                 if ($(this).data("layoutRole")) {
5015                                         $P = $(this);
5016                                         return false; // BREAK
5017                                 }
5018                         });
5019                 if (!$P || !$P.length) return; // INVALID
5020
5021                 var
5022                         pane    = $P.data("layoutEdge")
5023                 ,       s               = state[pane]
5024                 ,       CSS             = s.cssSaved || {}
5025                 ;
5026                 // reset the zIndex
5027                 if (!s.isSliding && !s.isResizing)
5028                         $P.css("zIndex", options.zIndexes.pane_normal);
5029
5030                 // reset Overflow - if necessary
5031                 $P.css( CSS );
5032
5033                 // clear var
5034                 s.cssSaved = false;
5035         };
5036
5037 /*
5038  * #####################
5039  * CREATE/RETURN LAYOUT
5040  * #####################
5041  */
5042
5043         // validate that container exists
5044         var $N = $(this).eq(0); // FIRST matching Container element
5045         if (!$N.length) {
5046                 return _log( options.errors.containerMissing );
5047         };
5048
5049         // Users retrieve Instance of a layout with: $N.layout() OR $N.data("layout")
5050         // return the Instance-pointer if layout has already been initialized
5051         if ($N.data("layoutContainer") && $N.data("layout"))
5052                 return $N.data("layout"); // cached pointer
5053
5054         // init global vars
5055         var 
5056                 $Ps     = {}    // Panes x5             - set in initPanes()
5057         ,       $Cs     = {}    // Content x5   - set in initPanes()
5058         ,       $Rs     = {}    // Resizers x4  - set in initHandles()
5059         ,       $Ts     = {}    // Togglers x4  - set in initHandles()
5060         ,       $Ms     = $([]) // Masks - up to 2 masks per pane (IFRAME + DIV)
5061         //      aliases for code brevity
5062         ,       sC      = state.container // alias for easy access to 'container dimensions'
5063         ,       sID     = state.id // alias for unique layout ID/namespace - eg: "layout435"
5064         ;
5065
5066         // create Instance object to expose data & option Properties, and primary action Methods
5067         var Instance = {
5068         //      layout data
5069                 options:                        options                 // property - options hash
5070         ,       state:                          state                   // property - dimensions hash
5071         //      object pointers
5072         ,       container:                      $N                              // property - object pointers for layout container
5073         ,       panes:                          $Ps                             // property - object pointers for ALL Panes: panes.north, panes.center
5074         ,       contents:                       $Cs                             // property - object pointers for ALL Content: contents.north, contents.center
5075         ,       resizers:                       $Rs                             // property - object pointers for ALL Resizers, eg: resizers.north
5076         ,       togglers:                       $Ts                             // property - object pointers for ALL Togglers, eg: togglers.north
5077         //      border-pane open/close
5078         ,       hide:                           hide                    // method - ditto
5079         ,       show:                           show                    // method - ditto
5080         ,       toggle:                         toggle                  // method - pass a 'pane' ("north", "west", etc)
5081         ,       open:                           open                    // method - ditto
5082         ,       close:                          close                   // method - ditto
5083         ,       slideOpen:                      slideOpen               // method - ditto
5084         ,       slideClose:                     slideClose              // method - ditto
5085         ,       slideToggle:            slideToggle             // method - ditto
5086         //      pane actions
5087         ,       setSizeLimits:          setSizeLimits   // method - pass a 'pane' - update state min/max data
5088         ,       _sizePane:                      sizePane                // method -intended for user by plugins only!
5089         ,       sizePane:                       manualSizePane  // method - pass a 'pane' AND an 'outer-size' in pixels or percent, or 'auto'
5090         ,       sizeContent:            sizeContent             // method - pass a 'pane'
5091         ,       swapPanes:                      swapPanes               // method - pass TWO 'panes' - will swap them
5092         ,       showMasks:                      showMasks               // method - pass a 'pane' OR list of panes - default = all panes with mask option set
5093         ,       hideMasks:                      hideMasks               // method - ditto'
5094         //      pane element methods
5095         ,       initContent:            initContent             // method - ditto
5096         ,       addPane:                        addPane                 // method - pass a 'pane'
5097         ,       removePane:                     removePane              // method - pass a 'pane' to remove from layout, add 'true' to delete the pane-elem
5098         ,       createChildren:         createChildren  // method - pass a 'pane' and (optional) layout-options (OVERRIDES options[pane].children
5099         ,       refreshChildren:        refreshChildren // method - pass a 'pane' and a layout-instance
5100         //      special pane option setting
5101         ,       enableClosable:         enableClosable  // method - pass a 'pane'
5102         ,       disableClosable:        disableClosable // method - ditto
5103         ,       enableSlidable:         enableSlidable  // method - ditto
5104         ,       disableSlidable:        disableSlidable // method - ditto
5105         ,       enableResizable:        enableResizable // method - ditto
5106         ,       disableResizable:       disableResizable// method - ditto
5107         //      utility methods for panes
5108         ,       allowOverflow:          allowOverflow   // utility - pass calling element (this)
5109         ,       resetOverflow:          resetOverflow   // utility - ditto
5110         //      layout control
5111         ,       destroy:                        destroy                 // method - no parameters
5112         ,       initPanes:                      isInitialized   // method - no parameters
5113         ,       resizeAll:                      resizeAll               // method - no parameters
5114         //      callback triggering
5115         ,       runCallbacks:           _runCallbacks   // method - pass evtName & pane (if a pane-event), eg: trigger("onopen", "west")
5116         //      alias collections of options, state and children - created in addPane and extended elsewhere
5117         ,       hasParentLayout:        false                   // set by initContainer()
5118         ,       children:                       children                // pointers to child-layouts, eg: Instance.children.west.layoutName
5119         ,       north:                          false                   // alias group: { name: pane, pane: $Ps[pane], options: options[pane], state: state[pane], children: children[pane] }
5120         ,       south:                          false                   // ditto
5121         ,       west:                           false                   // ditto
5122         ,       east:                           false                   // ditto
5123         ,       center:                         false                   // ditto
5124         };
5125
5126         // create the border layout NOW
5127         if (_create() === 'cancel') // onload_start callback returned false to CANCEL layout creation
5128                 return null;
5129         else // true OR false -- if layout-elements did NOT init (hidden or do not exist), can auto-init later
5130                 return Instance; // return the Instance object
5131
5132 }
5133
5134
5135 })( jQuery );
5136
5137
5138
5139
5140 /**
5141  * jquery.layout.state 1.2
5142  * $Date: 2015/03/13 22:37:04 $
5143  *
5144  * Copyright (c) 2014 
5145  *   Kevin Dalman (http://allpro.net)
5146  *
5147  * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
5148  * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
5149  *
5150  * @requires: UI Layout 1.4.0 or higher
5151  * @requires: $.ui.cookie (above)
5152  *
5153  * @see: http://groups.google.com/group/jquery-ui-layout
5154  */
5155 ;(function ($) {
5156
5157 if (!$.layout) return;
5158
5159
5160 /**
5161  *      UI COOKIE UTILITY
5162  *
5163  *      A $.cookie OR $.ui.cookie namespace *should be standard*, but until then...
5164  *      This creates $.ui.cookie so Layout does not need the cookie.jquery.js plugin
5165  *      NOTE: This utility is REQUIRED by the layout.state plugin
5166  *
5167  *      Cookie methods in Layout are created as part of State Management 
5168  */
5169 if (!$.ui) $.ui = {};
5170 $.ui.cookie = {
5171
5172         // cookieEnabled is not in DOM specs, but DOES works in all browsers,including IE6
5173         acceptsCookies: !!navigator.cookieEnabled
5174
5175 ,       read: function (name) {
5176                 var
5177                         c       = document.cookie
5178                 ,       cs      = c ? c.split(';') : []
5179                 ,       pair, data, i
5180                 ;
5181                 for (i=0; pair=cs[i]; i++) {
5182                         data = $.trim(pair).split('='); // name=value => [ name, value ]
5183                         if (data[0] == name) // found the layout cookie
5184                                 return decodeURIComponent(data[1]);
5185                 }
5186                 return null;
5187         }
5188
5189 ,       write: function (name, val, cookieOpts) {
5190                 var     params  = ""
5191                 ,       date    = ""
5192                 ,       clear   = false
5193                 ,       o               = cookieOpts || {}
5194                 ,       x               = o.expires  || null
5195                 ,       t               = $.type(x)
5196                 ;
5197                 if (t === "date")
5198                         date = x;
5199                 else if (t === "string" && x > 0) {
5200                         x = parseInt(x,10);
5201                         t = "number";
5202                 }
5203                 if (t === "number") {
5204                         date = new Date();
5205                         if (x > 0)
5206                                 date.setDate(date.getDate() + x);
5207                         else {
5208                                 date.setFullYear(1970);
5209                                 clear = true;
5210                         }
5211                 }
5212                 if (date)               params += ";expires="+ date.toUTCString();
5213                 if (o.path)             params += ";path="+ o.path;
5214                 if (o.domain)   params += ";domain="+ o.domain;
5215                 if (o.secure)   params += ";secure";
5216                 document.cookie = name +"="+ (clear ? "" : encodeURIComponent( val )) + params; // write or clear cookie
5217         }
5218
5219 ,       clear: function (name) {
5220                 $.ui.cookie.write(name, "", {expires: -1});
5221         }
5222
5223 };
5224 // if cookie.jquery.js is not loaded, create an alias to replicate it
5225 // this may be useful to other plugins or code dependent on that plugin
5226 if (!$.cookie) $.cookie = function (k, v, o) {
5227         var C = $.ui.cookie;
5228         if (v === null)
5229                 C.clear(k);
5230         else if (v === undefined)
5231                 return C.read(k);
5232         else
5233                 C.write(k, v, o);
5234 };
5235
5236
5237
5238 /**
5239  *      State-management options stored in options.stateManagement, which includes a .cookie hash
5240  *      Default options saves ALL KEYS for ALL PANES, ie: pane.size, pane.isClosed, pane.isHidden
5241  *
5242  *      // STATE/COOKIE OPTIONS
5243  *      @example $(el).layout({
5244                                 stateManagement: {
5245                                         enabled:        true
5246                                 ,       stateKeys:      "east.size,west.size,east.isClosed,west.isClosed"
5247                                 ,       cookie:         { name: "appLayout", path: "/" }
5248                                 }
5249                         })
5250  *      @example $(el).layout({ stateManagement__enabled: true }) // enable auto-state-management using cookies
5251  *      @example $(el).layout({ stateManagement__cookie: { name: "appLayout", path: "/" } })
5252  *      @example $(el).layout({ stateManagement__cookie__name: "appLayout", stateManagement__cookie__path: "/" })
5253  *
5254  *      // STATE/COOKIE METHODS
5255  *      @example myLayout.saveCookie( "west.isClosed,north.size,south.isHidden", {expires: 7} );
5256  *      @example myLayout.loadCookie();
5257  *      @example myLayout.deleteCookie();
5258  *      @example var JSON = myLayout.readState();       // CURRENT Layout State
5259  *      @example var JSON = myLayout.readCookie();      // SAVED Layout State (from cookie)
5260  *      @example var JSON = myLayout.state.stateData;   // LAST LOADED Layout State (cookie saved in layout.state hash)
5261  *
5262  *      CUSTOM STATE-MANAGEMENT (eg, saved in a database)
5263  *      @example var JSON = myLayout.readState( "west.isClosed,north.size,south.isHidden" );
5264  *      @example myLayout.loadState( JSON );
5265  */
5266
5267 // tell Layout that the state plugin is available
5268 $.layout.plugins.stateManagement = true;
5269
5270 //      Add State-Management options to layout.defaults
5271 $.layout.defaults.stateManagement = {
5272         enabled:                false   // true = enable state-management, even if not using cookies
5273 ,       autoSave:               true    // Save a state-cookie when page exits?
5274 ,       autoLoad:               true    // Load the state-cookie when Layout inits?
5275 ,       animateLoad:    true    // animate panes when loading state into an active layout
5276 ,       includeChildren: true   // recurse into child layouts to include their state as well
5277         // List state-data to save - must be pane-specific
5278 ,       stateKeys:      "north.size,south.size,east.size,west.size,"+
5279                                 "north.isClosed,south.isClosed,east.isClosed,west.isClosed,"+
5280                                 "north.isHidden,south.isHidden,east.isHidden,west.isHidden"
5281 ,       cookie: {
5282                 name:   ""      // If not specified, will use Layout.name, else just "Layout"
5283         ,       domain: ""      // blank = current domain
5284         ,       path:   ""      // blank = current page, "/" = entire website
5285         ,       expires: ""     // 'days' to keep cookie - leave blank for 'session cookie'
5286         ,       secure: false
5287         }
5288 };
5289
5290 // Set stateManagement as a 'layout-option', NOT a 'pane-option'
5291 $.layout.optionsMap.layout.push("stateManagement");
5292 // Update config so layout does not move options into the pane-default branch (panes)
5293 $.layout.config.optionRootKeys.push("stateManagement");
5294
5295 /*
5296  *      State Management methods
5297  */
5298 $.layout.state = {
5299
5300         /**
5301          * Get the current layout state and save it to a cookie
5302          *
5303          * myLayout.saveCookie( keys, cookieOpts )
5304          *
5305          * @param {Object}                      inst
5306          * @param {(string|Array)=}     keys
5307          * @param {Object=}                     cookieOpts
5308          */
5309         saveCookie: function (inst, keys, cookieOpts) {
5310                 var o   = inst.options
5311                 ,       sm      = o.stateManagement
5312                 ,       oC      = $.extend(true, {}, sm.cookie, cookieOpts || null)
5313                 ,       data = inst.state.stateData = inst.readState( keys || sm.stateKeys ) // read current panes-state
5314                 ;
5315                 $.ui.cookie.write( oC.name || o.name || "Layout", $.layout.state.encodeJSON(data), oC );
5316                 return $.extend(true, {}, data); // return COPY of state.stateData data
5317         }
5318
5319         /**
5320          * Remove the state cookie
5321          *
5322          * @param {Object}      inst
5323          */
5324 ,       deleteCookie: function (inst) {
5325                 var o = inst.options;
5326                 $.ui.cookie.clear( o.stateManagement.cookie.name || o.name || "Layout" );
5327         }
5328
5329         /**
5330          * Read & return data from the cookie - as JSON
5331          *
5332          * @param {Object}      inst
5333          */
5334 ,       readCookie: function (inst) {
5335                 var o = inst.options;
5336                 var c = $.ui.cookie.read( o.stateManagement.cookie.name || o.name || "Layout" );
5337                 // convert cookie string back to a hash and return it
5338                 return c ? $.layout.state.decodeJSON(c) : {};
5339         }
5340
5341         /**
5342          * Get data from the cookie and USE IT to loadState
5343          *
5344          * @param {Object}      inst
5345          */
5346 ,       loadCookie: function (inst) {
5347                 var c = $.layout.state.readCookie(inst); // READ the cookie
5348                 if (c && !$.isEmptyObject( c )) {
5349                         inst.state.stateData = $.extend(true, {}, c); // SET state.stateData
5350                         inst.loadState(c); // LOAD the retrieved state
5351                 }
5352                 return c;
5353         }
5354
5355         /**
5356          * Update layout options from the cookie, if one exists
5357          *
5358          * @param {Object}              inst
5359          * @param {Object=}             stateData
5360          * @param {boolean=}    animate
5361          */
5362 ,       loadState: function (inst, data, opts) {
5363                 if (!$.isPlainObject( data ) || $.isEmptyObject( data )) return;
5364
5365                 // normalize data & cache in the state object
5366                 data = inst.state.stateData = $.layout.transformData( data ); // panes = default subkey
5367
5368                 // add missing/default state-restore options
5369                 var smo = inst.options.stateManagement;
5370                 opts = $.extend({
5371                         animateLoad:            false //smo.animateLoad
5372                 ,       includeChildren:        smo.includeChildren
5373                 }, opts );
5374
5375                 if (!inst.state.initialized) {
5376                         /*
5377                          *      layout NOT initialized, so just update its options
5378                          */
5379                         // MUST remove pane.children keys before applying to options
5380                         // use a copy so we don't remove keys from original data
5381                         var o = $.extend(true, {}, data);
5382                         //delete o.center; // center has no state-data - only children
5383                         $.each($.layout.config.allPanes, function (idx, pane) {
5384                                 if (o[pane]) delete o[pane].children;              
5385                          });
5386                         // update CURRENT layout-options with saved state data
5387                         $.extend(true, inst.options, o);
5388                 }
5389                 else {
5390                         /*
5391                          *      layout already initialized, so modify layout's configuration
5392                          */
5393                         var noAnimate = !opts.animateLoad
5394                         ,       o, c, h, state, open
5395                         ;
5396                         $.each($.layout.config.borderPanes, function (idx, pane) {
5397                                 o = data[ pane ];
5398                                 if (!$.isPlainObject( o )) return; // no key, skip pane
5399
5400                                 s       = o.size;
5401                                 c       = o.initClosed;
5402                                 h       = o.initHidden;
5403                                 ar      = o.autoResize
5404                                 state   = inst.state[pane];
5405                                 open    = state.isVisible;
5406
5407                                 // reset autoResize
5408                                 if (ar)
5409                                         state.autoResize = ar;
5410                                 // resize BEFORE opening
5411                                 if (!open)
5412                                         inst._sizePane(pane, s, false, false, false); // false=skipCallback/noAnimation/forceResize
5413                                 // open/close as necessary - DO NOT CHANGE THIS ORDER!
5414                                 if (h === true)                 inst.hide(pane, noAnimate);
5415                                 else if (c === true)    inst.close(pane, false, noAnimate);
5416                                 else if (c === false)   inst.open (pane, false, noAnimate);
5417                                 else if (h === false)   inst.show (pane, false, noAnimate);
5418                                 // resize AFTER any other actions
5419                                 if (open)
5420                                         inst._sizePane(pane, s, false, false, noAnimate); // animate resize if option passed
5421                         });
5422
5423                         /*
5424                          *      RECURSE INTO CHILD-LAYOUTS
5425                          */
5426                         if (opts.includeChildren) {
5427                                 var paneStateChildren, childState;
5428                                 $.each(inst.children, function (pane, paneChildren) {
5429                                         paneStateChildren = data[pane] ? data[pane].children : 0;
5430                                         if (paneStateChildren && paneChildren) {
5431                                                 $.each(paneChildren, function (stateKey, child) {
5432                                                         childState = paneStateChildren[stateKey];
5433                                                         if (child && childState)
5434                                                                 child.loadState( childState );
5435                                                 });
5436                                         }
5437                                 });
5438                         }
5439                 }
5440         }
5441
5442         /**
5443          * Get the *current layout state* and return it as a hash
5444          *
5445          * @param {Object=}             inst    // Layout instance to get state for
5446          * @param {object=}             [opts]  // State-Managements override options
5447          */
5448 ,       readState: function (inst, opts) {
5449                 // backward compatility
5450                 if ($.type(opts) === 'string') opts = { keys: opts };
5451                 if (!opts) opts = {};
5452                 var     sm              = inst.options.stateManagement
5453                 ,       ic              = opts.includeChildren
5454                 ,       recurse = ic !== undefined ? ic : sm.includeChildren
5455                 ,       keys    = opts.stateKeys || sm.stateKeys
5456                 ,       alt             = { isClosed: 'initClosed', isHidden: 'initHidden' }
5457                 ,       state   = inst.state
5458                 ,       panes   = $.layout.config.allPanes
5459                 ,       data    = {}
5460                 ,       pair, pane, key, val
5461                 ,       ps, pC, child, array, count, branch
5462                 ;
5463                 if ($.isArray(keys)) keys = keys.join(",");
5464                 // convert keys to an array and change delimiters from '__' to '.'
5465                 keys = keys.replace(/__/g, ".").split(',');
5466                 // loop keys and create a data hash
5467                 for (var i=0, n=keys.length; i < n; i++) {
5468                         pair = keys[i].split(".");
5469                         pane = pair[0];
5470                         key  = pair[1];
5471                         if ($.inArray(pane, panes) < 0) continue; // bad pane!
5472                         val = state[ pane ][ key ];
5473                         if (val == undefined) continue;
5474                         if (key=="isClosed" && state[pane]["isSliding"])
5475                                 val = true; // if sliding, then *really* isClosed
5476                         ( data[pane] || (data[pane]={}) )[ alt[key] ? alt[key] : key ] = val;
5477                 }
5478
5479                 // recurse into the child-layouts for each pane
5480                 if (recurse) {
5481                         $.each(panes, function (idx, pane) {
5482                                 pC = inst.children[pane];
5483                                 ps = state.stateData[pane];
5484                                 if ($.isPlainObject( pC ) && !$.isEmptyObject( pC )) {
5485                                         // ensure a key exists for this 'pane', eg: branch = data.center
5486                                         branch = data[pane] || (data[pane] = {});
5487                                         if (!branch.children) branch.children = {};
5488                                         $.each( pC, function (key, child) {
5489                                                 // ONLY read state from an initialize layout
5490                                                 if ( child.state.initialized )
5491                                                         branch.children[ key ] = $.layout.state.readState( child );
5492                                                 // if we have PREVIOUS (onLoad) state for this child-layout, KEEP IT!
5493                                                 else if ( ps && ps.children && ps.children[ key ] ) {
5494                                                         branch.children[ key ] = $.extend(true, {}, ps.children[ key ] );
5495                                                 }
5496                                         });
5497                                 }
5498                         });
5499                 }
5500
5501                 return data;
5502         }
5503
5504         /**
5505          *      Stringify a JSON hash so can save in a cookie or db-field
5506          */
5507 ,       encodeJSON: function (json) {
5508                 var local = window.JSON || {};
5509                 return (local.stringify || stringify)(json);
5510
5511                 function stringify (h) {
5512                         var D=[], i=0, k, v, t // k = key, v = value
5513                         ,       a = $.isArray(h)
5514                         ;
5515                         for (k in h) {
5516                                 v = h[k];
5517                                 t = typeof v;
5518                                 if (t == 'string')              // STRING - add quotes
5519                                         v = '"'+ v +'"';
5520                                 else if (t == 'object') // SUB-KEY - recurse into it
5521                                         v = parse(v);
5522                                 D[i++] = (!a ? '"'+ k +'":' : '') + v;
5523                         }
5524                         return (a ? '[' : '{') + D.join(',') + (a ? ']' : '}');
5525                 };
5526         }
5527
5528         /**
5529          *      Convert stringified JSON back to a hash object
5530          *      @see            $.parseJSON(), adding in jQuery 1.4.1
5531          */
5532 ,       decodeJSON: function (str) {
5533                 try { return $.parseJSON ? $.parseJSON(str) : window["eval"]("("+ str +")") || {}; }
5534                 catch (e) { return {}; }
5535         }
5536
5537
5538 ,       _create: function (inst) {
5539                 var s   = $.layout.state
5540                 ,       o       = inst.options
5541                 ,       sm      = o.stateManagement
5542                 ;
5543                 //      ADD State-Management plugin methods to inst
5544                  $.extend( inst, {
5545                 //      readCookie - update options from cookie - returns hash of cookie data
5546                         readCookie:             function () { return s.readCookie(inst); }
5547                 //      deleteCookie
5548                 ,       deleteCookie:   function () { s.deleteCookie(inst); }
5549                 //      saveCookie - optionally pass keys-list and cookie-options (hash)
5550                 ,       saveCookie:             function (keys, cookieOpts) { return s.saveCookie(inst, keys, cookieOpts); }
5551                 //      loadCookie - readCookie and use to loadState() - returns hash of cookie data
5552                 ,       loadCookie:             function () { return s.loadCookie(inst); }
5553                 //      loadState - pass a hash of state to use to update options
5554                 ,       loadState:              function (stateData, opts) { s.loadState(inst, stateData, opts); }
5555                 //      readState - returns hash of current layout-state
5556                 ,       readState:              function (keys) { return s.readState(inst, keys); }
5557                 //      add JSON utility methods too...
5558                 ,       encodeJSON:             s.encodeJSON
5559                 ,       decodeJSON:             s.decodeJSON
5560                 });
5561
5562                 // init state.stateData key, even if plugin is initially disabled
5563                 inst.state.stateData = {};
5564
5565                 // autoLoad MUST BE one of: data-array, data-hash, callback-function, or TRUE
5566                 if ( !sm.autoLoad ) return;
5567
5568                 //      When state-data exists in the autoLoad key USE IT,
5569                 //      even if stateManagement.enabled == false
5570                 if ($.isPlainObject( sm.autoLoad )) {
5571                         if (!$.isEmptyObject( sm.autoLoad )) {
5572                                 inst.loadState( sm.autoLoad );
5573                         }
5574                 }
5575                 else if ( sm.enabled ) {
5576                         // update the options from cookie or callback
5577                         // if options is a function, call it to get stateData
5578                         if ($.isFunction( sm.autoLoad )) {
5579                                 var d = {};
5580                                 try {
5581                                         d = sm.autoLoad( inst, inst.state, inst.options, inst.options.name || '' ); // try to get data from fn
5582                                 } catch (e) {}
5583                                 if (d && $.isPlainObject( d ) && !$.isEmptyObject( d ))
5584                                         inst.loadState(d);
5585                         }
5586                         else // any other truthy value will trigger loadCookie
5587                                 inst.loadCookie();
5588                 }
5589         }
5590
5591 ,       _unload: function (inst) {
5592                 var sm = inst.options.stateManagement;
5593                 if (sm.enabled && sm.autoSave) {
5594                         // if options is a function, call it to save the stateData
5595                         if ($.isFunction( sm.autoSave )) {
5596                                 try {
5597                                         sm.autoSave( inst, inst.state, inst.options, inst.options.name || '' ); // try to get data from fn
5598                                 } catch (e) {}
5599                         }
5600                         else // any truthy value will trigger saveCookie
5601                                 inst.saveCookie();
5602                 }
5603         }
5604
5605 };
5606
5607 // add state initialization method to Layout's onCreate array of functions
5608 $.layout.onCreate.push( $.layout.state._create );
5609 $.layout.onUnload.push( $.layout.state._unload );
5610
5611 })( jQuery );
5612
5613
5614
5615 /**
5616  * @preserve jquery.layout.buttons 1.0
5617  * $Date: 2015/03/13 22:37:04 $
5618  *
5619  * Copyright (c) 2011 
5620  *   Kevin Dalman (http://allpro.net)
5621  *
5622  * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
5623  * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
5624  *
5625  * @dependancies: UI Layout 1.3.0.rc30.1 or higher
5626  *
5627  * @support: http://groups.google.com/group/jquery-ui-layout
5628  *
5629  * Docs: [ to come ]
5630  * Tips: [ to come ]
5631  */
5632 ;(function ($) {
5633
5634 if (!$.layout) return;
5635
5636
5637 // tell Layout that the state plugin is available
5638 $.layout.plugins.buttons = true;
5639
5640 //      Add State-Management options to layout.defaults
5641 $.layout.defaults.autoBindCustomButtons = false;
5642 // Set stateManagement as a layout-option, NOT a pane-option
5643 $.layout.optionsMap.layout.push("autoBindCustomButtons");
5644
5645 var lang = $.layout.language;
5646
5647 /*
5648  *      Button methods
5649  */
5650 $.layout.buttons = {
5651         // set data used by multiple methods below
5652         config: {
5653                 borderPanes:    "north,south,west,east"
5654         }
5655
5656         /**
5657         * Searches for .ui-layout-button-xxx elements and auto-binds them as layout-buttons
5658         *
5659         * @see  _create()
5660         */
5661 ,       init: function (inst) {
5662                 var pre         = "ui-layout-button-"
5663                 ,       layout  = inst.options.name || ""
5664                 ,       name;
5665                 $.each("toggle,open,close,pin,toggle-slide,open-slide".split(","), function (i, action) {
5666                         $.each($.layout.buttons.config.borderPanes.split(","), function (ii, pane) {
5667                                 $("."+pre+action+"-"+pane).each(function(){
5668                                         // if button was previously 'bound', data.layoutName was set, but is blank if layout has no 'name'
5669                                         name = $(this).data("layoutName") || $(this).attr("layoutName");
5670                                         if (name == undefined || name === layout)
5671                                                 inst.bindButton(this, action, pane);
5672                                 });
5673                         });
5674                 });
5675         }
5676
5677         /**
5678         * Helper function to validate params received by addButton utilities
5679         *
5680         * Two classes are added to the element, based on the buttonClass...
5681         * The type of button is appended to create the 2nd className:
5682         *  - ui-layout-button-pin
5683         *  - ui-layout-pane-button-toggle
5684         *  - ui-layout-pane-button-open
5685         *  - ui-layout-pane-button-close
5686         *
5687         * @param  {(string|!Object)}    selector        jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
5688         * @param  {string}                      pane            Name of the pane the button is for: 'north', 'south', etc.
5689         * @return {Array.<Object>}              If both params valid, the element matching 'selector' in a jQuery wrapper - otherwise returns null
5690         */
5691 ,       get: function (inst, selector, pane, action) {
5692                 var $E  = $(selector)
5693                 ,       o       = inst.options
5694                 ,       err     = o.showErrorMessages
5695                 ;
5696                 if (!$E.length) { // element not found
5697                         if (err) alert(lang.errButton + lang.selector +": "+ selector);
5698                 }
5699                 else if ($.layout.buttons.config.borderPanes.indexOf(pane) === -1) { // invalid 'pane' sepecified
5700                         if (err) alert(lang.errButton + lang.pane +": "+ pane);
5701                         $E = $("");  // NO BUTTON
5702                 }
5703                 else { // VALID
5704                         var btn = o[pane].buttonClass +"-"+ action;
5705                         $E      .addClass( btn +" "+ btn +"-"+ pane )
5706                                 .data("layoutName", o.name); // add layout identifier - even if blank!
5707                 }
5708                 return $E;
5709         }
5710
5711
5712         /**
5713         * NEW syntax for binding layout-buttons - will eventually replace addToggle, addOpen, etc.
5714         *
5715         * @param {(string|!Object)}     sel             jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
5716         * @param {string}                       action
5717         * @param {string}                       pane
5718         */
5719 ,       bind: function (inst, sel, action, pane) {
5720                 var _ = $.layout.buttons;
5721                 switch (action.toLowerCase()) {
5722                         case "toggle":                  _.addToggle     (inst, sel, pane); break;       
5723                         case "open":                    _.addOpen       (inst, sel, pane); break;
5724                         case "close":                   _.addClose      (inst, sel, pane); break;
5725                         case "pin":                             _.addPin        (inst, sel, pane); break;
5726                         case "toggle-slide":    _.addToggle     (inst, sel, pane, true); break; 
5727                         case "open-slide":              _.addOpen       (inst, sel, pane, true); break;
5728                 }
5729                 return inst;
5730         }
5731
5732         /**
5733         * Add a custom Toggler button for a pane
5734         *
5735         * @param {(string|!Object)}     selector        jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
5736         * @param {string}                       pane            Name of the pane the button is for: 'north', 'south', etc.
5737         * @param {boolean=}                     slide           true = slide-open, false = pin-open
5738         */
5739 ,       addToggle: function (inst, selector, pane, slide) {
5740                 $.layout.buttons.get(inst, selector, pane, "toggle")
5741                         .click(function(evt){
5742                                 inst.toggle(pane, !!slide);
5743                                 evt.stopPropagation();
5744                         });
5745                 return inst;
5746         }
5747
5748         /**
5749         * Add a custom Open button for a pane
5750         *
5751         * @param {(string|!Object)}     selector        jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
5752         * @param {string}                       pane            Name of the pane the button is for: 'north', 'south', etc.
5753         * @param {boolean=}                     slide           true = slide-open, false = pin-open
5754         */
5755 ,       addOpen: function (inst, selector, pane, slide) {
5756                 $.layout.buttons.get(inst, selector, pane, "open")
5757                         .attr("title", lang.Open)
5758                         .click(function (evt) {
5759                                 inst.open(pane, !!slide);
5760                                 evt.stopPropagation();
5761                         });
5762                 return inst;
5763         }
5764
5765         /**
5766         * Add a custom Close button for a pane
5767         *
5768         * @param {(string|!Object)}     selector        jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
5769         * @param {string}               pane            Name of the pane the button is for: 'north', 'south', etc.
5770         */
5771 ,       addClose: function (inst, selector, pane) {
5772                 $.layout.buttons.get(inst, selector, pane, "close")
5773                         .attr("title", lang.Close)
5774                         .click(function (evt) {
5775                                 inst.close(pane);
5776                                 evt.stopPropagation();
5777                         });
5778                 return inst;
5779         }
5780
5781         /**
5782         * Add a custom Pin button for a pane
5783         *
5784         * Four classes are added to the element, based on the paneClass for the associated pane...
5785         * Assuming the default paneClass and the pin is 'up', these classes are added for a west-pane pin:
5786         *  - ui-layout-pane-pin
5787         *  - ui-layout-pane-west-pin
5788         *  - ui-layout-pane-pin-up
5789         *  - ui-layout-pane-west-pin-up
5790         *
5791         * @param {(string|!Object)}     selector        jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button"
5792         * @param {string}               pane            Name of the pane the pin is for: 'north', 'south', etc.
5793         */
5794 ,       addPin: function (inst, selector, pane) {
5795                 var $E = $.layout.buttons.get(inst, selector, pane, "pin");
5796                 if ($E.length) {
5797                         var s = inst.state[pane];
5798                         $E.click(function (evt) {
5799                                 $.layout.buttons.setPinState(inst, $(this), pane, (s.isSliding || s.isClosed));
5800                                 if (s.isSliding || s.isClosed) inst.open( pane ); // change from sliding to open
5801                                 else inst.close( pane ); // slide-closed
5802                                 evt.stopPropagation();
5803                         });
5804                         // add up/down pin attributes and classes
5805                         $.layout.buttons.setPinState(inst, $E, pane, (!s.isClosed && !s.isSliding));
5806                         // add this pin to the pane data so we can 'sync it' automatically
5807                         // PANE.pins key is an array so we can store multiple pins for each pane
5808                         s.pins.push( selector ); // just save the selector string
5809                 }
5810                 return inst;
5811         }
5812
5813         /**
5814         * Change the class of the pin button to make it look 'up' or 'down'
5815         *
5816         * @see  addPin(), syncPins()
5817         * @param {Array.<Object>}       $Pin    The pin-span element in a jQuery wrapper
5818         * @param {string}       pane    These are the params returned to callbacks by layout()
5819         * @param {boolean}      doPin   true = set the pin 'down', false = set it 'up'
5820         */
5821 ,       setPinState: function (inst, $Pin, pane, doPin) {
5822                 var updown = $Pin.attr("pin");
5823                 if (updown && doPin === (updown=="down")) return; // already in correct state
5824                 var
5825                         pin             = inst.options[pane].buttonClass +"-pin"
5826                 ,       side    = pin +"-"+ pane
5827                 ,       UP              = pin +"-up "+  side +"-up"
5828                 ,       DN              = pin +"-down "+side +"-down"
5829                 ;
5830                 $Pin
5831                         .attr("pin", doPin ? "down" : "up") // logic
5832                         .attr("title", doPin ? lang.Unpin : lang.Pin)
5833                         .removeClass( doPin ? UP : DN ) 
5834                         .addClass( doPin ? DN : UP ) 
5835                 ;
5836         }
5837
5838         /**
5839         * INTERNAL function to sync 'pin buttons' when pane is opened or closed
5840         * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes
5841         *
5842         * @see  open(), close()
5843         * @param {string}       pane   These are the params returned to callbacks by layout()
5844         * @param {boolean}      doPin  True means set the pin 'down', False means 'up'
5845         */
5846 ,       syncPinBtns: function (inst, pane, doPin) {
5847                 // REAL METHOD IS _INSIDE_ LAYOUT - THIS IS HERE JUST FOR REFERENCE
5848                 $.each(state[pane].pins, function (i, selector) {
5849                         $.layout.buttons.setPinState(inst, $(selector), pane, doPin);
5850                 });
5851         }
5852
5853
5854 ,       _load: function (inst) {
5855                 //      ADD Button methods to Layout Instance
5856                 $.extend( inst, {
5857                         bindButton:             function (selector, action, pane) { return $.layout.buttons.bind(inst, selector, action, pane); }
5858                 //      DEPRECATED METHODS...
5859                 ,       addToggleBtn:   function (selector, pane, slide) { return $.layout.buttons.addToggle(inst, selector, pane, slide); }
5860                 ,       addOpenBtn:             function (selector, pane, slide) { return $.layout.buttons.addOpen(inst, selector, pane, slide); }
5861                 ,       addCloseBtn:    function (selector, pane) { return $.layout.buttons.addClose(inst, selector, pane); }
5862                 ,       addPinBtn:              function (selector, pane) { return $.layout.buttons.addPin(inst, selector, pane); }
5863                 });
5864
5865                 // init state array to hold pin-buttons
5866                 for (var i=0; i<4; i++) {
5867                         var pane = $.layout.buttons.config.borderPanes[i];
5868                         inst.state[pane].pins = [];
5869                 }
5870
5871                 // auto-init buttons onLoad if option is enabled
5872                 if ( inst.options.autoBindCustomButtons )
5873                         $.layout.buttons.init(inst);
5874         }
5875
5876 ,       _unload: function (inst) {
5877                 // TODO: unbind all buttons???
5878         }
5879
5880 };
5881
5882 // add initialization method to Layout's onLoad array of functions
5883 $.layout.onLoad.push(  $.layout.buttons._load );
5884 //$.layout.onUnload.push( $.layout.buttons._unload );
5885
5886 })( jQuery );
5887
5888
5889
5890
5891 /**
5892  * jquery.layout.browserZoom 1.0
5893  * $Date: 2015/03/13 22:37:04 $
5894  *
5895  * Copyright (c) 2012 
5896  *   Kevin Dalman (http://allpro.net)
5897  *
5898  * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
5899  * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
5900  *
5901  * @requires: UI Layout 1.3.0.rc30.1 or higher
5902  *
5903  * @see: http://groups.google.com/group/jquery-ui-layout
5904  *
5905  * TODO: Extend logic to handle other problematic zooming in browsers
5906  * TODO: Add hotkey/mousewheel bindings to _instantly_ respond to these zoom event
5907  */
5908 (function ($) {
5909
5910 // tell Layout that the plugin is available
5911 $.layout.plugins.browserZoom = true;
5912
5913 $.layout.defaults.browserZoomCheckInterval = 1000;
5914 $.layout.optionsMap.layout.push("browserZoomCheckInterval");
5915
5916 /*
5917  *      browserZoom methods
5918  */
5919 $.layout.browserZoom = {
5920
5921         _init: function (inst) {
5922                 // abort if browser does not need this check
5923                 if ($.layout.browserZoom.ratio() !== false)
5924                         $.layout.browserZoom._setTimer(inst);
5925         }
5926
5927 ,       _setTimer: function (inst) {
5928                 // abort if layout destroyed or browser does not need this check
5929                 if (inst.destroyed) return;
5930                 var o   = inst.options
5931                 ,       s       = inst.state
5932                 //      don't need check if inst has parentLayout, but check occassionally in case parent destroyed!
5933                 //      MINIMUM 100ms interval, for performance
5934                 ,       ms      = inst.hasParentLayout ?  5000 : Math.max( o.browserZoomCheckInterval, 100 )
5935                 ;
5936                 // set the timer
5937                 setTimeout(function(){
5938                         if (inst.destroyed || !o.resizeWithWindow) return;
5939                         var d = $.layout.browserZoom.ratio();
5940                         if (d !== s.browserZoom) {
5941                                 s.browserZoom = d;
5942                                 inst.resizeAll();
5943                         }
5944                         // set a NEW timeout
5945                         $.layout.browserZoom._setTimer(inst);
5946                 }
5947                 ,       ms );
5948         }
5949
5950 ,       ratio: function () {
5951                 var w   = window
5952                 ,       s       = screen
5953                 ,       d       = document
5954                 ,       dE      = d.documentElement || d.body
5955                 ,       b       = $.layout.browser
5956                 ,       v       = b.version
5957                 ,       r, sW, cW
5958                 ;
5959                 // we can ignore all browsers that fire window.resize event onZoom
5960                 if (!b.msie || v > 8)
5961                         return false; // don't need to track zoom
5962                 if (s.deviceXDPI && s.systemXDPI) // syntax compiler hack
5963                         return calc(s.deviceXDPI, s.systemXDPI);
5964                 // everything below is just for future reference!
5965                 if (b.webkit && (r = d.body.getBoundingClientRect))
5966                         return calc((r.left - r.right), d.body.offsetWidth);
5967                 if (b.webkit && (sW = w.outerWidth))
5968                         return calc(sW, w.innerWidth);
5969                 if ((sW = s.width) && (cW = dE.clientWidth))
5970                         return calc(sW, cW);
5971                 return false; // no match, so cannot - or don't need to - track zoom
5972
5973                 function calc (x,y) { return (parseInt(x,10) / parseInt(y,10) * 100).toFixed(); }
5974         }
5975
5976 };
5977 // add initialization method to Layout's onLoad array of functions
5978 $.layout.onReady.push( $.layout.browserZoom._init );
5979
5980
5981 })( jQuery );
5982
5983
5984
5985
5986 /**
5987  *      UI Layout Plugin: Slide-Offscreen Animation
5988  *
5989  *      Prevent panes from being 'hidden' so that an iframes/objects 
5990  *      does not reload/refresh when pane 'opens' again.
5991  *      This plug-in adds a new animation called "slideOffscreen".
5992  *      It is identical to the normal "slide" effect, but avoids hiding the element
5993  *
5994  *      Requires Layout 1.3.0.RC30.1 or later for Close offscreen
5995  *      Requires Layout 1.3.0.RC30.5 or later for Hide, initClosed & initHidden offscreen
5996  *
5997  *      Version:        1.1 - 2012-11-18
5998  *      Author:         Kevin Dalman (kevin@jquery-dev.com)
5999  *      @preserve       jquery.layout.slideOffscreen-1.1.js
6000  */
6001 ;(function ($) {
6002
6003 // Add a new "slideOffscreen" effect
6004 if ($.effects) {
6005
6006         // add an option so initClosed and initHidden will work
6007         $.layout.defaults.panes.useOffscreenClose = false; // user must enable when needed
6008         /* set the new animation as the default for all panes
6009         $.layout.defaults.panes.fxName = "slideOffscreen";
6010         */
6011
6012         if ($.layout.plugins)
6013                 $.layout.plugins.effects.slideOffscreen = true;
6014
6015         // dupe 'slide' effect defaults as new effect defaults
6016         $.layout.effects.slideOffscreen = $.extend(true, {}, $.layout.effects.slide);
6017
6018         // add new effect to jQuery UI
6019         $.effects.slideOffscreen = function(o) {
6020                 return this.queue(function(){
6021
6022                         var fx          = $.effects
6023                         ,       opt             = o.options
6024                         ,       $el             = $(this)
6025                         ,       pane    = $el.data('layoutEdge')
6026                         ,       state   = $el.data('parentLayout').state
6027                         ,       dist    = state[pane].size
6028                         ,       s               = this.style
6029                         ,       props   = ['top','bottom','left','right']
6030                                 // Set options
6031                         ,       mode    = fx.setMode($el, opt.mode || 'show') // Set Mode
6032                         ,       show    = (mode == 'show')
6033                         ,       dir             = opt.direction || 'left' // Default Direction
6034                         ,       ref             = (dir == 'up' || dir == 'down') ? 'top' : 'left'
6035                         ,       pos             = (dir == 'up' || dir == 'left')
6036                         ,       offscrn = $.layout.config.offscreenCSS || {}
6037                         ,       keyLR   = $.layout.config.offscreenReset
6038                         ,       keyTB   = 'offscreenResetTop' // only used internally
6039                         ,       animation = {}
6040                         ;
6041                         // Animation settings
6042                         animation[ref]  = (show ? (pos ? '+=' : '-=') : (pos ? '-=' : '+=')) + dist;
6043
6044                         if (show) { // show() animation, so save top/bottom but retain left/right set when 'hidden'
6045                                 $el.data(keyTB, { top: s.top, bottom: s.bottom });
6046
6047                                 // set the top or left offset in preparation for animation
6048                                 // Note: ALL animations work by shifting the top or left edges
6049                                 if (pos) { // top (north) or left (west)
6050                                         $el.css(ref, isNaN(dist) ? "-" + dist : -dist); // Shift outside the left/top edge
6051                                 }
6052                                 else { // bottom (south) or right (east) - shift all the way across container
6053                                         if (dir === 'right')
6054                                                 $el.css({ left: state.container.layoutWidth, right: 'auto' });
6055                                         else // dir === bottom
6056                                                 $el.css({ top: state.container.layoutHeight, bottom: 'auto' });
6057                                 }
6058                                 // restore the left/right setting if is a top/bottom animation
6059                                 if (ref === 'top')
6060                                         $el.css( $el.data( keyLR ) || {} );
6061                         }
6062                         else { // hide() animation, so save ALL CSS
6063                                 $el.data(keyTB, { top: s.top, bottom: s.bottom });
6064                                 $el.data(keyLR, { left: s.left, right: s.right });
6065                         }
6066
6067                         // Animate
6068                         $el.show().animate(animation, { queue: false, duration: o.duration, easing: opt.easing, complete: function(){
6069                                 // Restore top/bottom
6070                                 if ($el.data( keyTB ))
6071                                         $el.css($el.data( keyTB )).removeData( keyTB );
6072                                 if (show) // Restore left/right too
6073                                         $el.css($el.data( keyLR ) || {}).removeData( keyLR );
6074                                 else // Move the pane off-screen (left: -99999, right: 'auto')
6075                                         $el.css( offscrn );
6076
6077                                 if (o.callback) o.callback.apply(this, arguments); // Callback
6078                                 $el.dequeue();
6079                         }});
6080
6081                 });
6082         };
6083
6084 }
6085
6086 })( jQuery );