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