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