Made sure that .removeClass(null) doesn't throw an exception. Fixes #3847.
[jquery.git] / src / core.js
1 var 
2         // Will speed up references to window, and allows munging its name.
3         window = this,
4         // Will speed up references to undefined, and allows munging its name.
5         undefined,
6         // Map over jQuery in case of overwrite
7         _jQuery = window.jQuery,
8         // Map over the $ in case of overwrite
9         _$ = window.$,
10
11         jQuery = window.jQuery = window.$ = function( selector, context ) {
12                 // The jQuery object is actually just the init constructor 'enhanced'
13                 return new jQuery.fn.init( selector, context );
14         },
15
16         // A simple way to check for HTML strings or ID strings
17         // (both of which we optimize for)
18         quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
19         // Is it a simple selector
20         isSimple = /^.[^:#\[\.,]*$/;
21
22 jQuery.fn = jQuery.prototype = {
23         init: function( selector, context ) {
24                 // Make sure that a selection was provided
25                 selector = selector || document;
26
27                 // Handle $(DOMElement)
28                 if ( selector.nodeType ) {
29                         this[0] = selector;
30                         this.length = 1;
31                         this.context = selector;
32                         return this;
33                 }
34                 // Handle HTML strings
35                 if ( typeof selector === "string" ) {
36                         // Are we dealing with HTML string or an ID?
37                         var match = quickExpr.exec( selector );
38
39                         // Verify a match, and that no context was specified for #id
40                         if ( match && (match[1] || !context) ) {
41
42                                 // HANDLE: $(html) -> $(array)
43                                 if ( match[1] )
44                                         selector = jQuery.clean( [ match[1] ], context );
45
46                                 // HANDLE: $("#id")
47                                 else {
48                                         var elem = document.getElementById( match[3] );
49
50                                         // Handle the case where IE and Opera return items
51                                         // by name instead of ID
52                                         if ( elem && elem.id != match[3] )
53                                                 return jQuery().find( selector );
54
55                                         // Otherwise, we inject the element directly into the jQuery object
56                                         var ret = jQuery( elem || [] );
57                                         ret.context = document;
58                                         ret.selector = selector;
59                                         return ret;
60                                 }
61
62                         // HANDLE: $(expr, [context])
63                         // (which is just equivalent to: $(content).find(expr)
64                         } else
65                                 return jQuery( context ).find( selector );
66
67                 // HANDLE: $(function)
68                 // Shortcut for document ready
69                 } else if ( jQuery.isFunction( selector ) )
70                         return jQuery( document ).ready( selector );
71
72                 // Make sure that old selector state is passed along
73                 if ( selector.selector && selector.context ) {
74                         this.selector = selector.selector;
75                         this.context = selector.context;
76                 }
77
78                 return this.setArray(jQuery.makeArray(selector));
79         },
80
81         // Start with an empty selector
82         selector: "",
83
84         // The current version of jQuery being used
85         jquery: "@VERSION",
86
87         // The number of elements contained in the matched element set
88         size: function() {
89                 return this.length;
90         },
91
92         // Get the Nth element in the matched element set OR
93         // Get the whole matched element set as a clean array
94         get: function( num ) {
95                 return num === undefined ?
96
97                         // Return a 'clean' array
98                         jQuery.makeArray( this ) :
99
100                         // Return just the object
101                         this[ num ];
102         },
103
104         // Take an array of elements and push it onto the stack
105         // (returning the new matched element set)
106         pushStack: function( elems, name, selector ) {
107                 // Build a new jQuery matched element set
108                 var ret = jQuery( elems );
109
110                 // Add the old object onto the stack (as a reference)
111                 ret.prevObject = this;
112
113                 ret.context = this.context;
114
115                 if ( name === "find" )
116                         ret.selector = this.selector + (this.selector ? " " : "") + selector;
117                 else if ( name )
118                         ret.selector = this.selector + "." + name + "(" + selector + ")";
119
120                 // Return the newly-formed element set
121                 return ret;
122         },
123
124         // Force the current matched set of elements to become
125         // the specified array of elements (destroying the stack in the process)
126         // You should use pushStack() in order to do this, but maintain the stack
127         setArray: function( elems ) {
128                 // Resetting the length to 0, then using the native Array push
129                 // is a super-fast way to populate an object with array-like properties
130                 this.length = 0;
131                 Array.prototype.push.apply( this, elems );
132
133                 return this;
134         },
135
136         // Execute a callback for every element in the matched set.
137         // (You can seed the arguments with an array of args, but this is
138         // only used internally.)
139         each: function( callback, args ) {
140                 return jQuery.each( this, callback, args );
141         },
142
143         // Determine the position of an element within
144         // the matched set of elements
145         index: function( elem ) {
146                 // Locate the position of the desired element
147                 return jQuery.inArray(
148                         // If it receives a jQuery object, the first element is used
149                         elem && elem.jquery ? elem[0] : elem
150                 , this );
151         },
152
153         attr: function( name, value, type ) {
154                 var options = name;
155
156                 // Look for the case where we're accessing a style value
157                 if ( typeof name === "string" )
158                         if ( value === undefined )
159                                 return this[0] && jQuery[ type || "attr" ]( this[0], name );
160
161                         else {
162                                 options = {};
163                                 options[ name ] = value;
164                         }
165
166                 // Check to see if we're setting style values
167                 return this.each(function(i){
168                         // Set all the styles
169                         for ( name in options )
170                                 jQuery.attr(
171                                         type ?
172                                                 this.style :
173                                                 this,
174                                         name, jQuery.prop( this, options[ name ], type, i, name )
175                                 );
176                 });
177         },
178
179         css: function( key, value ) {
180                 // ignore negative width and height values
181                 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
182                         value = undefined;
183                 return this.attr( key, value, "curCSS" );
184         },
185
186         text: function( text ) {
187                 if ( typeof text !== "object" && text != null )
188                         return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
189
190                 var ret = "";
191
192                 jQuery.each( text || this, function(){
193                         jQuery.each( this.childNodes, function(){
194                                 if ( this.nodeType != 8 )
195                                         ret += this.nodeType != 1 ?
196                                                 this.nodeValue :
197                                                 jQuery.fn.text( [ this ] );
198                         });
199                 });
200
201                 return ret;
202         },
203
204         wrapAll: function( html ) {
205                 if ( this[0] ) {
206                         // The elements to wrap the target around
207                         var wrap = jQuery( html, this[0].ownerDocument ).clone();
208
209                         if ( this[0].parentNode )
210                                 wrap.insertBefore( this[0] );
211
212                         wrap.map(function(){
213                                 var elem = this;
214
215                                 while ( elem.firstChild )
216                                         elem = elem.firstChild;
217
218                                 return elem;
219                         }).append(this);
220                 }
221
222                 return this;
223         },
224
225         wrapInner: function( html ) {
226                 return this.each(function(){
227                         jQuery( this ).contents().wrapAll( html );
228                 });
229         },
230
231         wrap: function( html ) {
232                 return this.each(function(){
233                         jQuery( this ).wrapAll( html );
234                 });
235         },
236
237         append: function() {
238                 return this.domManip(arguments, true, function(elem){
239                         if (this.nodeType == 1)
240                                 this.appendChild( elem );
241                 });
242         },
243
244         prepend: function() {
245                 return this.domManip(arguments, true, function(elem){
246                         if (this.nodeType == 1)
247                                 this.insertBefore( elem, this.firstChild );
248                 });
249         },
250
251         before: function() {
252                 return this.domManip(arguments, false, function(elem){
253                         this.parentNode.insertBefore( elem, this );
254                 });
255         },
256
257         after: function() {
258                 return this.domManip(arguments, false, function(elem){
259                         this.parentNode.insertBefore( elem, this.nextSibling );
260                 });
261         },
262
263         end: function() {
264                 return this.prevObject || jQuery( [] );
265         },
266
267         // For internal use only.
268         // Behaves like an Array's .push method, not like a jQuery method.
269         push: [].push,
270
271         find: function( selector ) {
272                 if ( this.length === 1 && !/,/.test(selector) ) {
273                         var ret = this.pushStack( [], "find", selector );
274                         ret.length = 0;
275                         jQuery.find( selector, this[0], ret );
276                         return ret;
277                 } else {
278                         var elems = jQuery.map(this, function(elem){
279                                 return jQuery.find( selector, elem );
280                         });
281
282                         return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
283                                 jQuery.unique( elems ) :
284                                 elems, "find", selector );
285                 }
286         },
287
288         clone: function( events ) {
289                 // Do the clone
290                 var ret = this.map(function(){
291                         if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
292                                 // IE copies events bound via attachEvent when
293                                 // using cloneNode. Calling detachEvent on the
294                                 // clone will also remove the events from the orignal
295                                 // In order to get around this, we use innerHTML.
296                                 // Unfortunately, this means some modifications to
297                                 // attributes in IE that are actually only stored
298                                 // as properties will not be copied (such as the
299                                 // the name attribute on an input).
300                                 var clone = this.cloneNode(true),
301                                         container = document.createElement("div");
302                                 container.appendChild(clone);
303                                 return jQuery.clean([container.innerHTML])[0];
304                         } else
305                                 return this.cloneNode(true);
306                 });
307
308                 // Need to set the expando to null on the cloned set if it exists
309                 // removeData doesn't work here, IE removes it from the original as well
310                 // this is primarily for IE but the data expando shouldn't be copied over in any browser
311                 var clone = ret.find("*").andSelf().each(function(){
312                         if ( this[ expando ] !== undefined )
313                                 this[ expando ] = null;
314                 });
315
316                 // Copy the events from the original to the clone
317                 if ( events === true )
318                         this.find("*").andSelf().each(function(i){
319                                 if (this.nodeType == 3)
320                                         return;
321                                 var events = jQuery.data( this, "events" );
322
323                                 for ( var type in events )
324                                         for ( var handler in events[ type ] )
325                                                 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
326                         });
327
328                 // Return the cloned set
329                 return ret;
330         },
331
332         filter: function( selector ) {
333                 return this.pushStack(
334                         jQuery.isFunction( selector ) &&
335                         jQuery.grep(this, function(elem, i){
336                                 return selector.call( elem, i );
337                         }) ||
338
339                         jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
340                                 return elem.nodeType === 1;
341                         }) ), "filter", selector );
342         },
343
344         closest: function( selector ) {
345                 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null;
346
347                 return this.map(function(){
348                         var cur = this;
349                         while ( cur && cur.ownerDocument ) {
350                                 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) )
351                                         return cur;
352                                 cur = cur.parentNode;
353                         }
354                 });
355         },
356
357         not: function( selector ) {
358                 if ( typeof selector === "string" )
359                         // test special case where just one selector is passed in
360                         if ( isSimple.test( selector ) )
361                                 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
362                         else
363                                 selector = jQuery.multiFilter( selector, this );
364
365                 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
366                 return this.filter(function() {
367                         return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
368                 });
369         },
370
371         add: function( selector ) {
372                 return this.pushStack( jQuery.unique( jQuery.merge(
373                         this.get(),
374                         typeof selector === "string" ?
375                                 jQuery( selector ) :
376                                 jQuery.makeArray( selector )
377                 )));
378         },
379
380         is: function( selector ) {
381                 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
382         },
383
384         hasClass: function( selector ) {
385                 return !!selector && this.is( "." + selector );
386         },
387
388         val: function( value ) {
389                 if ( value === undefined ) {                    
390                         var elem = this[0];
391
392                         if ( elem ) {
393                                 if( jQuery.nodeName( elem, 'option' ) )
394                                         return (elem.attributes.value || {}).specified ? elem.value : elem.text;
395                                 
396                                 // We need to handle select boxes special
397                                 if ( jQuery.nodeName( elem, "select" ) ) {
398                                         var index = elem.selectedIndex,
399                                                 values = [],
400                                                 options = elem.options,
401                                                 one = elem.type == "select-one";
402
403                                         // Nothing was selected
404                                         if ( index < 0 )
405                                                 return null;
406
407                                         // Loop through all the selected options
408                                         for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
409                                                 var option = options[ i ];
410
411                                                 if ( option.selected ) {
412                                                         // Get the specifc value for the option
413                                                         value = jQuery(option).val();
414
415                                                         // We don't need an array for one selects
416                                                         if ( one )
417                                                                 return value;
418
419                                                         // Multi-Selects return an array
420                                                         values.push( value );
421                                                 }
422                                         }
423
424                                         return values;                          
425                                 }
426
427                                 // Everything else, we just grab the value
428                                 return (elem.value || "").replace(/\r/g, "");
429
430                         }
431
432                         return undefined;
433                 }
434
435                 if ( typeof value === "number" )
436                         value += '';
437
438                 return this.each(function(){
439                         if ( this.nodeType != 1 )
440                                 return;
441
442                         if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
443                                 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
444                                         jQuery.inArray(this.name, value) >= 0);
445
446                         else if ( jQuery.nodeName( this, "select" ) ) {
447                                 var values = jQuery.makeArray(value);
448
449                                 jQuery( "option", this ).each(function(){
450                                         this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
451                                                 jQuery.inArray( this.text, values ) >= 0);
452                                 });
453
454                                 if ( !values.length )
455                                         this.selectedIndex = -1;
456
457                         } else
458                                 this.value = value;
459                 });
460         },
461
462         html: function( value ) {
463                 return value === undefined ?
464                         (this[0] ?
465                                 this[0].innerHTML :
466                                 null) :
467                         this.empty().append( value );
468         },
469
470         replaceWith: function( value ) {
471                 return this.after( value ).remove();
472         },
473
474         eq: function( i ) {
475                 return this.slice( i, +i + 1 );
476         },
477
478         slice: function() {
479                 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
480                         "slice", Array.prototype.slice.call(arguments).join(",") );
481         },
482
483         map: function( callback ) {
484                 return this.pushStack( jQuery.map(this, function(elem, i){
485                         return callback.call( elem, i, elem );
486                 }));
487         },
488
489         andSelf: function() {
490                 return this.add( this.prevObject );
491         },
492
493         domManip: function( args, table, callback ) {
494                 if ( this[0] ) {
495                         var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
496                                 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
497                                 first = fragment.firstChild,
498                                 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
499
500                         if ( first )
501                                 for ( var i = 0, l = this.length; i < l; i++ )
502                                         callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
503                         
504                         if ( scripts )
505                                 jQuery.each( scripts, evalScript );
506                 }
507
508                 return this;
509                 
510                 function root( elem, cur ) {
511                         return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
512                                 (elem.getElementsByTagName("tbody")[0] ||
513                                 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
514                                 elem;
515                 }
516         }
517 };
518
519 // Give the init function the jQuery prototype for later instantiation
520 jQuery.fn.init.prototype = jQuery.fn;
521
522 function evalScript( i, elem ) {
523         if ( elem.src )
524                 jQuery.ajax({
525                         url: elem.src,
526                         async: false,
527                         dataType: "script"
528                 });
529
530         else
531                 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
532
533         if ( elem.parentNode )
534                 elem.parentNode.removeChild( elem );
535 }
536
537 function now(){
538         return +new Date;
539 }
540
541 jQuery.extend = jQuery.fn.extend = function() {
542         // copy reference to target object
543         var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
544
545         // Handle a deep copy situation
546         if ( typeof target === "boolean" ) {
547                 deep = target;
548                 target = arguments[1] || {};
549                 // skip the boolean and the target
550                 i = 2;
551         }
552
553         // Handle case when target is a string or something (possible in deep copy)
554         if ( typeof target !== "object" && !jQuery.isFunction(target) )
555                 target = {};
556
557         // extend jQuery itself if only one argument is passed
558         if ( length == i ) {
559                 target = this;
560                 --i;
561         }
562
563         for ( ; i < length; i++ )
564                 // Only deal with non-null/undefined values
565                 if ( (options = arguments[ i ]) != null )
566                         // Extend the base object
567                         for ( var name in options ) {
568                                 var src = target[ name ], copy = options[ name ];
569
570                                 // Prevent never-ending loop
571                                 if ( target === copy )
572                                         continue;
573
574                                 // Recurse if we're merging object values
575                                 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
576                                         target[ name ] = jQuery.extend( deep, 
577                                                 // Never move original objects, clone them
578                                                 src || ( copy.length != null ? [ ] : { } )
579                                         , copy );
580
581                                 // Don't bring in undefined values
582                                 else if ( copy !== undefined )
583                                         target[ name ] = copy;
584
585                         }
586
587         // Return the modified object
588         return target;
589 };
590
591 // exclude the following css properties to add px
592 var     exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
593         // cache defaultView
594         defaultView = document.defaultView || {},
595         toString = Object.prototype.toString;
596
597 jQuery.extend({
598         noConflict: function( deep ) {
599                 window.$ = _$;
600
601                 if ( deep )
602                         window.jQuery = _jQuery;
603
604                 return jQuery;
605         },
606
607         // See test/unit/core.js for details concerning isFunction.
608         // Since version 1.3, DOM methods and functions like alert
609         // aren't supported. They return false on IE (#2968).
610         isFunction: function( obj ) {
611                 return toString.call(obj) === "[object Function]";
612         },
613
614         isArray: function( obj ) {
615                 return toString.call(obj) === "[object Array]";
616         },
617
618         // check if an element is in a (or is an) XML document
619         isXMLDoc: function( elem ) {
620                 return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
621                         !!elem.ownerDocument && jQuery.isXMLDoc( elem.ownerDocument );
622         },
623
624         // Evalulates a script in a global context
625         globalEval: function( data ) {
626                 data = jQuery.trim( data );
627
628                 if ( data ) {
629                         // Inspired by code by Andrea Giammarchi
630                         // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
631                         var head = document.getElementsByTagName("head")[0] || document.documentElement,
632                                 script = document.createElement("script");
633
634                         script.type = "text/javascript";
635                         if ( jQuery.support.scriptEval )
636                                 script.appendChild( document.createTextNode( data ) );
637                         else
638                                 script.text = data;
639
640                         // Use insertBefore instead of appendChild  to circumvent an IE6 bug.
641                         // This arises when a base node is used (#2709).
642                         head.insertBefore( script, head.firstChild );
643                         head.removeChild( script );
644                 }
645         },
646
647         nodeName: function( elem, name ) {
648                 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
649         },
650
651         // args is for internal usage only
652         each: function( object, callback, args ) {
653                 var name, i = 0, length = object.length;
654
655                 if ( args ) {
656                         if ( length === undefined ) {
657                                 for ( name in object )
658                                         if ( callback.apply( object[ name ], args ) === false )
659                                                 break;
660                         } else
661                                 for ( ; i < length; )
662                                         if ( callback.apply( object[ i++ ], args ) === false )
663                                                 break;
664
665                 // A special, fast, case for the most common use of each
666                 } else {
667                         if ( length === undefined ) {
668                                 for ( name in object )
669                                         if ( callback.call( object[ name ], name, object[ name ] ) === false )
670                                                 break;
671                         } else
672                                 for ( var value = object[0];
673                                         i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
674                 }
675
676                 return object;
677         },
678
679         prop: function( elem, value, type, i, name ) {
680                 // Handle executable functions
681                 if ( jQuery.isFunction( value ) )
682                         value = value.call( elem, i );
683
684                 // Handle passing in a number to a CSS property
685                 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
686                         value + "px" :
687                         value;
688         },
689
690         className: {
691                 // internal only, use addClass("class")
692                 add: function( elem, classNames ) {
693                         jQuery.each((classNames || "").split(/\s+/), function(i, className){
694                                 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
695                                         elem.className += (elem.className ? " " : "") + className;
696                         });
697                 },
698
699                 // internal only, use removeClass("class")
700                 remove: function( elem, classNames ) {
701                         if (elem.nodeType == 1)
702                                 elem.className = classNames !== undefined ?
703                                         jQuery.grep(elem.className.split(/\s+/), function(className){
704                                                 return !jQuery.className.has( classNames, className );
705                                         }).join(" ") :
706                                         "";
707                 },
708
709                 // internal only, use hasClass("class")
710                 has: function( elem, className ) {
711                         return elem && jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
712                 }
713         },
714
715         // A method for quickly swapping in/out CSS properties to get correct calculations
716         swap: function( elem, options, callback ) {
717                 var old = {};
718                 // Remember the old values, and insert the new ones
719                 for ( var name in options ) {
720                         old[ name ] = elem.style[ name ];
721                         elem.style[ name ] = options[ name ];
722                 }
723
724                 callback.call( elem );
725
726                 // Revert the old values
727                 for ( var name in options )
728                         elem.style[ name ] = old[ name ];
729         },
730
731         css: function( elem, name, force ) {
732                 if ( name == "width" || name == "height" ) {
733                         var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
734
735                         function getWH() {
736                                 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
737                                 var padding = 0, border = 0;
738                                 jQuery.each( which, function() {
739                                         padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
740                                         border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
741                                 });
742                                 val -= Math.round(padding + border);
743                         }
744
745                         if ( jQuery(elem).is(":visible") )
746                                 getWH();
747                         else
748                                 jQuery.swap( elem, props, getWH );
749
750                         return Math.max(0, val);
751                 }
752
753                 return jQuery.curCSS( elem, name, force );
754         },
755
756         curCSS: function( elem, name, force ) {
757                 var ret, style = elem.style;
758
759                 // We need to handle opacity special in IE
760                 if ( name == "opacity" && !jQuery.support.opacity ) {
761                         ret = jQuery.attr( style, "opacity" );
762
763                         return ret == "" ?
764                                 "1" :
765                                 ret;
766                 }
767
768                 // Make sure we're using the right name for getting the float value
769                 if ( name.match( /float/i ) )
770                         name = styleFloat;
771
772                 if ( !force && style && style[ name ] )
773                         ret = style[ name ];
774
775                 else if ( defaultView.getComputedStyle ) {
776
777                         // Only "float" is needed here
778                         if ( name.match( /float/i ) )
779                                 name = "float";
780
781                         name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
782
783                         var computedStyle = defaultView.getComputedStyle( elem, null );
784
785                         if ( computedStyle )
786                                 ret = computedStyle.getPropertyValue( name );
787
788                         // We should always get a number back from opacity
789                         if ( name == "opacity" && ret == "" )
790                                 ret = "1";
791
792                 } else if ( elem.currentStyle ) {
793                         var camelCase = name.replace(/\-(\w)/g, function(all, letter){
794                                 return letter.toUpperCase();
795                         });
796
797                         ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
798
799                         // From the awesome hack by Dean Edwards
800                         // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
801
802                         // If we're not dealing with a regular pixel number
803                         // but a number that has a weird ending, we need to convert it to pixels
804                         if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
805                                 // Remember the original values
806                                 var left = style.left, rsLeft = elem.runtimeStyle.left;
807
808                                 // Put in the new values to get a computed value out
809                                 elem.runtimeStyle.left = elem.currentStyle.left;
810                                 style.left = ret || 0;
811                                 ret = style.pixelLeft + "px";
812
813                                 // Revert the changed values
814                                 style.left = left;
815                                 elem.runtimeStyle.left = rsLeft;
816                         }
817                 }
818
819                 return ret;
820         },
821
822         clean: function( elems, context, fragment ) {
823                 context = context || document;
824
825                 // !context.createElement fails in IE with an error but returns typeof 'object'
826                 if ( typeof context.createElement === "undefined" )
827                         context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
828
829                 // If a single string is passed in and it's a single tag
830                 // just do a createElement and skip the rest
831                 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
832                         var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
833                         if ( match )
834                                 return [ context.createElement( match[1] ) ];
835                 }
836
837                 var ret = [], scripts = [], div = context.createElement("div");
838
839                 jQuery.each(elems, function(i, elem){
840                         if ( typeof elem === "number" )
841                                 elem += '';
842
843                         if ( !elem )
844                                 return;
845
846                         // Convert html string into DOM nodes
847                         if ( typeof elem === "string" ) {
848                                 // Fix "XHTML"-style tags in all browsers
849                                 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
850                                         return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
851                                                 all :
852                                                 front + "></" + tag + ">";
853                                 });
854
855                                 // Trim whitespace, otherwise indexOf won't work as expected
856                                 var tags = jQuery.trim( elem ).toLowerCase();
857
858                                 var wrap =
859                                         // option or optgroup
860                                         !tags.indexOf("<opt") &&
861                                         [ 1, "<select multiple='multiple'>", "</select>" ] ||
862
863                                         !tags.indexOf("<leg") &&
864                                         [ 1, "<fieldset>", "</fieldset>" ] ||
865
866                                         tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
867                                         [ 1, "<table>", "</table>" ] ||
868
869                                         !tags.indexOf("<tr") &&
870                                         [ 2, "<table><tbody>", "</tbody></table>" ] ||
871
872                                         // <thead> matched above
873                                         (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
874                                         [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
875
876                                         !tags.indexOf("<col") &&
877                                         [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
878
879                                         // IE can't serialize <link> and <script> tags normally
880                                         !jQuery.support.htmlSerialize &&
881                                         [ 1, "div<div>", "</div>" ] ||
882
883                                         [ 0, "", "" ];
884
885                                 // Go to html and back, then peel off extra wrappers
886                                 div.innerHTML = wrap[1] + elem + wrap[2];
887
888                                 // Move to the right depth
889                                 while ( wrap[0]-- )
890                                         div = div.lastChild;
891
892                                 // Remove IE's autoinserted <tbody> from table fragments
893                                 if ( !jQuery.support.tbody ) {
894
895                                         // String was a <table>, *may* have spurious <tbody>
896                                         var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
897                                                 div.firstChild && div.firstChild.childNodes :
898
899                                                 // String was a bare <thead> or <tfoot>
900                                                 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
901                                                         div.childNodes :
902                                                         [];
903
904                                         for ( var j = tbody.length - 1; j >= 0 ; --j )
905                                                 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
906                                                         tbody[ j ].parentNode.removeChild( tbody[ j ] );
907
908                                         }
909
910                                 // IE completely kills leading whitespace when innerHTML is used
911                                 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
912                                         div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
913                                 
914                                 elem = jQuery.makeArray( div.childNodes );
915                         }
916
917                         if ( elem.nodeType )
918                                 ret.push( elem );
919                         else
920                                 ret = jQuery.merge( ret, elem );
921
922                 });
923
924                 if ( fragment ) {
925                         for ( var i = 0; ret[i]; i++ ) {
926                                 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
927                                         scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
928                                 } else {
929                                         if ( ret[i].nodeType === 1 )
930                                                 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
931                                         fragment.appendChild( ret[i] );
932                                 }
933                         }
934                         
935                         return scripts;
936                 }
937
938                 return ret;
939         },
940
941         attr: function( elem, name, value ) {
942                 // don't set attributes on text and comment nodes
943                 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
944                         return undefined;
945
946                 var notxml = !jQuery.isXMLDoc( elem ),
947                         // Whether we are setting (or getting)
948                         set = value !== undefined;
949
950                 // Try to normalize/fix the name
951                 name = notxml && jQuery.props[ name ] || name;
952
953                 // Only do all the following if this is a node (faster for style)
954                 // IE elem.getAttribute passes even for style
955                 if ( elem.tagName ) {
956
957                         // These attributes require special treatment
958                         var special = /href|src|style/.test( name );
959
960                         // Safari mis-reports the default selected property of a hidden option
961                         // Accessing the parent's selectedIndex property fixes it
962                         if ( name == "selected" && elem.parentNode )
963                                 elem.parentNode.selectedIndex;
964
965                         // If applicable, access the attribute via the DOM 0 way
966                         if ( name in elem && notxml && !special ) {
967                                 if ( set ){
968                                         // We can't allow the type property to be changed (since it causes problems in IE)
969                                         if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
970                                                 throw "type property can't be changed";
971
972                                         elem[ name ] = value;
973                                 }
974
975                                 // browsers index elements by id/name on forms, give priority to attributes.
976                                 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
977                                         return elem.getAttributeNode( name ).nodeValue;
978
979                                 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
980                                 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
981                                 if ( name == "tabIndex" ) {
982                                         var attributeNode = elem.getAttributeNode( "tabIndex" );
983                                         return attributeNode && attributeNode.specified
984                                                 ? attributeNode.value
985                                                 : elem.nodeName.match(/(button|input|object|select|textarea)/i)
986                                                         ? 0
987                                                         : elem.nodeName.match(/^(a|area)$/i) && elem.href
988                                                                 ? 0
989                                                                 : undefined;
990                                 }
991
992                                 return elem[ name ];
993                         }
994
995                         if ( !jQuery.support.style && notxml &&  name == "style" )
996                                 return jQuery.attr( elem.style, "cssText", value );
997
998                         if ( set )
999                                 // convert the value to a string (all browsers do this but IE) see #1070
1000                                 elem.setAttribute( name, "" + value );
1001
1002                         var attr = !jQuery.support.hrefNormalized && notxml && special
1003                                         // Some attributes require a special call on IE
1004                                         ? elem.getAttribute( name, 2 )
1005                                         : elem.getAttribute( name );
1006
1007                         // Non-existent attributes return null, we normalize to undefined
1008                         return attr === null ? undefined : attr;
1009                 }
1010
1011                 // elem is actually elem.style ... set the style
1012
1013                 // IE uses filters for opacity
1014                 if ( !jQuery.support.opacity && name == "opacity" ) {
1015                         if ( set ) {
1016                                 // IE has trouble with opacity if it does not have layout
1017                                 // Force it by setting the zoom level
1018                                 elem.zoom = 1;
1019
1020                                 // Set the alpha filter to set the opacity
1021                                 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1022                                         (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1023                         }
1024
1025                         return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1026                                 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1027                                 "";
1028                 }
1029
1030                 name = name.replace(/-([a-z])/ig, function(all, letter){
1031                         return letter.toUpperCase();
1032                 });
1033
1034                 if ( set )
1035                         elem[ name ] = value;
1036
1037                 return elem[ name ];
1038         },
1039
1040         trim: function( text ) {
1041                 return (text || "").replace( /^\s+|\s+$/g, "" );
1042         },
1043
1044         makeArray: function( array ) {
1045                 var ret = [];
1046
1047                 if( array != null ){
1048                         var i = array.length;
1049                         // The window, strings (and functions) also have 'length'
1050                         if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1051                                 ret[0] = array;
1052                         else
1053                                 while( i )
1054                                         ret[--i] = array[i];
1055                 }
1056
1057                 return ret;
1058         },
1059
1060         inArray: function( elem, array ) {
1061                 for ( var i = 0, length = array.length; i < length; i++ )
1062                 // Use === because on IE, window == document
1063                         if ( array[ i ] === elem )
1064                                 return i;
1065
1066                 return -1;
1067         },
1068
1069         merge: function( first, second ) {
1070                 // We have to loop this way because IE & Opera overwrite the length
1071                 // expando of getElementsByTagName
1072                 var i = 0, elem, pos = first.length;
1073                 // Also, we need to make sure that the correct elements are being returned
1074                 // (IE returns comment nodes in a '*' query)
1075                 if ( !jQuery.support.getAll ) {
1076                         while ( (elem = second[ i++ ]) != null )
1077                                 if ( elem.nodeType != 8 )
1078                                         first[ pos++ ] = elem;
1079
1080                 } else
1081                         while ( (elem = second[ i++ ]) != null )
1082                                 first[ pos++ ] = elem;
1083
1084                 return first;
1085         },
1086
1087         unique: function( array ) {
1088                 var ret = [], done = {};
1089
1090                 try {
1091
1092                         for ( var i = 0, length = array.length; i < length; i++ ) {
1093                                 var id = jQuery.data( array[ i ] );
1094
1095                                 if ( !done[ id ] ) {
1096                                         done[ id ] = true;
1097                                         ret.push( array[ i ] );
1098                                 }
1099                         }
1100
1101                 } catch( e ) {
1102                         ret = array;
1103                 }
1104
1105                 return ret;
1106         },
1107
1108         grep: function( elems, callback, inv ) {
1109                 var ret = [];
1110
1111                 // Go through the array, only saving the items
1112                 // that pass the validator function
1113                 for ( var i = 0, length = elems.length; i < length; i++ )
1114                         if ( !inv != !callback( elems[ i ], i ) )
1115                                 ret.push( elems[ i ] );
1116
1117                 return ret;
1118         },
1119
1120         map: function( elems, callback ) {
1121                 var ret = [];
1122
1123                 // Go through the array, translating each of the items to their
1124                 // new value (or values).
1125                 for ( var i = 0, length = elems.length; i < length; i++ ) {
1126                         var value = callback( elems[ i ], i );
1127
1128                         if ( value != null )
1129                                 ret[ ret.length ] = value;
1130                 }
1131
1132                 return ret.concat.apply( [], ret );
1133         }
1134 });
1135
1136 // Use of jQuery.browser is deprecated.
1137 // It's included for backwards compatibility and plugins,
1138 // although they should work to migrate away.
1139
1140 var userAgent = navigator.userAgent.toLowerCase();
1141
1142 // Figure out what browser is being used
1143 jQuery.browser = {
1144         version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1145         safari: /webkit/.test( userAgent ),
1146         opera: /opera/.test( userAgent ),
1147         msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1148         mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1149 };
1150
1151 jQuery.each({
1152         parent: function(elem){return elem.parentNode;},
1153         parents: function(elem){return jQuery.dir(elem,"parentNode");},
1154         next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1155         prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1156         nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1157         prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1158         siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1159         children: function(elem){return jQuery.sibling(elem.firstChild);},
1160         contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1161 }, function(name, fn){
1162         jQuery.fn[ name ] = function( selector ) {
1163                 var ret = jQuery.map( this, fn );
1164
1165                 if ( selector && typeof selector == "string" )
1166                         ret = jQuery.multiFilter( selector, ret );
1167
1168                 return this.pushStack( jQuery.unique( ret ), name, selector );
1169         };
1170 });
1171
1172 jQuery.each({
1173         appendTo: "append",
1174         prependTo: "prepend",
1175         insertBefore: "before",
1176         insertAfter: "after",
1177         replaceAll: "replaceWith"
1178 }, function(name, original){
1179         jQuery.fn[ name ] = function() {
1180                 var args = arguments;
1181
1182                 return this.each(function(){
1183                         for ( var i = 0, length = args.length; i < length; i++ )
1184                                 jQuery( args[ i ] )[ original ]( this );
1185                 });
1186         };
1187 });
1188
1189 jQuery.each({
1190         removeAttr: function( name ) {
1191                 jQuery.attr( this, name, "" );
1192                 if (this.nodeType == 1)
1193                         this.removeAttribute( name );
1194         },
1195
1196         addClass: function( classNames ) {
1197                 jQuery.className.add( this, classNames );
1198         },
1199
1200         removeClass: function( classNames ) {
1201                 jQuery.className.remove( this, classNames );
1202         },
1203
1204         toggleClass: function( classNames, state ) {
1205                 if( typeof state !== "boolean" )
1206                         state = !jQuery.className.has( this, classNames );
1207                 jQuery.className[ state ? "add" : "remove" ]( this, classNames );
1208         },
1209
1210         remove: function( selector ) {
1211                 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1212                         // Prevent memory leaks
1213                         jQuery( "*", this ).add([this]).each(function(){
1214                                 jQuery.event.remove(this);
1215                                 jQuery.removeData(this);
1216                         });
1217                         if (this.parentNode)
1218                                 this.parentNode.removeChild( this );
1219                 }
1220         },
1221
1222         empty: function() {
1223                 // Remove element nodes and prevent memory leaks
1224                 jQuery( ">*", this ).remove();
1225
1226                 // Remove any remaining nodes
1227                 while ( this.firstChild )
1228                         this.removeChild( this.firstChild );
1229         }
1230 }, function(name, fn){
1231         jQuery.fn[ name ] = function(){
1232                 return this.each( fn, arguments );
1233         };
1234 });
1235
1236 // Helper function used by the dimensions and offset modules
1237 function num(elem, prop) {
1238         return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;
1239 }