1 (function(){
  2     
  3     // This is helpful during development of tests, but may hide errors in
  4     // handling caching in the actual panel component. Be careful!
  5     $.ajaxSetup({
  6         cache: false
  7     });
  8     
  9     var html = [
 10         '<div>',
 11             '<style id="ssheet1" type="text/css" media="screen">',
 12                 'div#foo {padding:100px;};',
 13             '</style>',
 14             '<script type="text/javascript" charset="utf-8">',
 15                 'madrona.onShow(function(){',
 16                 	"$(document.body).append('<div id=\"sctSuccess\" />');",
 17                 '});',
 18                 'madrona.onShow(function(){',
 19                 	"$(document.body).append('<div id=\"sctSuccess2\" />');",
 20                 '});',
 21             '</script>',
 22             // should be ignored
 23             '<script src="blah.js" type="text/javascript" charset="utf-8">',
 24             '</script>',
 25             // html should make it out and be available via 
 26             // SanitizedContent#html
 27             '<p id="foo">bar</p></div>',
 28         '</div>'
 29     ].join('');
 30     
 31     var html2 = [
 32         '<div>',
 33             '<style id="ssheet1" type="text/css" media="screen">',
 34                 'div#foo {padding:100px;};',
 35             '</style>',
 36             '<script type="text/javascript" charset="utf-8">',
 37                 'madrona.onShow(function(){',
 38                 	"$(document.body).append('<div id=\"sctSuccess\" />');",
 39                 '});',
 40                 'madrona.onShow("#tab1", function(){',
 41                 	"$(document.body).append('<div id=\"tabSuccess1\" />');",
 42                 '});',
 43                 'madrona.onShow("#tab2", function(){',
 44                 	"$(document.body).append('<div id=\"tabSuccess2\" />');",
 45                 '});',
 46                 'madrona.onShow("#tab2", function(){',
 47                 	"$(document.body).append('<div id=\"tabSuccess22\" />');",
 48                 '});',
 49             '</script>',
 50             '<div class="tabs">',
 51                 '<ul>',
 52                     '<li><a href="tab1"><span>tab1</span></a></li>',
 53                     '<li><a href="tab2"><span>tab2</span></a></li>',
 54                 '</ul>',
 55                 '<div id="tab1"></div>',
 56                 '<div id="tab2"></div>',
 57             '</div>',
 58         '</div>'
 59     ].join('');
 60         
 61     module('SanitizedContent');
 62     
 63     test('strips out style and script tags', function(){
 64         var content = new madrona.layout.SanitizedContent(html);
 65         ok(!content.html.match('script'), 'script tags removed');
 66         ok(!content.html.match('style'), 'style tags removed');
 67         ok(content.html.match('foo'), 'html left intact');
 68     });
 69 
 70     test('addStylesToDocument', function(){
 71         var content = new madrona.layout.SanitizedContent(html);
 72         content.addStylesToDocument();
 73         ok($('#ssheet1').length === 1, 'stylesheet added to doc');
 74         var content = new madrona.layout.SanitizedContent(html);
 75         content.addStylesToDocument();
 76         ok($('#ssheet1').length === 1, 'stylesheet added to doc only once');
 77     });
 78     
 79     test('finds onShow callbacks', function(){
 80         var content = new madrona.layout.SanitizedContent(html);
 81         var callbacks = content.extractCallbacks();
 82         ok(callbacks['panel'] && callbacks['panel'].show && 
 83             callbacks['panel'].show.length === 2, 'found two callbacks');
 84         callbacks['panel'].show[0](); callbacks['panel'].show[1]();
 85         ok($('#sctSuccess').length === 1, 'appropriate callbacks stored.');
 86         ok($('#sctSuccess2').length === 1, 'appropriate callbacks stored.');
 87         $('#sctSuccess, #sctSuccess2').remove();
 88     });
 89 
 90     test('finds onShow callbacks bound to tabs', function(){
 91         var content = new madrona.layout.SanitizedContent(html2);
 92         var callbacks = content.extractCallbacks();
 93         ok(callbacks['panel']);
 94         ok(callbacks['panel'] && callbacks['panel'].show && 
 95             callbacks['panel'].show.length === 1, 'found one panel callback');
 96         ok(callbacks['tabs'] && callbacks['tabs']['#tab1'].show.length === 1, 
 97             'found one callback for tab1');
 98         ok(callbacks['tabs'] && callbacks['tabs']['#tab2'].show.length === 2, 
 99             'found two callbacks for tab2');
100         callbacks['panel'].show[0]();
101         ok($('#sctSuccess').length === 1, 'appropriate callbacks stored.');
102         callbacks['tabs']['#tab1'].show[0]();
103         ok($('#tabSuccess1').length === 1, 'appropriate callbacks stored.');
104         callbacks['tabs']['#tab2'].show[0]();
105         ok($('#tabSuccess2').length === 1, 'appropriate callbacks stored.');
106         callbacks['tabs']['#tab2'].show[1]();
107         ok($('#tabSuccess22').length === 1, 'appropriate callbacks stored.');
108         $('#tabSuccess22, #tabSuccess2, #tabSuccess1, #sctSuccess').remove();
109     });
110     
111     module('contentLoader');
112     
113     asyncTest('error handling', function(){
114         var target = $('<div id="target"></div>');
115         $(document.body).append(target);
116         var loader = madrona.contentLoader({
117             url: '../url/that/doesnt/exist/',
118             target: target,
119             success: function(){
120                 ok(false, 
121                     'success called even though content does not exist!');
122                 $('#target').remove();
123                 start();
124             },
125             error: function(){
126                 ok(true, 'Could not load url.');
127                 $('#target').remove();
128                 start();
129             }
130         });
131         loader.load();
132     });
133     
134     // Verify creation of tabs and subtabs from markup
135     // ===============================================
136     
137     asyncTest('verify "a simple panel" example from docs.', function(){
138         var target = $('<div id="target"></div>');
139         $(document.body).append(target);
140         var loader = madrona.contentLoader({
141             url: '../media/common/js/test/layout/example1.html',
142             target: target,
143             success: function(){
144                 ok(true, 'content loaded.');
145                 ok(target.find('.panel').length === 1, 
146                     'content appended to target and success handler called.');
147                 $('#target').remove();
148                 start();
149             },
150             error: function(){
151                 ok(false, 'Could not load url.');
152                 $('#target').remove();
153                 start();
154             }
155         });
156         loader.load();
157     });
158     
159     asyncTest('verify "synchronous tabs" example from docs.', function(){
160         var t = $('<div id="target"></div>');
161         $(document.body).append(t);
162         var loader = madrona.contentLoader({
163             url: '../media/common/js/test/layout/example2.html',
164             target: t,
165             success: function(){
166                 ok(true, 'content loaded.');
167                 ok(t.find('.panel').length === 1, 
168                     'content appended to target and success handler called.');
169                 ok(t.find('#Report').hasClass('ui-tabs-hide') === true, 
170                     'Report tab content should be hidden');
171                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === false, 
172                     'Attributes tab content should be shown');
173                 // make sure tabs are working
174                 t.find('a[href=#Report]').click();
175                 ok(t.find('#Report').hasClass('ui-tabs-hide') === false, 
176                     'Clicking tab should show it.');
177                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === true, 
178                     'Attributes tab content should be hidden now.');
179                 $('#target').remove();
180                 start();
181             },
182             error: function(){
183                 ok(false, 'Could not load url.');
184                 $('#target').remove();
185                 start();
186             }
187         });
188         loader.load();
189     });
190 
191     asyncTest('verify "asynchronous tabs" example from docs.', function(){
192         var t = $('<div id="target"></div>');
193         $(document.body).append(t);
194         var loader = madrona.contentLoader({
195             url: '../media/common/js/test/layout/example3.html',
196             target: t,
197             success: function(){
198                 ok(true, 'content loaded.');
199                 ok(t.find('.panel').length === 1, 
200                     'appended to target and success handler called.');
201                 ok(t.find('#Report').length === 0, 
202                     'No report div yet.');
203                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === false, 
204                     'Attributes tab content should be shown');
205                 // make sure tabs are working
206                 t.find('a:contains(Report)').click();
207                 t.find('.tabs').bind('tabsload', function(){
208                     t.find('.tabs').unbind('tabsload');
209                     ok(t.find('img.chart').length === 1, 'content loaded');
210                     var report = t.find('img.chart').parent().parent();
211                     ok(!report.hasClass('ui-tabs-hide'), 
212                         'Report tab is shown');
213                     ok(t.find('#Attributes').hasClass('ui-tabs-hide'), 
214                         'Attributes tab content should be hidden now');
215                     $('#target').remove();
216                     start();
217                 });
218             },
219             error: function(){
220                 ok(false, 'Could not load url.');
221                 $('#target').remove();
222                 start();
223             }
224         });
225         loader.load();
226     });
227     
228     asyncTest('synchronous tabs with subtabs.', function(){
229         var t = $('<div id="target"></div>');
230         $(document.body).append(t);
231         var loader = madrona.contentLoader({
232             url: '../media/common/js/test/layout/example4.html',
233             target: t,
234             success: function(){
235                 ok(true, 'content loaded.');
236                 ok(t.find('.panel').length === 1, 
237                     'appended to target and success called afterwards.');
238                 ok(t.find('#Report').hasClass('ui-tabs-hide') === true, 
239                     'Report tab content should be hidden');
240                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === false, 
241                     'Attributes tab content should be shown');
242                 // make sure tabs are working
243                 t.find('a[href=#Report]').click();
244                 ok(t.find('#Report').hasClass('ui-tabs-hide') === false, 
245                     'Clicking tab should show it.');
246                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === true, 
247                     'Attributes tab content should be hidden now.');
248                 var subtabs = t.find('#Report');
249                 ok(subtabs.find('ul').hasClass('ui-tabs-nav'), 
250                     'subtabs active');
251                 ok(!subtabs.find('#chart').hasClass('ui-tabs-hide'), 
252                     'first subtab shown');
253                 ok(subtabs.find('#grid').hasClass('ui-tabs-hide'), 
254                     'second subtab hidden');
255                 subtabs.find('a:contains(Grid)').click();
256                 ok(subtabs.find('#chart').hasClass('ui-tabs-hide'), 
257                     'first subtab hidden');
258                 ok(!subtabs.find('#grid').hasClass('ui-tabs-hide'), 
259                     'second subtab shown');
260                 $('#target').remove();
261                 start();
262             },
263             error: function(){
264                 ok(false, 'Could not load url.');
265                 $('#target').remove();
266                 start();
267             }
268         });
269         loader.load();
270     });
271     
272     asyncTest('synchronous tabs with async subtabs.', function(){
273         var t = $('<div id="target"></div>');
274         $(document.body).append(t);
275         var loader = madrona.contentLoader({
276             url: '../media/common/js/test/layout/example6.html',
277             target: t,
278             success: function(){
279                 ok(true, 'content loaded.');
280                 ok(t.find('.panel').length === 1, 
281                     'content appended to target and success handler called.');
282                 ok(t.find('#Report').hasClass('ui-tabs-hide') === true, 
283                     'Report tab content should be hidden');
284                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === false, 
285                     'Attributes tab content should be shown');
286                 // make sure tabs are working
287                 t.find('a[href=#Report]').click();
288                 ok(t.find('#Report').hasClass('ui-tabs-hide') === false, 
289                     'Clicking tab should show it.');
290                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === true, 
291                     'Attributes tab content should be hidden now.');
292                 ok(!t.find('#sub1').hasClass('ui-tabs-hide'), 
293                     'first subtab selected');
294                 t.find('a:contains(subtab2)').click();
295                 t.find('.tabs').bind('tabsload', function(){
296                     t.find('.tabs').unbind('tabsload');
297                     // A timeout has to go here because tabsload actually
298                     // fires before the content is shown, and tabsshow is 
299                     // called evenbefore that
300                     setTimeout(function(){
301                         ok(t.find('img.chart').length === 1, 
302                             'content loaded');
303                         var subtab1 = t.find('img.chart').parent().parent();
304                         var parent = subtab1.parent().parent();
305                         ok(!parent.hasClass('ui-tabs-hide'), 
306                             'subtab2 is shown');
307                         t.find('a:contains(subtab1)').click();
308                         ok(!t.find('#sub1').hasClass('ui-tabs-hide'), 
309                             'first subtab now selected');
310                         start();
311                     }, 100);
312                 });
313             },
314             error: function(){
315                 ok(false, 'Could not load url.');
316                 $('#target').remove();
317                 start();
318             }
319         });
320         loader.load();
321     });
322     
323     asyncTest('async tabs with subtabs.', function(){
324         $('#target').remove();
325         var t = $('<div id="target"></div>');
326         $(document.body).append(t);
327         var loader = madrona.contentLoader({
328             url: '../media/common/js/test/layout/example5.html',
329             target: t,
330             success: function(){
331                 ok(true, 'content loaded.');
332                 ok(t.find('.panel').length === 1, 
333                     'content appended to target and success handler called.');
334                 ok(t.find('#Report').length === 0, 
335                     'No report div yet.');
336                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === false, 
337                     'Attributes tab content should be shown');
338                 // make sure tabs are working
339                 t.find('a:contains(Report)').click();
340                 t.find('.tabs').bind('tabsload', function(){
341                     t.find('.tabs').unbind('tabsload');
342                     // A timeout has to go here because tabsload actually
343                     // fires before the content is shown, and tabsshow is 
344                     // called evenbefore that
345                     setTimeout(function(){
346                         ok(t.find('img.chart').length === 1, 
347                             'content loaded');
348                         var reports = t.find('img.chart').parent().parent();
349                         var parent = reports.parent().parent();
350                         ok(!parent.hasClass('ui-tabs-hide'), 
351                             'Report tab is shown');
352                         ok(t.find('#Attributes').hasClass('ui-tabs-hide'), 
353                             'Attributes tab content should be hidden now');
354                         ok(!reports.find('#chart').hasClass('ui-tabs-hide'), 
355                             'first subtab shown');
356                         ok(reports.find('#grid').hasClass('ui-tabs-hide'), 
357                             'second subtab hidden');
358                         reports.find('a:contains(Grid)').click();
359                         ok(reports.find('#chart').hasClass('ui-tabs-hide'), 
360                             'first subtab hidden');
361                         ok(!reports.find('#grid').hasClass('ui-tabs-hide'), 
362                             'second subtab shown');
363                         $('#target').remove();
364                         start();                        
365                     }, 200);
366                 });
367             },
368             error: function(){
369                 ok(false, 'Could not load url.');
370                 $('#target').remove();
371                 start();
372             }
373         });
374         loader.load();
375     });
376     
377     asyncTest('async tabs with async subtabs.', function(){
378         $('#target').remove();
379         var t = $('<div id="target"></div>');
380         $(document.body).append(t);
381         var loader = madrona.contentLoader({
382             url: '../media/common/js/test/layout/example7.html',
383             target: t,
384             success: function(){
385                 ok(true, 'content loaded.');
386                 ok(t.find('.panel').length === 1, 
387                     'content appended to target and success handler called.');
388                 ok(t.find('#Report').length === 0, 
389                     'No report div yet.');
390                 ok(t.find('#Attributes').hasClass('ui-tabs-hide') === false, 
391                     'Attributes tab content should be shown');
392                 // make sure tabs are working
393                 t.find('a:contains(Report)').click();
394                 t.find('.tabs').bind('tabsload', function(){
395                     t.find('.tabs').unbind('tabsload');
396                     // A timeout has to go here because tabsload actually
397                     // fires before the content is shown, and tabsshow is 
398                     // called evenbefore that
399                     setTimeout(function(){
400                         ok(t.find('img.chart1').length === 1, 
401                             'content loaded');
402                         var reports = t.find('img.chart1').parent().parent();
403                         var parent = reports.parent().parent();
404                         ok(!parent.hasClass('ui-tabs-hide'), 
405                             'Report tab is shown');
406                         ok(t.find('#Attributes').hasClass('ui-tabs-hide'), 
407                             'Attributes tab content should be hidden now');
408                         ok(!reports.find('#subtab1').hasClass('ui-tabs-hide'), 
409                             'first subtab shown');
410                         reports.find('a:contains(subtab2)').click();
411                         parent.bind('tabsload', function(){
412                             parent.unbind('tabsload');
413                             setTimeout(function(){
414                                 ok(reports.find('img.chart'), 
415                                     'subtab content loaded');
416                                 var subtab2 = reports.find('img.chart')
417                                     .parent().parent();
418                                 ok(!subtab2.hasClass('ui-tabs-hide'), 
419                                     'tab is shown');
420                                 $('#target').remove();
421                                 start();                                                        
422                             }, 200);
423                         });
424                     }, 200);
425                 });
426             },
427             error: function(){
428                 ok(false, 'Could not load url.');
429                 $('#target').remove();
430                 start();
431             }
432         });
433         loader.load();
434     });
435 
436     // Verify stylesheet handling
437     // ==========================
438     
439     asyncTest('verify simple css example from docs', function(){
440         var target = $('<div id="target"></div>');
441         $(document.body).append(target);
442         var loader = madrona.contentLoader({
443             url: '../media/common/js/test/layout/cssExample1.html',
444             target: target,
445             success: function(){
446                 var target = $('#target');
447                 ok(true, 'content loaded.');
448                 ok(target.find('.panel').length === 1, 
449                     'content appended to target and success handler called.');
450                 equals($('#chartStyle').length, 1, 'Style added to document');
451                 $('#target').remove();
452                 var target = $('<div id="target"></div>');
453                 $(document.body).append(target);
454                 var numStyles = $('style').length;
455                 var loader = madrona.contentLoader({
456                     url: '../media/common/js/test/layout/cssExample1.html',
457                     target: target,
458                     error: function(){
459                         ok(false, 'Could not load url.');
460                         $('#target').remove();
461                         start();
462                     },
463                     success: function(){
464                         ok(true, 'content loaded.');
465                         ok(target.find('.panel').length === 1, 
466                             'content appended and success handler called.');
467                         equals($('#chartStyle').length, 1, 
468                             'Style added to document');
469                         equals($('style').length, numStyles, 
470                             'style tag only added once for the same id');
471                         start();                        
472                     }                
473                 });
474                 loader.load();
475                 
476             },
477             error: function(){
478                 ok(false, 'Could not load url.');
479                 $('#target').remove();
480                 start();
481             }
482         });
483         loader.load();
484     });
485     
486     var numStyles;
487     
488     asyncTest('verify complex css example from docs \
489         (2 style tags, one w/id one without)', function(){
490         numStyles = 0;
491         $('#target').remove();
492         $('#chartStyle').remove();
493         var target = $('<div id="target"></div>');
494         $(document.body).append(target);
495         numStyles = $('style').length;
496         var loader = madrona.contentLoader({
497             url: '../media/common/js/test/layout/cssExample2.html',
498             target: target,
499             success: function(){
500                 var target = $('#target');
501                 ok(true, 'content loaded.');
502                 ok(target.find('.panel').length === 1, 
503                     'content appended to target and success handler called.');
504                 equals($('#chartStyle').length, 1, 'Style added to document');
505                 equals($('style').length - numStyles, 2, 
506                     'two style tags added');
507                 $('#target').remove();
508                 var target = $('<div id="target"></div>');
509                 $(document.body).append(target);
510                 numStyles = $('style').length;
511                 var loader = madrona.contentLoader({
512                     url: '../media/common/js/test/layout/cssExample2.html',
513                     target: target,
514                     error: function(){
515                         ok(false, 'Could not load url.');
516                         $('#target').remove();
517                         start();
518                     },
519                     success: function(){
520                         ok(true, 'content loaded.');
521                         ok(target.find('.panel').length === 1, 
522                             'content appended to target and success called.');
523                         equals($('#chartStyle').length, 1, 
524                             'only one style tag with id=chartStyle added');
525                         equals(($('style').length - numStyles), 1, 
526                             'only one style tag added the second time.');
527                         $('#target').remove();
528                         start();                        
529                     }                
530                 });
531                 loader.load();
532                 
533             },
534             error: function(){
535                 ok(false, 'Could not load url.');
536                 $('#target').remove();
537                 start();
538             }
539         });
540         loader.load();
541     });
542     
543     asyncTest('css stylesheets can be added via async tabs', function(){
544         $('#exampleThreePointOneStyle').remove();
545         $('#target').remove();
546         numStyle = 0;
547         var t = $('<div id="target"></div>');
548         $(document.body).append(t);
549         var loader = madrona.contentLoader({
550             url: '../media/common/js/test/layout/example3.html',
551             target: t,
552             success: function(){
553                 ok(true, 'content loaded.');
554                 ok(t.find('.panel').length === 1, 
555                     'appended to target and success handler called.');
556                 numStyle = $('style').length;
557                 t.find('a:contains(Report)').click();
558                 t.find('.tabs').bind('tabsload', function(){
559                     t.find('.tabs').unbind('tabsload');
560                     setTimeout(function(){
561                         ok(t.find('img.chart').length === 1, 
562                             'content loaded');
563                         equals($('style').length - numStyle, 1, 
564                             'One stylesheet added');
565                         ok($('style#exampleThreePointOneStyle').length == 1, 
566                             'has the right ID');
567                         $('#target').remove();
568                         start();
569                         
570                     }, 100);
571                 });
572             },
573             error: function(){
574                 ok(false, 'Could not load url.');
575                 $('#target').remove();
576                 start();
577             }
578         });
579         loader.load();
580     });
581     
582     // Verify javascript event handling
583     // ================================
584     
585     asyncTest('verify 1st inline js example (onShow) from docs', function(){
586         var target = $('<div id="target"></div>');
587         $(document.body).append(target);
588         window.callbackFired = 0;
589         window.selectedEl = undefined;
590         var loader = madrona.contentLoader({
591             url: '../media/common/js/test/layout/jsExample1.html',
592             target: target,
593             success: function(){
594                 ok(true, 'content loaded.');
595                 ok(target.find('.panel').length === 1, 
596                     'content appended to target and success handler called.');
597                 equals(window.callbackFired, 1, 'Callback was executed');
598                 equals(window.selectedEl.length, 1, 
599                     'Callback executed after content was added to document');
600                 window.callbackFired = undefined;
601                 window.selectedEl = undefined;
602                 $('#target').remove();
603                 start();
604             },
605             error: function(){
606                 ok(false, 'Could not load url.');
607                 $('#target').remove();
608                 start();
609             }
610         });
611         loader.load();
612     });
613     
614     asyncTest('verify 2nd inline js example (onShow with tabs)', function(){
615         var target = $('<div id="target"></div>');
616         $(document.body).append(target);
617         window.callbackFired = 0;
618         window.selectedEl = undefined;
619         var loader = madrona.contentLoader({
620             url: '../media/common/js/test/layout/jsExample2.html',
621             target: target,
622             success: function(){
623                 ok(true, 'content loaded.');
624                 ok(target.find('.panel').length === 1, 
625                     'content appended to target and success handler called.');
626                 ok(!window.callbackFired, 'callback not fired yet.');
627                 ok(!window.selectedEl, 'callback not fired until tab click');
628                 $('a:contains(Report)').click();
629                 ok(window.callbackFired, 'callback fired after tab opened');
630                 ok(window.selectedEl.length == 1, 
631                     'callback executed after content added to doc');
632                 window.callbackFired = undefined;
633                 window.selectedEl = undefined;
634                 $('a:contains(Information)').click();
635                 $('a:contains(Report)').click();
636                 ok(!window.callbackFired, 'onShow is called only once.');                
637                 $('#target').remove();
638                 start();
639             },
640             error: function(){
641                 ok(false, 'Could not load url.');
642                 $('#target').remove();
643                 start();
644             }
645         });
646         loader.load();
647     });
648 
649     
650     asyncTest('verify 3rd inline js example (onShow with tabs)', function(){
651         var t = $('<div id="target"></div>');
652         $(document.body).append(t);
653         window.callbackFired = 0;
654         window.selectedEl = undefined;
655         var loader = madrona.contentLoader({
656             url: '../media/common/js/test/layout/jsExample3.html',
657             target: t,
658             success: function(){
659                 ok(true, 'content loaded.');
660                 ok(t.find('.panel').length === 1, 
661                     'appended to target and success handler called.');
662                 ok(!window.callbackFired, 'callback not fired yet.');
663                 ok(!window.selectedEl, 'callback not fired until tab click');
664                 t.find('a:contains(Report)').click();
665                 t.find('.tabs').bind('tabsload', function(){
666                     t.find('.tabs').unbind('tabsload');
667                     setTimeout(function(){
668                         ok(t.find('img.chart').length === 1, 
669                             'content loaded');
670                         ok(window.callbackFired, 
671                             'callback fired after tab opened');
672                         ok(window.selectedEl.length == 1, 
673                             'callback executed after content added to doc');
674                         $('#target').remove();
675                         start();
676                         
677                     }, 100);
678                 });
679             },
680             error: function(){
681                 ok(false, 'Could not load url.');
682                 $('#target').remove();
683                 start();
684             }
685         });
686         loader.load();
687     });
688 
689     asyncTest('same as above but w/callback on first tab as well', function(){
690         var t = $('<div id="target"></div>');
691         $(document.body).append(t);
692         window.callbackFired = 0;
693         window.selectedEl = undefined;
694         window.callbackOne = 0;
695         var loader = madrona.contentLoader({
696             url: '../media/common/js/test/layout/jsExample4.html',
697             target: t,
698             success: function(){
699                 ok(true, 'content loaded.');
700                 ok(t.find('.panel').length === 1, 
701                     'appended to target and success handler called.');
702                 ok(!window.callbackFired, 'callback not fired yet.');
703                 ok(!window.selectedEl, 'callback not fired until tab click');
704                 ok(window.callbackOne, "first tab's callback fired");
705                 t.find('a:contains(Report)').click();
706                 t.find('.tabs').bind('tabsload', function(){
707                     t.find('.tabs').unbind('tabsload');
708                     setTimeout(function(){
709                         ok(t.find('img.chart').length === 1, 
710                             'content loaded');
711                         ok(window.callbackFired, 
712                             'callback fired after tab opened');
713                         ok(window.selectedEl.length == 1, 
714                             'callback executed after content added to doc');
715                         t.find('a:contains(Information)').click();
716                         equals(window.callbackOne, 1, 
717                             "first tab's callback fires only once");                        
718                         t.find('a:contains(Report)').click();
719                         equals(window.callbackFired, 1, 
720                             "second tab's callback fires only once");                        
721                         $('#target').remove();
722                         start();
723                         
724                     }, 100);
725                 });
726             },
727             error: function(){
728                 ok(false, 'Could not load url.');
729                 $('#target').remove();
730                 start();
731             }
732         });
733         loader.load();
734     });
735 
736     asyncTest('onHide/onUnhide with synchronous tabs', function(){
737         var target = $('<div id="target"></div>');
738         $(document.body).append(target);
739         // zero out variables that the callbacks will interact with
740         window.attributesShown      = 0;
741         window.attributesUnhidden   = 0;
742         window.attributesHidden     = 0;
743         window.reportShown          = 0;
744         window.reportUnhidden       = 0;
745         window.reportHidden         = 0;
746 
747         var loader = madrona.contentLoader({
748             url: '../media/common/js/test/layout/jsExample5.html',
749             target: $('#target'),
750             success: function(){
751                 ok(true, 'content loaded.');
752                 ok(target.find('.panel').length === 1, 
753                     'content appended to target and success handler called.');
754                     
755                 // test initial state callbacks
756                 equals(window.attributesShown, 1, 'attributes onshow fired');
757                 equals(window.attributesUnhidden, 1, 
758                     'attributes onUnhide fired');
759                 equals(window.attributesHidden, 0, 
760                     'attributes onHide not fired yet');
761                 equals(window.reportHidden, 0, 
762                     'report onHide not fired yet');
763                 equals(window.reportShown, 0, 
764                     'report onShow not fired yet');
765                 equals(window.reportUnhidden, 0, 
766                     'report onUnhide not fired yet');
767 
768                 // change to reports tab
769                 target.find('a:contains(Report)').click();
770                 
771                 equals(window.attributesShown, 1, "hasn't changed");
772                 equals(window.attributesUnhidden, 1, 
773                     "hasn't changed");
774                 equals(window.attributesHidden, 1, 
775                     'attributes onHide fired');
776                 equals(window.reportHidden, 0, 
777                     'report onHide not fired yet');
778                 equals(window.reportShown, 1, 
779                     'report onShow fired');
780                 equals(window.reportUnhidden, 1, 
781                     'report onUnhide fired');
782                 
783                 // change back to attributes
784                 target.find('a:contains(Information)').click();
785                 equals(window.attributesShown, 1, "onShow fires only once");
786                 equals(window.attributesUnhidden, 2, 
787                     "onUnhide called again");
788                 equals(window.attributesHidden, 1, 
789                     'unchanged');
790                 equals(window.reportHidden, 1, 
791                     'report onHide fired');
792                 equals(window.reportShown, 1, 
793                     'unchanged');
794                 equals(window.reportUnhidden, 1, 
795                     'unchanged');
796 
797                 // change back to reports
798                 target.find('a:contains(Report)').click();
799                 equals(window.attributesShown, 1, "onShow fires only once");
800                 equals(window.attributesUnhidden, 2, 
801                     "unchanged");
802                 equals(window.attributesHidden, 2, 
803                     'attributes onHide called again');
804                 equals(window.reportHidden, 1, 
805                     'unchanged');
806                 equals(window.reportShown, 1, 
807                     'only called once');
808                 equals(window.reportUnhidden, 2, 
809                     'report onUnhide called again');
810 
811                 
812                 // cleanup
813                 window.attributesShown      = 0;
814                 window.attributesUnhidden   = 0;
815                 window.attributesHidden     = 0;
816                 window.reportShown          = 0;
817                 window.reportUnhidden       = 0;
818                 window.reportHidden         = 0;
819                 
820                 $('#target').remove();
821                 start();
822             },
823             error: function(){
824                 ok(false, 'Could not load url.');
825                 $('#target').remove();
826                 start();
827             }
828         });
829         loader.load();
830     });
831     
832     asyncTest('onHide/onUnhide with async tabs', function(){
833         $('#target').remove();
834         var target = $('<div id="target"></div>');
835         $(document.body).append(target);
836         // zero out variables that the callbacks will interact with
837         window.attributesShown      = 0;
838         window.attributesUnhidden   = 0;
839         window.attributesHidden     = 0;
840         window.reportShown          = 0;
841         window.reportUnhidden       = 0;
842         window.reportHidden         = 0;
843         
844         window.onUnhideSelected = false;
845 
846         var loader = madrona.contentLoader({
847             url: '../media/common/js/test/layout/jsExample6.html',
848             target: $('#target'),
849             success: function(){
850                 ok(true, 'content loaded.');
851                 ok(target.find('.panel').length === 1, 
852                     'content appended to target and success handler called.');
853                     
854                 // test initial state callbacks
855                 equals(window.attributesShown, 1, 'attributes onshow fired');
856                 equals(window.attributesUnhidden, 1, 
857                     'attributes onUnhide fired');
858                 equals(window.attributesHidden, 0, 
859                     'attributes onHide not fired yet');
860                 equals(window.reportHidden, 0, 
861                     'report onHide not fired yet');
862                 equals(window.reportShown, 0, 
863                     'report onShow not fired yet');
864                 equals(window.reportUnhidden, 0, 
865                     'report onUnhide not fired yet');
866 
867                 // change to reports tab
868                 target.find('a:contains(Report)').click();
869                 
870                 target.find('.tabs').bind('tabsload', function(){
871                     target.find('.tabs').unbind('tabsload');
872                     setTimeout(function(){                
873                         equals(window.attributesShown, 1, "hasn't changed");
874                         equals(window.attributesUnhidden, 1, 
875                             "hasn't changed");
876                         equals(window.attributesHidden, 1, 
877                             'attributes onHide fired');
878                         equals(window.reportHidden, 0, 
879                             'report onHide not fired yet');
880                         equals(window.reportShown, 1, 
881                             'report onShow fired');
882                         equals(window.reportUnhidden, 1, 
883                             'report onUnhide fired');
884                 
885                         // change back to attributes
886                         target.find('a:contains(Information)').click();
887                         equals(window.attributesShown, 1, 
888                             "onShow fires only once");
889                         equals(window.attributesUnhidden, 2, 
890                             "onUnhide called again");
891                         equals(window.attributesHidden, 1, 
892                             'unchanged');
893                         equals(window.reportHidden, 1, 
894                             'report onHide fired');
895                         equals(window.reportShown, 1, 
896                             'unchanged');
897                         equals(window.reportUnhidden, 1, 
898                             'unchanged');
899 
900                         // change back to reports
901                         target.find('a:contains(Report)').click();
902                         equals(window.attributesShown, 1, 
903                             "onShow fires only once");
904                         equals(window.attributesUnhidden, 2, 
905                             "unchanged");
906                         equals(window.attributesHidden, 2, 
907                             'attributes onHide called again');
908                         equals(window.reportHidden, 1, 
909                             'unchanged');
910                         equals(window.reportShown, 1, 
911                             'only called once');
912                         equals(window.reportUnhidden, 2, 
913                             'report onUnhide called again');
914 
915                 
916                         // cleanup
917                         window.attributesShown      = 0;
918                         window.attributesUnhidden   = 0;
919                         window.attributesHidden     = 0;
920                         window.reportShown          = 0;
921                         window.reportUnhidden       = 0;
922                         window.reportHidden         = 0;
923                 
924                         $('#target').remove();
925                         start();
926                         
927                     }, 100);                    
928                 });
929             },
930             error: function(){
931                 ok(false, 'Could not load url.');
932                 $('#target').remove();
933                 start();
934             }
935         });
936         loader.load();        
937     });
938     
939     asyncTest('nested tabs with onHide/onUnhide', function(){
940         $('#target').remove();
941         var target = $('<div id="target"></div>');
942         $(document.body).append(target);
943         // zero out variables that the callbacks will interact with
944         window.attributesShown      = 0;
945         window.attributesUnhidden   = 0;
946         window.attributesHidden     = 0;
947         window.reportShown          = 0;
948         window.reportUnhidden       = 0;
949         window.reportHidden         = 0;
950                                
951         window.subtab1Shown         = 0;
952         window.subtab1Unhidden      = 0;
953         window.subtab1Hidden        = 0;
954         window.subtab2Shown         = 0;
955         window.subtab2Unhidden      = 0;
956         window.subtab2Hidden        = 0;    
957 
958         var loader = madrona.contentLoader({
959             url: '../media/common/js/test/layout/jsExample7.html',
960             target: $('#target'),
961             success: function(){
962                 ok(true, 'content loaded.');
963                 ok(target.find('.panel').length === 1, 
964                     'content appended to target and success handler called.');
965                     
966                 // test initial state callbacks
967                 equals(window.attributesShown, 1, 
968                     'attributes onshow fired');
969                 equals(window.attributesUnhidden, 1, 
970                     'attributes onUnhide fired');
971                 equals(window.attributesHidden, 0, 
972                     'attributes onHide not fired yet');
973                 equals(window.reportHidden, 0, 
974                     'report onHide not fired yet');
975                 equals(window.reportShown, 0, 
976                     'report onShow not fired yet');
977                 equals(window.reportUnhidden, 0, 
978                     'report onUnhide not fired yet');
979                 // subtabs
980                 equals(window.subtab1Shown, 0,
981                     'subtab1 not shown yet');
982                 equals(window.subtab1Unhidden, 0,
983                     'subtab1 not unhidden yet');
984                 equals(window.subtab1Hidden, 0,
985                     'subtab1 not hidden yet');
986                 equals(window.subtab2Shown, 0,
987                     'subtab2 not shown yet');
988                 equals(window.subtab2Unhidden, 0,
989                     'subtab2 not unhidden yet');
990                 equals(window.subtab2Hidden, 0,
991                     'subtab2 not hidden yet');
992 
993                 // change to reports tab
994                 target.find('a:contains(Report)').click();
995                 
996                 target.find('.tabs').bind('tabsload', function(){
997                     target.find('.tabs').unbind('tabsload');
998                     setTimeout(function(){
999                         
1000                         equals(window.attributesShown, 1, 
1001                             'unchanged');
1002                         equals(window.attributesUnhidden, 1, 
1003                             'unchanged');
1004                         equals(window.attributesHidden, 1, 
1005                             'attributes onHide fired');
1006                         equals(window.reportHidden, 0, 
1007                             'report onHide not fired yet');
1008                         equals(window.reportShown, 1, 
1009                             'report onShow fired');
1010                         equals(window.reportUnhidden, 1, 
1011                             'report onUnhide fired');
1012                         // subtabs    
1013                         equals(window.subtab1Shown, 1,
1014                             'subtab1 onShow fired');
1015                         equals(window.subtab1Unhidden, 1,
1016                             'subtab1 onUnhide fired');
1017                         equals(window.subtab1Hidden, 0,
1018                             'subtab1 not hidden yet');
1019                         equals(window.subtab2Shown, 0,
1020                             'subtab2 not shown yet');
1021                         equals(window.subtab2Unhidden, 0,
1022                             'subtab2 not unhidden yet');
1023                         equals(window.subtab2Hidden, 0,
1024                             'subtab2 not hidden yet');
1025 
1026                         // switch to subtab2
1027                         target.find('a:contains(subtab2)').click();
1028                         target.find('.tabs').bind('tabsload', function(){
1029                             target.find('.tabs').unbind('tabsload');
1030                             setTimeout(function(){
1031                                 ok(true, 'tab loaded');
1032                                 
1033                                 equals(window.attributesShown, 1, 
1034                                     'unchanged');
1035                                 equals(window.attributesUnhidden, 1, 
1036                                     'unchanged');
1037                                 equals(window.attributesHidden, 1, 
1038                                     'unchanged');
1039                                 equals(window.reportHidden, 0, 
1040                                     'unchanged');
1041                                 equals(window.reportShown, 1, 
1042                                     'unchanged');
1043                                 equals(window.reportUnhidden, 1, 
1044                                     'unchanged');
1045                                 // subtabs    
1046                                 equals(window.subtab1Shown, 1,
1047                                     'unchanged');
1048                                 equals(window.subtab1Unhidden, 1,
1049                                     'unchanged');
1050                                 equals(window.subtab1Hidden, 1,
1051                                     'now hidden');
1052                                 equals(window.subtab2Shown, 1,
1053                                     'now shown');
1054                                 equals(window.subtab2Unhidden, 1,
1055                                     'onUnhide fired');
1056                                 equals(window.subtab2Hidden, 0,
1057                                     'subtab2 has not been hidden yet');
1058                                 
1059                                 // Now go back to subtab1
1060                                 target.find('a:contains(subtab1)').click();
1061                                 
1062                                 equals(window.attributesShown, 1, 
1063                                     'unchanged');
1064                                 equals(window.attributesUnhidden, 1, 
1065                                     'unchanged');
1066                                 equals(window.attributesHidden, 1, 
1067                                     'unchanged');
1068                                 equals(window.reportHidden, 0, 
1069                                     'unchanged');
1070                                 equals(window.reportShown, 1, 
1071                                     'unchanged');
1072                                 equals(window.reportUnhidden, 1, 
1073                                     'unchanged');
1074                                 // subtabs    
1075                                 equals(window.subtab1Shown, 1,
1076                                     'fires only once');
1077                                 equals(window.subtab1Unhidden, 2,
1078                                     'onUnhide should fire again');
1079                                 equals(window.subtab1Hidden, 1,
1080                                     'unchanged');
1081                                 equals(window.subtab2Shown, 1,
1082                                     'unchanged');
1083                                 equals(window.subtab2Unhidden, 1,
1084                                     'unchanged');
1085                                 equals(window.subtab2Hidden, 1,
1086                                     'now hidden');
1087                                 
1088                                 // change back to attributes
1089                                 target.find('a:contains(Information)')
1090                                     .click();
1091                                 
1092                                 equals(window.attributesShown, 1, 
1093                                     'fires only once');
1094                                 equals(window.attributesUnhidden, 2, 
1095                                     'fired again');
1096                                 equals(window.attributesHidden, 1, 
1097                                     'unchanged');
1098                                 equals(window.reportHidden, 1, 
1099                                     'now hidden');
1100                                 equals(window.reportShown, 1, 
1101                                     'unchanged');
1102                                 equals(window.reportUnhidden, 1, 
1103                                     'unchanged');
1104                                 // subtabs    
1105                                 equals(window.subtab1Shown, 1,
1106                                     'unchanged');
1107                                 equals(window.subtab1Unhidden, 2,
1108                                     'unchanged');
1109                                 equals(window.subtab1Hidden, 2,
1110                                     'hidden again');
1111                                 equals(window.subtab2Shown, 1,
1112                                     'unchanged');
1113                                 equals(window.subtab2Unhidden, 1,
1114                                     'unchanged');
1115                                 equals(window.subtab2Hidden, 1,
1116                                     'unchanged');
1117 
1118 
1119                                 // cleanup
1120                                 window.attributesShown      = 0;
1121                                 window.attributesUnhidden   = 0;
1122                                 window.attributesHidden     = 0;
1123                                 window.reportShown          = 0;
1124                                 window.reportUnhidden       = 0;
1125                                 window.reportHidden         = 0;
1126 
1127                                 window.subtab1Shown         = 0;
1128                                 window.subtab1Unhidden      = 0;
1129                                 window.subtab1Hidden        = 0;
1130                                 window.subtab2Shown         = 0;
1131                                 window.subtab2Unhidden      = 0;
1132                                 window.subtab2Hidden        = 0;
1133 
1134                                 $('#target').remove();
1135                                 start();
1136                                 
1137                             }, 100);
1138                         });                        
1139                     }, 100);                    
1140                 });
1141             },
1142             error: function(){
1143                 ok(false, 'Could not load url.');
1144                 $('#target').remove();
1145                 start();
1146             }
1147         });
1148         loader.load();        
1149     });
1150     
1151     asyncTest('beforeDestroy w/simple example', function(){
1152         $('#target').remove();
1153         var target = $('<div id="target"></div>');
1154         $(document.body).append(target);
1155         window.callbackFired = 0;
1156         window.selectedEl = undefined;
1157         var loader = madrona.contentLoader({
1158             url: '../media/common/js/test/layout/jsExample8.html',
1159             target: target,
1160             success: function(){
1161                 ok(true, 'content loaded.');
1162                 ok(target.find('.panel').length === 1, 
1163                     'content appended to target and success handler called.');
1164                 loader.destroy();
1165                 equals(window.callbackFired, 1, 'Callback was executed');
1166                 ok(window.selectedEl && window.selectedEl.length === 1, 
1167                     'Callback executed after content was added to document');
1168                 window.callbackFired = undefined;
1169                 window.selectedEl = undefined;
1170                 $('#target').remove();
1171                 start();
1172             },
1173             error: function(){
1174                 ok(false, 'Could not load url.');
1175                 $('#target').remove();
1176                 start();
1177             }
1178         });
1179         loader.load();
1180     });
1181     
1182     asyncTest('beforeDestroy specified by async tab', function(){
1183         $('#target').remove();
1184         var target = $('<div id="target"></div>');
1185         $(document.body).append(target);
1186         window.callbackFired = 0;
1187         var loader = madrona.contentLoader({
1188             url: '../media/common/js/test/layout/jsExample9.html',
1189             target: target,
1190             success: function(){
1191                 ok(true, 'content loaded.');
1192                 ok(target.find('.panel').length === 1, 
1193                     'content appended to target and success handler called.');
1194                 target.find('a:contains(Report)').click();
1195                 target.find('.tabs').bind('tabsload', function(){
1196                     target.find('.tabs').unbind('tabsload');
1197                     setTimeout(function(){
1198                         loader.destroy();
1199                         equals(window.callbackFired, 3, 
1200                             '3 Callbacks executed');
1201                         window.callbackFired = undefined;
1202                         $('#target').remove();
1203                         start();
1204                         
1205                     }, 100);
1206                 });
1207             },
1208             error: function(){
1209                 ok(false, 'Could not load url.');
1210                 $('#target').remove();
1211                 start();
1212             }
1213         });
1214         loader.load();
1215     });
1216         
1217     asyncTest('beforeDestroy defined in multiple nested tabs', function(){
1218         $('#target').remove();
1219         var target = $('<div id="target"></div>');
1220         $(document.body).append(target);
1221         window.callbackFired = 0;
1222         var loader = madrona.contentLoader({
1223             url: '../media/common/js/test/layout/jsExample10.html',
1224             target: target,
1225             success: function(){
1226                 ok(true, 'content loaded.');
1227                 ok(target.find('.panel').length === 1, 
1228                     'content appended to target and success handler called.');
1229                 target.find('a:contains(Report)').click();
1230                 target.find('.tabs').bind('tabsload', function(){
1231                     target.find('.tabs').unbind('tabsload');
1232                     setTimeout(function(){
1233                         target.find('.tabs').bind('tabsload', function(){
1234                             target.find('.tabs').unbind('tabsload');
1235                             setTimeout(function(){
1236                                 loader.destroy();
1237                                 equals(window.callbackFired, 4, 
1238                                     '4 Callbacks executed');
1239                                 $('#target').remove();
1240                                 start();
1241                             }, 100);
1242                         });
1243                         target.find('a:contains(subtab2)').click();
1244                     }, 40);
1245                 });
1246             },
1247             error: function(){
1248                 ok(false, 'Could not load url.');
1249                 $('#target').remove();
1250                 start();
1251             }
1252         });
1253         loader.load();
1254     });
1255     
1256     asyncTest('super combo callback test', function(){
1257         $('#target').remove();
1258         var target = $('<div id="target"></div>');
1259         $(document.body).append(target);
1260         
1261         // panel
1262         window.panelShow               = 0;
1263         window.panelUnhide             = 0;
1264         window.panelBeforeDestroy      = 0;
1265         // attributes tab
1266         window.attributesShow          = 0;
1267         window.attributesUnhide        = 0;
1268         window.attributesHide          = 0;
1269         // report tab
1270         window.reportShow              = 0;
1271         window.reportUnhide            = 0;
1272         window.reportHide              = 0;
1273         window.reportBeforeDestroy     = 0;
1274         // subtab1
1275         window.subtab1Show             = 0;
1276         window.subtab1Unhide           = 0;
1277         window.subtab1Hide             = 0;
1278         // subtab2
1279         window.subtab2Show             = 0;
1280         window.subtab2Unhide           = 0;
1281         window.subtab2Hide             = 0;
1282         window.subtab2BeforeDestroy    = 0;
1283         
1284         var loader = madrona.contentLoader({
1285             url: '../media/common/js/test/layout/jsExample11.html',
1286             target: target,
1287             success: function(){
1288                 ok(true, 'content loaded.');
1289                 ok(target.find('.panel').length === 1, 
1290                     'content appended to target and success handler called.');
1291                 
1292                 // initial state
1293                 // panel
1294                 equals(window.panelShow, 1,
1295                     "triggered");
1296                 equals(window.panelUnhide, 1,
1297                     "triggered");
1298                 equals(window.panelBeforeDestroy, 0,
1299                     "unchanged");
1300                 // attributes tab
1301                 equals(window.attributesShow, 1,
1302                     "triggered");
1303                 equals(window.attributesUnhide, 1,
1304                     "triggered");
1305                 equals(window.attributesHide, 0,
1306                     "unchanged");
1307                 // report tab
1308                 equals(window.reportShow, 0,
1309                     "unchanged");
1310                 equals(window.reportUnhide, 0,
1311                     "unchanged");
1312                 equals(window.reportHide, 0,
1313                     "unchanged");
1314                 equals(window.reportBeforeDestroy, 0,
1315                     "unchanged");
1316                 // subtab1
1317                 equals(window.subtab1Show, 0,
1318                     "unchanged");
1319                 equals(window.subtab1Unhide, 0,
1320                     "unchanged");
1321                 equals(window.subtab1Hide, 0,
1322                     "unchanged");
1323                 // subtab2
1324                 equals(window.subtab2Show, 0,
1325                     "unchanged");
1326                 equals(window.subtab2Unhide, 0,
1327                     "unchanged");
1328                 equals(window.subtab2Hide, 0,
1329                     "unchanged");
1330                 equals(window.subtab2BeforeDestroy, 0,
1331                     "unchanged");
1332                 
1333                 target.find('a:contains(Report)').click();
1334                 target.find('.tabs').bind('tabsload', function(){
1335                     target.find('.tabs').unbind('tabsload');
1336                     setTimeout(function(){
1337                         
1338                         ok(true, 'changed to report tab, subtab1 displayed');
1339                         
1340                         // panel
1341                         equals(window.panelShow, 1,
1342                             "unchanged");
1343                         equals(window.panelUnhide, 1,
1344                             "unchanged");
1345                         equals(window.panelBeforeDestroy, 0,
1346                             "unchanged");
1347                         // attributes tab
1348                         equals(window.attributesShow, 1,
1349                             "unchanged");
1350                         equals(window.attributesUnhide, 1,
1351                             "unchanged");
1352                         equals(window.attributesHide, 1,
1353                             "triggered");
1354                         // report tab
1355                         equals(window.reportShow, 1,
1356                             "triggered");
1357                         equals(window.reportUnhide, 1,
1358                             "triggered");
1359                         equals(window.reportHide, 0,
1360                             "unchanged");
1361                         equals(window.reportBeforeDestroy, 0,
1362                             "unchanged");
1363                         // subtab1
1364                         equals(window.subtab1Show, 1,
1365                             "triggered");
1366                         equals(window.subtab1Unhide, 1,
1367                             "triggered");
1368                         equals(window.subtab1Hide, 0,
1369                             "unchanged");
1370                         // subtab2
1371                         equals(window.subtab2Show, 0,
1372                             "unchanged");
1373                         equals(window.subtab2Unhide, 0,
1374                             "unchanged");
1375                         equals(window.subtab2Hide, 0,
1376                             "unchanged");
1377                         equals(window.subtab2BeforeDestroy, 0,
1378                             "unchanged");
1379 
1380                         // switch to subtab2
1381                         target.find('a:contains(subtab2)').click();
1382                         target.find('.tabs').bind('tabsload', function(){
1383                             target.find('.tabs').unbind('tabsload');
1384                             setTimeout(function(){
1385                                 ok(true, 'changed to report tab->subtab2');
1386 
1387                                 // panel
1388                                 equals(window.panelShow, 1,
1389                                     "unchanged");
1390                                 equals(window.panelUnhide, 1,
1391                                     "unchanged");
1392                                 equals(window.panelBeforeDestroy, 0,
1393                                     "unchanged");
1394                                 // attributes tab
1395                                 equals(window.attributesShow, 1,
1396                                     "unchanged");
1397                                 equals(window.attributesUnhide, 1,
1398                                     "unchanged");
1399                                 equals(window.attributesHide, 1,
1400                                     "unchanged");
1401                                 // report tab
1402                                 equals(window.reportShow, 1,
1403                                     "unchanged");
1404                                 equals(window.reportUnhide, 1,
1405                                     "unchanged");
1406                                 equals(window.reportHide, 0,
1407                                     "unchanged");
1408                                 equals(window.reportBeforeDestroy, 0,
1409                                     "unchanged");
1410                                 // subtab1
1411                                 equals(window.subtab1Show, 1,
1412                                     "unchanged");
1413                                 equals(window.subtab1Unhide, 1,
1414                                     "unchanged");
1415                                 equals(window.subtab1Hide, 1,
1416                                     "triggered");
1417                                 // subtab2
1418                                 equals(window.subtab2Show, 1,
1419                                     "triggered");
1420                                 equals(window.subtab2Unhide, 1,
1421                                     "triggered");
1422                                 equals(window.subtab2Hide, 0,
1423                                     "unchanged");
1424                                 equals(window.subtab2BeforeDestroy, 0,
1425                                     "unchanged");
1426                                     
1427                                 target.find('a:contains(subtab1)').click();
1428                                 // panel
1429                                 equals(window.panelShow, 1,
1430                                     "unchanged");
1431                                 equals(window.panelUnhide, 1,
1432                                     "unchanged");
1433                                 equals(window.panelBeforeDestroy, 0,
1434                                     "unchanged");
1435                                 // attributes tab
1436                                 equals(window.attributesShow, 1,
1437                                     "unchanged");
1438                                 equals(window.attributesUnhide, 1,
1439                                     "unchanged");
1440                                 equals(window.attributesHide, 1,
1441                                     "unchanged");
1442                                 // report tab
1443                                 equals(window.reportShow, 1,
1444                                     "unchanged");
1445                                 equals(window.reportUnhide, 1,
1446                                     "unchanged");
1447                                 equals(window.reportHide, 0,
1448                                     "unchanged");
1449                                 equals(window.reportBeforeDestroy, 0,
1450                                     "unchanged");
1451                                 // subtab1
1452                                 equals(window.subtab1Show, 1,
1453                                     "unchanged");
1454                                 equals(window.subtab1Unhide, 2,
1455                                     "triggered");
1456                                 equals(window.subtab1Hide, 1,
1457                                     "unchanged");
1458                                 // subtab2
1459                                 equals(window.subtab2Show, 1,
1460                                     "unchanged");
1461                                 equals(window.subtab2Unhide, 1,
1462                                     "unchanged");
1463                                 equals(window.subtab2Hide, 1,
1464                                     "triggered");
1465                                 equals(window.subtab2BeforeDestroy, 0,
1466                                     "unchanged");
1467 
1468                                 target.find('a:contains(subtab2)').click();
1469                                 // panel
1470                                 equals(window.panelShow, 1,
1471                                     "unchanged");
1472                                 equals(window.panelUnhide, 1,
1473                                     "unchanged");
1474                                 equals(window.panelBeforeDestroy, 0,
1475                                     "unchanged");
1476                                 // attributes tab
1477                                 equals(window.attributesShow, 1,
1478                                     "unchanged");
1479                                 equals(window.attributesUnhide, 1,
1480                                     "unchanged");
1481                                 equals(window.attributesHide, 1,
1482                                     "unchanged");
1483                                 // report tab
1484                                 equals(window.reportShow, 1,
1485                                     "unchanged");
1486                                 equals(window.reportUnhide, 1,
1487                                     "unchanged");
1488                                 equals(window.reportHide, 0,
1489                                     "unchanged");
1490                                 equals(window.reportBeforeDestroy, 0,
1491                                     "unchanged");
1492                                 // subtab1
1493                                 equals(window.subtab1Show, 1,
1494                                     "unchanged");
1495                                 equals(window.subtab1Unhide, 2,
1496                                     "unchanged");
1497                                 equals(window.subtab1Hide, 2,
1498                                     "triggered");
1499                                 // subtab2
1500                                 equals(window.subtab2Show, 1,
1501                                     "unchanged");
1502                                 equals(window.subtab2Unhide, 2,
1503                                     "triggered");
1504                                 equals(window.subtab2Hide, 1,
1505                                     "unchanged");
1506                                 equals(window.subtab2BeforeDestroy, 0,
1507                                     "unchanged");
1508 
1509                                 target.find('a:contains(Information)').click();
1510                                 // panel
1511                                 equals(window.panelShow, 1,
1512                                     "unchanged");
1513                                 equals(window.panelUnhide, 1,
1514                                     "unchanged");
1515                                 equals(window.panelBeforeDestroy, 0,
1516                                     "unchanged");
1517                                 // attributes tab
1518                                 equals(window.attributesShow, 1,
1519                                     "unchanged");
1520                                 equals(window.attributesUnhide, 2,
1521                                     "triggered");
1522                                 equals(window.attributesHide, 1,
1523                                     "unchanged");
1524                                 // report tab
1525                                 equals(window.reportShow, 1,
1526                                     "unchanged");
1527                                 equals(window.reportUnhide, 1,
1528                                     "unchanged");
1529                                 equals(window.reportHide, 1,
1530                                     "triggered");
1531                                 equals(window.reportBeforeDestroy, 0,
1532                                     "unchanged");
1533                                 // subtab1
1534                                 equals(window.subtab1Show, 1,
1535                                     "unchanged");
1536                                 equals(window.subtab1Unhide, 2,
1537                                     "unchanged");
1538                                 equals(window.subtab1Hide, 2,
1539                                     "unchanged");
1540                                 // subtab2
1541                                 equals(window.subtab2Show, 1,
1542                                     "unchanged");
1543                                 equals(window.subtab2Unhide, 2,
1544                                     "unchanged");
1545                                 equals(window.subtab2Hide, 2,
1546                                     "triggered");
1547                                 equals(window.subtab2BeforeDestroy, 0,
1548                                     "unchanged");
1549 
1550                                 target.find('a:contains(Report)').click();
1551                                 // panel
1552                                 equals(window.panelShow, 1,
1553                                     "unchanged");
1554                                 equals(window.panelUnhide, 1,
1555                                     "unchanged");
1556                                 equals(window.panelBeforeDestroy, 0,
1557                                     "unchanged");
1558                                 // attributes tab
1559                                 equals(window.attributesShow, 1,
1560                                     "unchanged");
1561                                 equals(window.attributesUnhide, 2,
1562                                     "unchanged");
1563                                 equals(window.attributesHide, 2,
1564                                     "triggered");
1565                                 // report tab
1566                                 equals(window.reportShow, 1,
1567                                     "unchanged");
1568                                 equals(window.reportUnhide, 2,
1569                                     "triggered");
1570                                 equals(window.reportHide, 1,
1571                                     "unchanged");
1572                                 equals(window.reportBeforeDestroy, 0,
1573                                     "unchanged");
1574                                 // subtab1
1575                                 equals(window.subtab1Show, 1,
1576                                     "unchanged");
1577                                 equals(window.subtab1Unhide, 2,
1578                                     "unchanged");
1579                                 equals(window.subtab1Hide, 2,
1580                                     "unchanged");
1581                                 // subtab2
1582                                 equals(window.subtab2Show, 1,
1583                                     "unchanged");
1584                                 equals(window.subtab2Unhide, 3,
1585                                     "triggered");
1586                                 equals(window.subtab2Hide, 2,
1587                                     "unchanged");
1588                                 equals(window.subtab2BeforeDestroy, 0,
1589                                     "unchanged");
1590                                     
1591                                 loader.destroy();
1592                                 
1593                                 // panel
1594                                 equals(window.panelShow, 1,
1595                                     "unchanged");
1596                                 equals(window.panelUnhide, 1,
1597                                     "unchanged");
1598                                 equals(window.panelBeforeDestroy, 1,
1599                                     "triggered");
1600                                 // attributes tab
1601                                 equals(window.attributesShow, 1,
1602                                     "unchanged");
1603                                 equals(window.attributesUnhide, 2,
1604                                     "unchanged");
1605                                 equals(window.attributesHide, 2,
1606                                     "unchanged");
1607                                 // report tab
1608                                 equals(window.reportShow, 1,
1609                                     "unchanged");
1610                                 equals(window.reportUnhide, 2,
1611                                     "unchanged");
1612                                 equals(window.reportHide, 1,
1613                                     "unchanged");
1614                                 equals(window.reportBeforeDestroy, 1,
1615                                     "triggered");
1616                                 // subtab1
1617                                 equals(window.subtab1Show, 1,
1618                                     "unchanged");
1619                                 equals(window.subtab1Unhide, 2,
1620                                     "unchanged");
1621                                 equals(window.subtab1Hide, 2,
1622                                     "unchanged");
1623                                 // subtab2
1624                                 equals(window.subtab2Show, 1,
1625                                     "unchanged");
1626                                 equals(window.subtab2Unhide, 3,
1627                                     "unchanged");
1628                                 equals(window.subtab2Hide, 2,
1629                                     "unchanged");
1630                                 equals(window.subtab2BeforeDestroy, 1,
1631                                     "triggered");
1632                                 
1633                                 // panel
1634                                 window.panelShow               = undefined;
1635                                 window.panelUnhide             = undefined;
1636                                 window.panelBeforeDestroy      = undefined;
1637                                 // attributes tab
1638                                 window.attributesShow          = undefined;
1639                                 window.attributesUnhide        = undefined;
1640                                 window.attributesHide          = undefined;
1641                                 // report tab
1642                                 window.reportShow              = undefined;
1643                                 window.reportUnhide            = undefined;
1644                                 window.reportHide              = undefined;
1645                                 window.reportBeforeDestroy     = undefined;
1646                                 // subtab1
1647                                 window.subtab1Show             = undefined;
1648                                 window.subtab1Unhide           = undefined;
1649                                 window.subtab1Hide             = undefined;
1650                                 // subtab2
1651                                 window.subtab2Show             = undefined;
1652                                 window.subtab2Unhide           = undefined;
1653                                 window.subtab2Hide             = undefined;
1654                                 window.subtab2BeforeDestroy    = undefined;
1655 
1656                                 $('#target').remove();
1657                                 start();
1658                             }, 100);
1659                         })                    
1660                         
1661                     }, 40);
1662                 });                
1663             },
1664             error: function(){
1665                 ok(false, 'Could not load url.');
1666                 $('#target').remove();
1667                 start();
1668             }
1669         });
1670         loader.load();
1671     });
1672     
1673     
1674     // Verfiy tab syncing
1675     // ==================
1676     
1677     asyncTest('super combo callback test, sync Report->subtab1', function(){
1678         $('#target').remove();
1679         var target = $('<div id="target"></div>');
1680         $(document.body).append(target);
1681         
1682         // panel
1683         window.panelShow               = 0;
1684         window.panelUnhide             = 0;
1685         window.panelBeforeDestroy      = 0;
1686         // attributes tab
1687         window.attributesShow          = 0;
1688         window.attributesUnhide        = 0;
1689         window.attributesHide          = 0;
1690         // report tab
1691         window.reportShow              = 0;
1692         window.reportUnhide            = 0;
1693         window.reportHide              = 0;
1694         window.reportBeforeDestroy     = 0;
1695         // subtab1
1696         window.subtab1Show             = 0;
1697         window.subtab1Unhide           = 0;
1698         window.subtab1Hide             = 0;
1699         // subtab2
1700         window.subtab2Show             = 0;
1701         window.subtab2Unhide           = 0;
1702         window.subtab2Hide             = 0;
1703         window.subtab2BeforeDestroy    = 0;
1704     
1705         window.subtab1Content = false;
1706         window.subtab2Content = false;
1707         
1708     
1709         var loader = madrona.contentLoader({
1710             url: '../media/common/js/test/layout/jsExample11.html',
1711             target: target,
1712             activeTabs: ['Report', 'subtab1'],
1713             success: function(){
1714                 ok(true, 'content loaded.');
1715                 ok(target.find('.panel').length > 0, 
1716                     'content appended to target and success handler called.');
1717                 
1718                 // initial state with synced tabs
1719                 // panel
1720                 equals(window.panelShow, 1,
1721                     "triggered");
1722                 equals(window.panelUnhide, 1,
1723                     "triggered");
1724                 equals(window.panelBeforeDestroy, 0,
1725                     "unchanged");
1726                 // attributes tab
1727                 equals(window.attributesShow, 0,
1728                     "unchanged");
1729                 equals(window.attributesUnhide, 0,
1730                     "unchanged");
1731                 equals(window.attributesHide, 0,
1732                     "unchanged");
1733                 // report tab
1734                 equals(window.reportShow, 1,
1735                     "triggered");
1736                 equals(window.reportUnhide, 1,
1737                     "triggered");
1738                 equals(window.reportHide, 0,
1739                     "unchanged");
1740                 equals(window.reportBeforeDestroy, 0,
1741                     "unchanged");
1742                 // subtab1
1743                 equals(window.subtab1Show, 1,
1744                     "triggered");
1745                 equals(window.subtab1Unhide, 1,
1746                     "triggered");
1747                 equals(window.subtab1Hide, 0,
1748                     "unchanged");
1749                 // subtab2
1750                 equals(window.subtab2Show, 0,
1751                     "unchanged");
1752                 equals(window.subtab2Unhide, 0,
1753                     "unchanged");
1754                 equals(window.subtab2Hide, 0,
1755                     "unchanged");
1756                 equals(window.subtab2BeforeDestroy, 0,
1757                     "unchanged");
1758                 
1759                 ok(window.subtab1Content && window.subtab1Content.length,
1760                     "event triggered only after content added to document");
1761 
1762                 // change back to information tab
1763                 target.find('a:contains(Information)').click();
1764                 
1765                 // panel
1766                 equals(window.panelShow, 1,
1767                     "unchanged");
1768                 equals(window.panelUnhide, 1,
1769                     "unchanged");
1770                 equals(window.panelBeforeDestroy, 0,
1771                     "unchanged");
1772                 // attributes tab
1773                 equals(window.attributesShow, 1,
1774                     "triggered");
1775                 equals(window.attributesUnhide, 1,
1776                     "triggered");
1777                 equals(window.attributesHide, 0,
1778                     "unchanged");
1779                 // report tab
1780                 equals(window.reportShow, 1,
1781                     "unchanged");
1782                 equals(window.reportUnhide, 1,
1783                     "unchanged");
1784                 equals(window.reportHide, 1,
1785                     "triggered");
1786                 equals(window.reportBeforeDestroy, 0,
1787                     "unchanged");
1788                 // subtab1
1789                 equals(window.subtab1Show, 1,
1790                     "unchanged");
1791                 equals(window.subtab1Unhide, 1,
1792                     "unchanged");
1793                 equals(window.subtab1Hide, 1,
1794                     "triggered");
1795                 // subtab2
1796                 equals(window.subtab2Show, 0,
1797                     "unchanged");
1798                 equals(window.subtab2Unhide, 0,
1799                     "unchanged");
1800                 equals(window.subtab2Hide, 0,
1801                     "unchanged");
1802                 equals(window.subtab2BeforeDestroy, 0,
1803                     "unchanged");
1804                     
1805                 // change back to report->subtab1
1806                 target.find('a:contains(Report)').click();
1807 
1808                 // panel
1809                 equals(window.panelShow, 1,
1810                     "unchanged");
1811                 equals(window.panelUnhide, 1,
1812                     "unchanged");
1813                 equals(window.panelBeforeDestroy, 0,
1814                     "unchanged");
1815                 // attributes tab
1816                 equals(window.attributesShow, 1,
1817                     "unchanged");
1818                 equals(window.attributesUnhide, 1,
1819                     "unchanged");
1820                 equals(window.attributesHide, 1,
1821                     "triggered");
1822                 // report tab
1823                 equals(window.reportShow, 1,
1824                     "unchanged");
1825                 equals(window.reportUnhide, 2,
1826                     "triggered");
1827                 equals(window.reportHide, 1,
1828                     "unchanged");
1829                 equals(window.reportBeforeDestroy, 0,
1830                     "unchanged");
1831                 // subtab1
1832                 equals(window.subtab1Show, 1,
1833                     "unchanged");
1834                 equals(window.subtab1Unhide, 2,
1835                     "triggered");
1836                 equals(window.subtab1Hide, 1,
1837                     "unchanged");
1838                 // subtab2
1839                 equals(window.subtab2Show, 0,
1840                     "unchanged");
1841                 equals(window.subtab2Unhide, 0,
1842                     "unchanged");
1843                 equals(window.subtab2Hide, 0,
1844                     "unchanged");
1845                 equals(window.subtab2BeforeDestroy, 0,
1846                     "unchanged");
1847 
1848                 // switch to subtab2
1849                 target.find('a:contains(subtab2)').click();
1850                 target.find('.tabs').bind('tabsload', function(){
1851                     target.find('.tabs').unbind('tabsload');
1852                     setTimeout(function(){
1853                         ok(true, 'changed to report tab->subtab2');
1854 
1855                         // panel
1856                         equals(window.panelShow, 1,
1857                             "unchanged");
1858                         equals(window.panelUnhide, 1,
1859                             "unchanged");
1860                         equals(window.panelBeforeDestroy, 0,
1861                             "unchanged");
1862                         // attributes tab
1863                         equals(window.attributesShow, 1,
1864                             "unchanged");
1865                         equals(window.attributesUnhide, 1,
1866                             "unchanged");
1867                         equals(window.attributesHide, 1,
1868                             "unchanged");
1869                         // report tab
1870                         equals(window.reportShow, 1,
1871                             "unchanged");
1872                         equals(window.reportUnhide, 2,
1873                             "unchanged");
1874                         equals(window.reportHide, 1,
1875                             "unchanged");
1876                         equals(window.reportBeforeDestroy, 0,
1877                             "unchanged");
1878                         // subtab1
1879                         equals(window.subtab1Show, 1,
1880                             "unchanged");
1881                         equals(window.subtab1Unhide, 2,
1882                             "unchanged");
1883                         equals(window.subtab1Hide, 2,
1884                             "triggered");
1885                         // subtab2
1886                         equals(window.subtab2Show, 1,
1887                             "triggered");
1888                         equals(window.subtab2Unhide, 1,
1889                             "triggered");
1890                         equals(window.subtab2Hide, 0,
1891                             "unchanged");
1892                         equals(window.subtab2BeforeDestroy, 0,
1893                             "unchanged");
1894                             
1895                         ok(window.subtab2Content && window.subtab2Content.length,
1896                             "event triggered only after content added to document");
1897                     
1898                         
1899                         loader.destroy();
1900                         // panel
1901                         equals(window.panelShow, 1,
1902                             "unchanged");
1903                         equals(window.panelUnhide, 1,
1904                             "unchanged");
1905                         equals(window.panelBeforeDestroy, 1,
1906                             "triggered");
1907                         // attributes tab
1908                         equals(window.attributesShow, 1,
1909                             "unchanged");
1910                         equals(window.attributesUnhide, 1,
1911                             "unchanged");
1912                         equals(window.attributesHide, 1,
1913                             "unchanged");
1914                         // report tab
1915                         equals(window.reportShow, 1,
1916                             "unchanged");
1917                         equals(window.reportUnhide, 2,
1918                             "unchanged");
1919                         equals(window.reportHide, 1,
1920                             "unchanged");
1921                         equals(window.reportBeforeDestroy, 1,
1922                             "triggered");
1923                         // subtab1
1924                         equals(window.subtab1Show, 1,
1925                             "unchanged");
1926                         equals(window.subtab1Unhide, 2,
1927                             "unchanged");
1928                         equals(window.subtab1Hide, 2,
1929                             "unchanged");
1930                         // subtab2
1931                         equals(window.subtab2Show, 1,
1932                             "unchanged");
1933                         equals(window.subtab2Unhide, 1,
1934                             "unchanged");
1935                         equals(window.subtab2Hide, 0,
1936                             "unchanged");
1937                         equals(window.subtab2BeforeDestroy, 1,
1938                             "triggered");
1939 
1940                         // cleanup
1941                         // panel
1942                         window.panelShow               = undefined;
1943                         window.panelUnhide             = undefined;
1944                         window.panelBeforeDestroy      = undefined;
1945                         // attributes tab
1946                         window.attributesShow          = undefined;
1947                         window.attributesUnhide        = undefined;
1948                         window.attributesHide          = undefined;
1949                         // report tab
1950                         window.reportShow              = undefined;
1951                         window.reportUnhide            = undefined;
1952                         window.reportHide              = undefined;
1953                         window.reportBeforeDestroy     = undefined;
1954                         // subtab1
1955                         window.subtab1Show             = undefined;
1956                         window.subtab1Unhide           = undefined;
1957                         window.subtab1Hide             = undefined;
1958                         // subtab2
1959                         window.subtab2Show             = undefined;
1960                         window.subtab2Unhide           = undefined;
1961                         window.subtab2Hide             = undefined;
1962                         window.subtab2BeforeDestroy    = undefined;
1963 
1964                         $('#target').remove();
1965                         start();
1966                         
1967                     }, 100);
1968                 });    
1969             },
1970             error: function(){
1971                 ok(false, 'Could not load url.');
1972                 $('#target').remove();
1973                 start();
1974             }
1975         });
1976         loader.load();
1977     });
1978     
1979     asyncTest('super combo callback test, sync Report->subtab2', function(){
1980         $('#target').remove();
1981         var target = $('<div id="target"></div>');
1982         $(document.body).append(target);
1983         
1984         // panel
1985         window.panelShow               = 0;
1986         window.panelUnhide             = 0;
1987         window.panelBeforeDestroy      = 0;
1988         // attributes tab
1989         window.attributesShow          = 0;
1990         window.attributesUnhide        = 0;
1991         window.attributesHide          = 0;
1992         // report tab
1993         window.reportShow              = 0;
1994         window.reportUnhide            = 0;
1995         window.reportHide              = 0;
1996         window.reportBeforeDestroy     = 0;
1997         // subtab1
1998         window.subtab1Show             = 0;
1999         window.subtab1Unhide           = 0;
2000         window.subtab1Hide             = 0;
2001         // subtab2
2002         window.subtab2Show             = 0;
2003         window.subtab2Unhide           = 0;
2004         window.subtab2Hide             = 0;
2005         window.subtab2BeforeDestroy    = 0;
2006     
2007         var loader = madrona.contentLoader({
2008             url: '../media/common/js/test/layout/jsExample11.html',
2009             target: target,
2010             activeTabs: ['Report', 'subtab2'],
2011             success: function(){
2012                 ok(true, 'content loaded.');
2013                 ok(target.find('.panel').length > 0, 
2014                     'content appended to target and success handler called.');
2015                 
2016                 // initial state with synced tabs
2017                 // panel
2018                 equals(window.panelShow, 1,
2019                     "triggered");
2020                 equals(window.panelUnhide, 1,
2021                     "triggered");
2022                 equals(window.panelBeforeDestroy, 0,
2023                     "unchanged");
2024                 // attributes tab
2025                 equals(window.attributesShow, 0,
2026                     "unchanged");
2027                 equals(window.attributesUnhide, 0,
2028                     "unchanged");
2029                 equals(window.attributesHide, 0,
2030                     "unchanged");
2031                 // report tab
2032                 equals(window.reportShow, 1,
2033                     "triggered");
2034                 equals(window.reportUnhide, 1,
2035                     "triggered");
2036                 equals(window.reportHide, 0,
2037                     "unchanged");
2038                 equals(window.reportBeforeDestroy, 0,
2039                     "unchanged");
2040                 // subtab1
2041                 equals(window.subtab1Show, 0,
2042                     "unchanged");
2043                 equals(window.subtab1Unhide, 0,
2044                     "unchanged");
2045                 equals(window.subtab1Hide, 0,
2046                     "unchanged");
2047                 // subtab2
2048                 equals(window.subtab2Show, 1,
2049                     "triggered");
2050                 equals(window.subtab2Unhide, 1,
2051                     "triggered");
2052                 equals(window.subtab2Hide, 0,
2053                     "unchanged");
2054                 equals(window.subtab2BeforeDestroy, 0,
2055                     "unchanged");
2056                 
2057                 ok(window.subtab2Content && window.subtab2Content.length,
2058                     "event triggered only after content added to document");
2059             
2060 
2061                 // change to information tab
2062                 target.find('a:contains(Information)').click();
2063                 
2064                 // panel
2065                 equals(window.panelShow, 1,
2066                     "unchanged");
2067                 equals(window.panelUnhide, 1,
2068                     "unchanged");
2069                 equals(window.panelBeforeDestroy, 0,
2070                     "unchanged");
2071                 // attributes tab
2072                 equals(window.attributesShow, 1,
2073                     "triggered");
2074                 equals(window.attributesUnhide, 1,
2075                     "triggered");
2076                 equals(window.attributesHide, 0,
2077                     "unchanged");
2078                 // report tab
2079                 equals(window.reportShow, 1,
2080                     "unchanged");
2081                 equals(window.reportUnhide, 1,
2082                     "unchanged");
2083                 equals(window.reportHide, 1,
2084                     "triggered");
2085                 equals(window.reportBeforeDestroy, 0,
2086                     "unchanged");
2087                 // subtab1
2088                 equals(window.subtab1Show, 0,
2089                     "unchanged");
2090                 equals(window.subtab1Unhide, 0,
2091                     "unchanged");
2092                 equals(window.subtab1Hide, 0,
2093                     "unchanged");
2094                 // subtab2
2095                 equals(window.subtab2Show, 1,
2096                     "unchanged");
2097                 equals(window.subtab2Unhide, 1,
2098                     "unchanged");
2099                 equals(window.subtab2Hide, 1,
2100                     "triggered");
2101                 equals(window.subtab2BeforeDestroy, 0,
2102                     "unchanged");                 
2103 
2104                 // change back to report->subtab2 tab
2105                 target.find('a:contains(Report)').click();
2106 
2107                 // panel
2108                 equals(window.panelShow, 1,
2109                     "unchanged");
2110                 equals(window.panelUnhide, 1,
2111                     "unchanged");
2112                 equals(window.panelBeforeDestroy, 0,
2113                     "unchanged");
2114                 // attributes tab
2115                 equals(window.attributesShow, 1,
2116                     "unchanged");
2117                 equals(window.attributesUnhide, 1,
2118                     "unchanged");
2119                 equals(window.attributesHide, 1,
2120                     "triggered");
2121                 // report tab
2122                 equals(window.reportShow, 1,
2123                     "unchanged");
2124                 equals(window.reportUnhide, 2,
2125                     "triggered");
2126                 equals(window.reportHide, 1,
2127                     "unchanged");
2128                 equals(window.reportBeforeDestroy, 0,
2129                     "unchanged");
2130                 // subtab1
2131                 equals(window.subtab1Show, 0,
2132                     "unchanged");
2133                 equals(window.subtab1Unhide, 0,
2134                     "unchanged");
2135                 equals(window.subtab1Hide, 0,
2136                     "unchanged");
2137                 // subtab2
2138                 equals(window.subtab2Show, 1,
2139                     "unchanged");
2140                 equals(window.subtab2Unhide, 2,
2141                     "triggered");
2142                 equals(window.subtab2Hide, 1,
2143                     "triggered");
2144                 equals(window.subtab2BeforeDestroy, 0,
2145                     "unchanged");                 
2146 
2147                 // change back to report->subtab1 tab
2148                 target.find('a:contains(subtab1)').click();
2149 
2150                 // panel
2151                 equals(window.panelShow, 1,
2152                     "unchanged");
2153                 equals(window.panelUnhide, 1,
2154                     "unchanged");
2155                 equals(window.panelBeforeDestroy, 0,
2156                     "unchanged");
2157                 // attributes tab
2158                 equals(window.attributesShow, 1,
2159                     "unchanged");
2160                 equals(window.attributesUnhide, 1,
2161                     "unchanged");
2162                 equals(window.attributesHide, 1,
2163                     "unchanged");
2164                 // report tab
2165                 equals(window.reportShow, 1,
2166                     "unchanged");
2167                 equals(window.reportUnhide, 2,
2168                     "unchanged");
2169                 equals(window.reportHide, 1,
2170                     "unchanged");
2171                 equals(window.reportBeforeDestroy, 0,
2172                     "unchanged");
2173                 // subtab1
2174                 equals(window.subtab1Show, 1,
2175                     "triggered");
2176                 equals(window.subtab1Unhide, 1,
2177                     "triggered");
2178                 equals(window.subtab1Hide, 0,
2179                     "unchanged");
2180                 // subtab2
2181                 equals(window.subtab2Show, 1,
2182                     "unchanged");
2183                 equals(window.subtab2Unhide, 2,
2184                     "unchanged");
2185                 equals(window.subtab2Hide, 2,
2186                     "triggered");
2187                 equals(window.subtab2BeforeDestroy, 0,
2188                     "unchanged");                 
2189 
2190                     
2191                 loader.destroy();
2192                 // panel
2193                 equals(window.panelShow, 1,
2194                     "unchanged");
2195                 equals(window.panelUnhide, 1,
2196                     "unchanged");
2197                 equals(window.panelBeforeDestroy, 1,
2198                     "triggered");
2199                 // attributes tab
2200                 equals(window.attributesShow, 1,
2201                     "unchanged");
2202                 equals(window.attributesUnhide, 1,
2203                     "unchanged");
2204                 equals(window.attributesHide, 1,
2205                     "unchanged");
2206                 // report tab
2207                 equals(window.reportShow, 1,
2208                     "unchanged");
2209                 equals(window.reportUnhide, 2,
2210                     "unchanged");
2211                 equals(window.reportHide, 1,
2212                     "unchanged");
2213                 equals(window.reportBeforeDestroy, 1,
2214                     "triggered");
2215                 // subtab1
2216                 equals(window.subtab1Show, 1,
2217                     "unchanged");
2218                 equals(window.subtab1Unhide, 1,
2219                     "unchanged");
2220                 equals(window.subtab1Hide, 0,
2221                     "unchanged");
2222                 // subtab2
2223                 equals(window.subtab2Show, 1,
2224                     "unchanged");
2225                 equals(window.subtab2Unhide, 2,
2226                     "unchanged");
2227                 equals(window.subtab2Hide, 2,
2228                     "unchanged");
2229                 equals(window.subtab2BeforeDestroy, 1,
2230                     "triggered");
2231                     
2232                 // cleanup
2233                 // panel
2234                 window.panelShow               = undefined;
2235                 window.panelUnhide             = undefined;
2236                 window.panelBeforeDestroy      = undefined;
2237                 // attributes tab
2238                 window.attributesShow          = undefined;
2239                 window.attributesUnhide        = undefined;
2240                 window.attributesHide          = undefined;
2241                 // report tab
2242                 window.reportShow              = undefined;
2243                 window.reportUnhide            = undefined;
2244                 window.reportHide              = undefined;
2245                 window.reportBeforeDestroy     = undefined;
2246                 // subtab1
2247                 window.subtab1Show             = undefined;
2248                 window.subtab1Unhide           = undefined;
2249                 window.subtab1Hide             = undefined;
2250                 // subtab2
2251                 window.subtab2Show             = undefined;
2252                 window.subtab2Unhide           = undefined;
2253                 window.subtab2Hide             = undefined;
2254                 window.subtab2BeforeDestroy    = undefined;
2255 
2256                 $('#target').remove();
2257                 start();
2258             },
2259             error: function(){
2260                 ok(false, 'Could not load url.');
2261                 $('#target').remove();
2262                 start();
2263             }
2264         });
2265         loader.load();
2266     });
2267     
2268     // Other options
2269     // =============
2270     
2271     asyncTest('behaviors option is executed', function(){
2272         window.behaviorsRan = false;
2273         var target = $('<div id="target"></div>');
2274         $(document.body).append(target);
2275         var loader = madrona.contentLoader({
2276             url: '../media/common/js/test/layout/example1.html',
2277             target: target,
2278             behaviors: function(staging){
2279                 if($(staging).length > 0){
2280                     window.behaviorsRan = true;
2281                 }
2282             },
2283             success: function(){
2284                 ok(true, 'content loaded.');
2285                 ok(target.find('.panel').length === 1, 
2286                     'content appended to target and success handler called.');
2287                 ok(window.behaviorsRan);
2288                 $('#target').remove();
2289                 start();
2290             },
2291             error: function(){
2292                 ok(false, 'Could not load url.');
2293                 $('#target').remove();
2294                 start();
2295             }
2296         });
2297         loader.load();        
2298     });
2299     
2300     module('panel');
2301     
2302     if(!madrona.options){
2303         madrona.options = {};
2304     }
2305     
2306     test('initializes', function(){
2307         var panel = madrona.panel({});
2308         ok(panel.getEl());
2309         panel.destroy();
2310     });
2311         
2312 })();