A bunch of fixes for thead/tbody related bugs.
[jquery.git] / src / jquery / jquery.js
1 /*
2  * jQuery - New Wave Javascript
3  *
4  * Copyright (c) 2006 John Resig (jquery.com)
5  * Licensed under the MIT License:
6  *   http://www.opensource.org/licenses/mit-license.php
7  *
8  * $Date$
9  * $Rev$
10  */
11
12 // Global undefined variable
13 window.undefined = window.undefined;
14
15 /**
16  * Create a new jQuery Object
17  *
18  * @test ok( Array.prototype.push, "Array.push()" );
19  * @test ok( Function.prototype.apply, "Function.apply()" );
20  * @test ok( document.getElementById, "getElementById" );
21  * @test ok( document.getElementsByTagName, "getElementsByTagName" );
22  * @test ok( RegExp, "RegExp" );
23  * @test ok( jQuery, "jQuery" );
24  * @test ok( $, "$()" );
25  *
26  * @constructor
27  * @private
28  * @name jQuery
29  */
30 function jQuery(a,c) {
31
32         // Initalize the extra macro functions
33         if ( !jQuery.initDone ) jQuery.init();
34
35         // Shortcut for document ready (because $(document).each() is silly)
36         if ( a && a.constructor == Function && jQuery.fn.ready )
37                 return jQuery(document).ready(a);
38
39         // Make sure t hat a selection was provided
40         a = a || jQuery.context || document;
41
42         /*
43          * Handle support for overriding other $() functions. Way too many libraries
44          * provide this function to simply ignore it and overwrite it.
45          */
46         /*
47         // Check to see if this is a possible collision case
48         if ( jQuery._$ && !c && a.constructor == String && 
49       
50                 // Make sure that the expression is a colliding one
51                 !/[^a-zA-Z0-9_-]/.test(a) &&
52         
53                 // and that there are no elements that match it
54                 // (this is the one truly ambiguous case)
55                 !document.getElementsByTagName(a).length )
56
57                         // Use the default method, in case it works some voodoo
58                         return jQuery._$( a );
59         */
60
61         // Watch for when a jQuery object is passed as the selector
62         if ( a.jquery )
63                 return a;
64
65         // Watch for when a jQuery object is passed at the context
66         if ( c && c.jquery )
67                 return jQuery(c.get()).find(a);
68         
69         // If the context is global, return a new object
70         if ( window == this )
71                 return new jQuery(a,c);
72
73         // Handle HTML strings
74         var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
75         if ( m ) a = jQuery.clean( [ m[1] ] );
76
77         // Watch for when an array is passed in
78         this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
79                 // Assume that it is an array of DOM Elements
80                 jQuery.merge( a, [] ) :
81
82                 // Find the matching elements and save them for later
83                 jQuery.find( a, c ) );
84
85         var fn = arguments[ arguments.length - 1 ];
86         if ( fn && fn.constructor == Function )
87                 this.each(fn);
88 }
89
90 // Map over the $ in case of overwrite
91 if ( $ )
92         jQuery._$ = $;
93
94 // Map the jQuery namespace to the '$' one
95 var $ = jQuery;
96
97 jQuery.fn = jQuery.prototype = {
98         /**
99          * The current SVN version of jQuery.
100          *
101          * @private
102          * @property
103          * @name jquery
104          * @type String
105          * @cat Core
106          */
107         jquery: "$Rev$",
108         
109         /**
110          * The number of elements currently matched.
111          *
112          * @example $("img").length;
113          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
114          * @result 2
115          *
116          * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
117          *
118          * @property
119          * @name length
120          * @type Number
121          * @cat Core
122          */
123         
124         /**
125          * The number of elements currently matched.
126          *
127          * @example $("img").size();
128          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
129          * @result 2
130          *
131          * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
132          *
133          * @name size
134          * @type Number
135          * @cat Core
136          */
137         size: function() {
138                 return this.length;
139         },
140         
141         /**
142          * Access all matched elements. This serves as a backwards-compatible
143          * way of accessing all matched elements (other than the jQuery object
144          * itself, which is, in fact, an array of elements).
145          *
146          * @example $("img").get();
147          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
148          * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
149          *
150          * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
151          *
152          * @name get
153          * @type Array<Element>
154          * @cat Core
155          */
156          
157         /**
158          * Access a single matched element. num is used to access the 
159          * Nth element matched.
160          *
161          * @example $("img").get(1);
162          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
163          * @result [ <img src="test1.jpg"/> ]
164          *
165          * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
166          *
167          * @name get
168          * @type Element
169          * @param Number num Access the element in the Nth position.
170          * @cat Core
171          */
172          
173         /**
174          * Set the jQuery object to an array of elements.
175          *
176          * @example $("img").get([ document.body ]);
177          * @result $("img").get() == [ document.body ]
178          *
179          * @private
180          * @name get
181          * @type jQuery
182          * @param Elements elems An array of elements
183          * @cat Core
184          */
185         get: function( num ) {
186                 // Watch for when an array (of elements) is passed in
187                 if ( num && num.constructor == Array ) {
188
189                         // Use a tricky hack to make the jQuery object
190                         // look and feel like an array
191                         this.length = 0;
192                         [].push.apply( this, num );
193                         
194                         return this;
195                 } else
196                         return num == undefined ?
197
198                                 // Return a 'clean' array
199                                 jQuery.map( this, function(a){ return a } ) :
200
201                                 // Return just the object
202                                 this[num];
203         },
204
205         /**
206          * Execute a function within the context of every matched element.
207          * This means that every time the passed-in function is executed
208          * (which is once for every element matched) the 'this' keyword
209          * points to the specific element.
210          *
211          * Additionally, the function, when executed, is passed a single
212          * argument representing the position of the element in the matched
213          * set.
214          *
215          * @example $("img").each(function(){ this.src = "test.jpg"; });
216          * @before <img/> <img/>
217          * @result <img src="test.jpg"/> <img src="test.jpg"/>
218          *
219          * @test var div = $("div");
220          * div.each(function(){this.foo = 'zoo';});
221          * var pass = true;
222          * for ( var i = 0; i < div.size(); i++ ) {
223          *   if ( div.get(i).foo != "zoo" ) pass = false;
224          * }
225          * ok( pass, "Execute a function, Relative" );
226          *
227          * @name each
228          * @type jQuery
229          * @param Function fn A function to execute
230          * @cat Core
231          */
232         each: function( fn, args ) {
233                 return jQuery.each( this, fn, args );
234         },
235         
236         /**
237          * Access a property on the first matched element.
238          * This method makes it easy to retreive a property value
239          * from the first matched element.
240          *
241          * @example $("img").attr("src");
242          * @before <img src="test.jpg"/>
243          * @result test.jpg
244          *
245          * @name attr
246          * @type Object
247          * @param String name The name of the property to access.
248          * @cat DOM
249          */
250          
251         /**
252          * Set a hash of key/value object properties to all matched elements.
253          * This serves as the best way to set a large number of properties
254          * on all matched elements.
255          *
256          * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
257          * @before <img/>
258          * @result <img src="test.jpg" alt="Test Image"/>
259          *
260          * @test var div = $("div");
261          * div.attr({foo: 'baz', zoo: 'ping'});
262          * var pass = true;
263          * for ( var i = 0; i < div.size(); i++ ) {
264          *   if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
265          * }
266          * ok( pass, "Set Multiple Attributes" );
267          *
268          * @name attr
269          * @type jQuery
270          * @param Hash prop A set of key/value pairs to set as object properties.
271          * @cat DOM
272          */
273          
274         /**
275          * Set a single property to a value, on all matched elements.
276          *
277          * @example $("img").attr("src","test.jpg");
278          * @before <img/>
279          * @result <img src="test.jpg"/>
280          *
281          * @test var div = $("div");
282          * div.attr("foo", "bar");
283          * var pass = true;
284          * for ( var i = 0; i < div.size(); i++ ) {
285          *   if ( div.get(i).foo != "bar" ) pass = false;
286          * }
287          * ok( pass, "Set Attribute" );
288          *
289          * @name attr
290          * @type jQuery
291          * @param String key The name of the property to set.
292          * @param Object value The value to set the property to.
293          * @cat DOM
294          */
295         attr: function( key, value, type ) {
296                 // Check to see if we're setting style values
297                 return key.constructor != String || value != undefined ?
298                         this.each(function(){
299                                 // See if we're setting a hash of styles
300                                 if ( value == undefined )
301                                         // Set all the styles
302                                         for ( var prop in key )
303                                                 jQuery.attr(
304                                                         type ? this.style : this,
305                                                         prop, key[prop]
306                                                 );
307                                 
308                                 // See if we're setting a single key/value style
309                                 else
310                                         jQuery.attr(
311                                                 type ? this.style : this,
312                                                 key, value
313                                         );
314                         }) :
315                         
316                         // Look for the case where we're accessing a style value
317                         jQuery[ type || "attr" ]( this[0], key );
318         },
319         
320         /**
321          * Access a style property on the first matched element.
322          * This method makes it easy to retreive a style property value
323          * from the first matched element.
324          *
325          * @example $("p").css("red");
326          * @before <p style="color:red;">Test Paragraph.</p>
327          * @result red
328          *
329          * @name css
330          * @type Object
331          * @param String name The name of the property to access.
332          * @cat CSS
333          */
334          
335         /**
336          * Set a hash of key/value style properties to all matched elements.
337          * This serves as the best way to set a large number of style properties
338          * on all matched elements.
339          *
340          * @example $("p").css({ color: "red", background: "blue" });
341          * @before <p>Test Paragraph.</p>
342          * @result <p style="color:red; background:blue;">Test Paragraph.</p>
343          *
344          * @name css
345          * @type jQuery
346          * @param Hash prop A set of key/value pairs to set as style properties.
347          * @cat CSS
348          */
349          
350         /**
351          * Set a single style property to a value, on all matched elements.
352          *
353          * @example $("p").css("color","red");
354          * @before <p>Test Paragraph.</p>
355          * @result <p style="color:red;">Test Paragraph.</p>
356          *
357          * @name css
358          * @type jQuery
359          * @param String key The name of the property to set.
360          * @param Object value The value to set the property to.
361          * @cat CSS
362          */
363         css: function( key, value ) {
364                 return this.attr( key, value, "curCSS" );
365         },
366         
367         /**
368          * Retreive the text contents of all matched elements. The result is
369          * a string that contains the combined text contents of all matched
370          * elements. This method works on both HTML and XML documents.
371          *
372          * @example $("p").text();
373          * @before <p>Test Paragraph.</p>
374          * @result Test Paragraph.
375          *
376          * @name text
377          * @type String
378          * @cat DOM
379          */
380         text: function(e) {
381                 e = e || this;
382                 var t = "";
383                 for ( var j = 0; j < e.length; j++ ) {
384                         var r = e[j].childNodes;
385                         for ( var i = 0; i < r.length; i++ )
386                                 t += r[i].nodeType != 1 ?
387                                         r[i].nodeValue : jQuery.fn.text([ r[i] ]);
388                 }
389                 return t;
390         },
391         
392         /**
393          * Wrap all matched elements with a structure of other elements.
394          * This wrapping process is most useful for injecting additional
395          * stucture into a document, without ruining the original semantic
396          * qualities of a document.
397          *
398          * The way that is works is that it goes through the first element argument
399          * provided and finds the deepest element within the structure - it is that
400          * element that will en-wrap everything else.
401          *
402          * @example $("p").wrap("<div class='wrap'></div>");
403          * @before <p>Test Paragraph.</p>
404          * @result <div class='wrap'><p>Test Paragraph.</p></div>
405          *
406          * @name wrap
407          * @type jQuery
408          * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
409          * @any Element elem A DOM element that will be wrapped.
410          * @any Array<Element> elems An array of elements, the first of which will be wrapped.
411          * @any Object obj Any object, converted to a string, then a text node.
412          * @cat DOM/Manipulation
413          */
414         wrap: function() {
415                 // The elements to wrap the target around
416                 var a = jQuery.clean(arguments);
417                 
418                 // Wrap each of the matched elements individually
419                 return this.each(function(){
420                         // Clone the structure that we're using to wrap
421                         var b = a[0].cloneNode(true);
422                         
423                         // Insert it before the element to be wrapped
424                         this.parentNode.insertBefore( b, this );
425                         
426                         // Find he deepest point in the wrap structure
427                         while ( b.firstChild )
428                                 b = b.firstChild;
429                         
430                         // Move the matched element to within the wrap structure
431                         b.appendChild( this );
432                 });
433         },
434         
435         /**
436          * Append any number of elements to the inside of all matched elements.
437          * This operation is similar to doing an appendChild to all the 
438          * specified elements, adding them into the document.
439          * 
440          * @example $("p").append("<b>Hello</b>");
441          * @before <p>I would like to say: </p>
442          * @result <p>I would like to say: <b>Hello</b></p>
443          *
444          * @name append
445          * @type jQuery
446          * @any String html A string of HTML, that will be created on the fly and appended to the target.
447          * @any Element elem A DOM element that will be appended.
448          * @any Array<Element> elems An array of elements, all of which will be appended.
449          * @any Object obj Any object, converted to a string, then a text node.
450          * @cat DOM/Manipulation
451          */
452         append: function() {
453                 return this.domManip(arguments, true, 1, function(a){
454                         this.appendChild( a );
455                 });
456         },
457         
458         /**
459          * Prepend any number of elements to the inside of all matched elements.
460          * This operation is the best way to insert a set of elements inside, at the 
461          * beginning, of all the matched element.
462          * 
463          * @example $("p").prepend("<b>Hello</b>");
464          * @before <p>, how are you?</p>
465          * @result <p><b>Hello</b>, how are you?</p>
466          *
467          * @name prepend
468          * @type jQuery
469          * @any String html A string of HTML, that will be created on the fly and prepended to the target.
470          * @any Element elem A DOM element that will be prepended.
471          * @any Array<Element> elems An array of elements, all of which will be prepended.
472          * @any Object obj Any object, converted to a string, then a text node.
473          * @cat DOM/Manipulation
474          */
475         prepend: function() {
476                 return this.domManip(arguments, true, -1, function(a){
477                         this.insertBefore( a, this.firstChild );
478                 });
479         },
480         
481         /**
482          * Insert any number of elements before each of the matched elements.
483          * 
484          * @example $("p").before("<b>Hello</b>");
485          * @before <p>how are you?</p>
486          * @result <b>Hello</b><p>how are you?</p>
487          *
488          * @name before
489          * @type jQuery
490          * @any String html A string of HTML, that will be created on the fly and inserted.
491          * @any Element elem A DOM element that will beinserted.
492          * @any Array<Element> elems An array of elements, all of which will be inserted.
493          * @any Object obj Any object, converted to a string, then a text node.
494          * @cat DOM/Manipulation
495          */
496         before: function() {
497                 return this.domManip(arguments, false, 1, function(a){
498                         this.parentNode.insertBefore( a, this );
499                 });
500         },
501         
502         /**
503          * Insert any number of elements after each of the matched elements.
504          * 
505          * @example $("p").after("<p>I'm doing fine.</p>");
506          * @before <p>How are you?</p>
507          * @result <p>How are you?</p><p>I'm doing fine.</p>
508          *
509          * @name after
510          * @type jQuery
511          * @any String html A string of HTML, that will be created on the fly and inserted.
512          * @any Element elem A DOM element that will beinserted.
513          * @any Array<Element> elems An array of elements, all of which will be inserted.
514          * @any Object obj Any object, converted to a string, then a text node.
515          * @cat DOM/Manipulation
516          */
517         after: function() {
518                 return this.domManip(arguments, false, -1, function(a){
519                         this.parentNode.insertBefore( a, this.nextSibling );
520                 });
521         },
522         
523         /**
524          * End the most recent 'destructive' operation, reverting the list of matched elements
525          * back to its previous state. After an end operation, the list of matched elements will 
526          * revert to the last state of matched elements.
527          *
528          * @example $("p").find("span").end();
529          * @before <p><span>Hello</span>, how are you?</p>
530          * @result $("p").find("span").end() == [ <p>...</p> ]
531          *
532          * @name end
533          * @type jQuery
534          * @cat DOM/Traversing
535          */
536         end: function() {
537                 return this.get( this.stack.pop() );
538         },
539         
540         /**
541          * Searches for all elements that match the specified expression.
542          * This method is the optimal way of finding additional descendant
543          * elements with which to process.
544          *
545          * All searching is done using a jQuery expression. The expression can be 
546          * written using CSS 1-3 Selector syntax, or basic XPath.
547          *
548          * @example $("p").find("span");
549          * @before <p><span>Hello</span>, how are you?</p>
550          * @result $("p").find("span") == [ <span>Hello</span> ]
551          *
552          * @name find
553          * @type jQuery
554          * @param String expr An expression to search with.
555          * @cat DOM/Traversing
556          */
557         find: function(t) {
558                 return this.pushStack( jQuery.map( this, function(a){
559                         return jQuery.find(t,a);
560                 }), arguments );
561         },
562         
563         /**
564          * Removes all elements from the set of matched elements that do not 
565          * match the specified expression. This method is used to narrow down
566          * the results of a search.
567          *
568          * All searching is done using a jQuery expression. The expression
569          * can be written using CSS 1-3 Selector syntax, or basic XPath.
570          * 
571          * @example $("p").filter(".selected")
572          * @before <p class="selected">Hello</p><p>How are you?</p>
573          * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
574          *
575          * @name filter
576          * @type jQuery
577          * @param String expr An expression to search with.
578          * @cat DOM/Traversing
579          */
580
581         /**
582          * Removes all elements from the set of matched elements that do not
583          * match at least one of the expressions passed to the function. This 
584          * method is used when you want to filter the set of matched elements 
585          * through more than one expression.
586          *
587          * Elements will be retained in the jQuery object if they match at
588          * least one of the expressions passed.
589          *
590          * @example $("p").filter([".selected", ":first"])
591          * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
592          * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
593          *
594          * @name filter
595          * @type jQuery
596          * @param Array<String> exprs A set of expressions to evaluate against
597          * @cat DOM/Traversing
598          */
599         filter: function(t) {
600                 return this.pushStack(
601                         t.constructor == Array &&
602                         jQuery.map(this,function(a){
603                                 for ( var i = 0; i < t.length; i++ )
604                                         if ( jQuery.filter(t[i],[a]).r.length )
605                                                 return a;
606                         }) ||
607
608                         t.constructor == Boolean &&
609                         ( t ? this.get() : [] ) ||
610
611                         t.constructor == Function &&
612                         jQuery.grep( this, t ) ||
613
614                         jQuery.filter(t,this).r, arguments );
615         },
616         
617         /**
618          * Removes the specified Element from the set of matched elements. This
619          * method is used to remove a single Element from a jQuery object.
620          *
621          * @example $("p").not( document.getElementById("selected") )
622          * @before <p>Hello</p><p id="selected">Hello Again</p>
623          * @result [ <p>Hello</p> ]
624          *
625          * @name not
626          * @type jQuery
627          * @param Element el An element to remove from the set
628          * @cat DOM/Traversing
629          */
630
631         /**
632          * Removes elements matching the specified expression from the set
633          * of matched elements. This method is used to remove one or more
634          * elements from a jQuery object.
635          * 
636          * @example $("p").not("#selected")
637          * @before <p>Hello</p><p id="selected">Hello Again</p>
638          * @result [ <p>Hello</p> ]
639          *
640          * @name not
641          * @type jQuery
642          * @param String expr An expression with which to remove matching elements
643          * @cat DOM/Traversing
644          */
645         not: function(t) {
646                 return this.pushStack( t.constructor == String ?
647                         jQuery.filter(t,this,false).r :
648                         jQuery.grep(this,function(a){ return a != t; }), arguments );
649         },
650
651         /**
652          * Adds the elements matched by the expression to the jQuery object. This
653          * can be used to concatenate the result sets of two expressions.
654          *
655          * @example $("p").add("span")
656          * @before <p>Hello</p><p><span>Hello Again</span></p>
657          * @result [ <p>Hello</p>, <span>Hello Again</span> ]
658          *
659          * @name add
660          * @type jQuery
661          * @param String expr An expression whose matched elements are added
662          * @cat DOM/Traversing
663          */
664
665         /**
666          * Adds each of the Elements in the array to the set of matched elements.
667          * This is used to add a set of Elements to a jQuery object.
668          *
669          * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
670          * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
671          * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
672          *
673          * @name add
674          * @type jQuery
675          * @param Array<Element> els An array of Elements to add
676          * @cat jQuery
677          */
678
679         /**
680          * Adds a single Element to the set of matched elements. This is used to
681          * add a single Element to a jQuery object.
682          *
683          * @example $("p").add( document.getElementById("a") )
684          * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
685          * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
686          *
687          * @name add
688          * @type jQuery
689          * @param Element el An Element to add
690          * @cat jQuery
691          */
692         add: function(t) {
693                 return this.pushStack( jQuery.merge( this, t.constructor == String ?
694                         jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
695         },
696         
697         /**
698          * A wrapper function for each() to be used by append and prepend.
699          * Handles cases where you're trying to modify the inner contents of
700          * a table, when you actually need to work with the tbody.
701          *
702          * @member jQuery
703          * @param {String} expr The expression with which to filter
704          * @type Boolean
705          * @cat jQuery
706          */
707         is: function(expr) {
708                 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
709         },
710         
711         /**
712          * 
713          *
714          * @private
715          * @name domManip
716          * @param Array args
717          * @param Boolean table
718          * @param Number int
719          * @param Function fn The function doing the DOM manipulation.
720          * @type jQuery
721          */
722         domManip: function(args, table, dir, fn){
723                 var clone = this.size() > 1;
724                 var a = jQuery.clean(args);
725                 
726                 return this.each(function(){
727                         var obj = this;
728                         
729                         if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
730                                 var tbody = this.getElementsByTagName("tbody");
731
732                                 if ( !tbody.length ) {
733                                         obj = document.createElement("tbody");
734                                         this.appendChild( obj );
735                                 } else
736                                         obj = tbody[0];
737                         }
738
739                         for ( var i = ( dir < 0 ? a.length - 1 : 0 );
740                                 i != ( dir < 0 ? dir : a.length ); i += dir ) {
741                                         fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
742                         }
743                 });
744         },
745         
746         /**
747          * 
748          *
749          * @private
750          * @name pushStack
751          * @param Array a
752          * @param Array args
753          * @type jQuery
754          */
755         pushStack: function(a,args) {
756                 var fn = args && args[args.length-1];
757
758                 if ( !fn || fn.constructor != Function ) {
759                         if ( !this.stack ) this.stack = [];
760                         this.stack.push( this.get() );
761                         this.get( a );
762                 } else {
763                         var old = this.get();
764                         this.get( a );
765                         if ( fn.constructor == Function )
766                                 return this.each( fn );
767                         this.get( old );
768                 }
769
770                 return this;
771         }
772 };
773
774 /**
775  * 
776  *
777  * @private
778  * @name extend
779  * @param Object obj
780  * @param Object prop
781  * @type Object
782  */
783  
784 /**
785  * Extend one object with another, returning the original,
786  * modified, object. This is a great utility for simple inheritance.
787  *
788  * @name jQuery.extend
789  * @param Object obj The object to extend
790  * @param Object prop The object that will be merged into the first.
791  * @type Object
792  * @cat Javascript
793  */
794 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
795         if ( !prop ) { prop = obj; obj = this; }
796         for ( var i in prop ) obj[i] = prop[i];
797         return obj;
798 };
799
800 jQuery.extend({
801         /**
802          * 
803          *
804          * @private
805          * @name init
806          * @type undefined
807          */
808         init: function(){
809                 jQuery.initDone = true;
810                 
811                 jQuery.each( jQuery.macros.axis, function(i,n){
812                         jQuery.fn[ i ] = function(a) {
813                                 var ret = jQuery.map(this,n);
814                                 if ( a && a.constructor == String )
815                                         ret = jQuery.filter(a,ret).r;
816                                 return this.pushStack( ret, arguments );
817                         };
818                 });
819                 
820                 jQuery.each( jQuery.macros.to, function(i,n){
821                         jQuery.fn[ i ] = function(){
822                                 var a = arguments;
823                                 return this.each(function(){
824                                         for ( var j = 0; j < a.length; j++ )
825                                                 $(a[j])[n]( this );
826                                 });
827                         };
828                 });
829                 
830                 jQuery.each( jQuery.macros.each, function(i,n){
831                         jQuery.fn[ i ] = function() {
832                                 return this.each( n, arguments );
833                         };
834                 });
835
836                 jQuery.each( jQuery.macros.filter, function(i,n){
837                         jQuery.fn[ n ] = function(num,fn) {
838                                 return this.filter( ":" + n + "(" + num + ")", fn );
839                         };
840                 });
841                 
842                 jQuery.each( jQuery.macros.attr, function(i,n){
843                         n = n || i;
844                         jQuery.fn[ i ] = function(h) {
845                                 return h == undefined ?
846                                         this.length ? this[0][n] : null :
847                                         this.attr( n, h );
848                         };
849                 });
850         
851                 jQuery.each( jQuery.macros.css, function(i,n){
852                         jQuery.fn[ i ] = function(h) {
853                                 return h == undefined ?
854                                         ( this.length ? jQuery.css( this[0], n ) : null ) :
855                                         this.css( n, h );
856                         };
857                 });
858         
859         },
860         
861         /**
862          * A generic iterator function, which can be used to seemlessly
863          * iterate over both objects and arrays.
864          *
865          * @name jQuery.each
866          * @param Object obj The object, or array, to iterate over.
867          * @param Object fn The function that will be executed on every object.
868          * @type Object
869          * @cat Javascript
870          */
871         each: function( obj, fn, args ) {
872                 if ( obj.length == undefined )
873                         for ( var i in obj )
874                                 fn.apply( obj[i], args || [i, obj[i]] );
875                 else
876                         for ( var i = 0; i < obj.length; i++ )
877                                 fn.apply( obj[i], args || [i, obj[i]] );
878                 return obj;
879         },
880         
881         className: {
882                 add: function(o,c){
883                         if (jQuery.className.has(o,c)) return;
884                         o.className += ( o.className ? " " : "" ) + c;
885                 },
886                 remove: function(o,c){
887                         o.className = !c ? "" :
888                                 o.className.replace(
889                                         new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
890                 },
891                 has: function(e,a) {
892                         if ( e.className )
893                                 e = e.className;
894                         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
895                 }
896         },
897         
898         /**
899          * Swap in/out style options.
900          * @private
901          */
902         swap: function(e,o,f) {
903                 for ( var i in o ) {
904                         e.style["old"+i] = e.style[i];
905                         e.style[i] = o[i];
906                 }
907                 f.apply( e, [] );
908                 for ( var i in o )
909                         e.style[i] = e.style["old"+i];
910         },
911         
912         css: function(e,p) {
913                 if ( p == "height" || p == "width" ) {
914                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
915         
916                         for ( var i in d ) {
917                                 old["padding" + d[i]] = 0;
918                                 old["border" + d[i] + "Width"] = 0;
919                         }
920         
921                         jQuery.swap( e, old, function() {
922                                 if (jQuery.css(e,"display") != "none") {
923                                         oHeight = e.offsetHeight;
924                                         oWidth = e.offsetWidth;
925                                 } else
926                                         jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
927                                                 function(){
928                                                         oHeight = e.clientHeight;
929                                                         oWidth = e.clientWidth;
930                                                 });
931                         });
932         
933                         return p == "height" ? oHeight : oWidth;
934                 } else if ( p == "opacity" && jQuery.browser.msie )
935                         return parseFloat(  jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
936
937                 return jQuery.curCSS( e, p );
938         },
939
940         curCSS: function(e,p,force) {
941                 var r;
942         
943                 if (!force && e.style[p])
944                         r = e.style[p];
945                 else if (e.currentStyle) {
946                         p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); 
947                         r = e.currentStyle[p];
948                 } else if (document.defaultView && document.defaultView.getComputedStyle) {
949                         p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
950                         var s = document.defaultView.getComputedStyle(e,"");
951                         r = s ? s.getPropertyValue(p) : null;
952                 }
953                 
954                 return r;
955         },
956         
957         clean: function(a) {
958                 var r = [];
959                 for ( var i = 0; i < a.length; i++ ) {
960                         if ( a[i].constructor == String ) {
961
962                                 var table = "";
963         
964                                 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
965                                         table = "thead";
966                                         a[i] = "<table>" + a[i] + "</table>";
967                                 } else if ( !a[i].indexOf("<tr") ) {
968                                         table = "tr";
969                                         a[i] = "<table>" + a[i] + "</table>";
970                                 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
971                                         table = "td";
972                                         a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
973                                 }
974         
975                                 var div = document.createElement("div");
976                                 div.innerHTML = a[i];
977         
978                                 if ( table ) {
979                                         div = div.firstChild;
980                                         if ( table != "thead" ) div = div.firstChild;
981                                         if ( table == "td" ) div = div.firstChild;
982                                 }
983         
984                                 for ( var j = 0; j < div.childNodes.length; j++ )
985                                         r.push( div.childNodes[j] );
986                                 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
987                                         for ( var k = 0; k < a[i].length; k++ )
988                                                 r.push( a[i][k] );
989                                 else if ( a[i] !== null )
990                                         r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
991                 }
992                 return r;
993         },
994         
995         expr: {
996                 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
997                 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
998                 ":": {
999                         // Position Checks
1000                         lt: "i<m[3]-0",
1001                         gt: "i>m[3]-0",
1002                         nth: "m[3]-0==i",
1003                         eq: "m[3]-0==i",
1004                         first: "i==0",
1005                         last: "i==r.length-1",
1006                         even: "i%2==0",
1007                         odd: "i%2",
1008                         
1009                         // Child Checks
1010                         "first-child": "jQuery.sibling(a,0).cur",
1011                         "last-child": "jQuery.sibling(a,0).last",
1012                         "only-child": "jQuery.sibling(a).length==1",
1013                         
1014                         // Parent Checks
1015                         parent: "a.childNodes.length",
1016                         empty: "!a.childNodes.length",
1017                         
1018                         // Text Check
1019                         contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1020                         
1021                         // Visibility
1022                         visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1023                         hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1024                         
1025                         // Form elements
1026                         enabled: "!a.disabled",
1027                         disabled: "a.disabled",
1028                         checked: "a.checked"
1029                 },
1030                 ".": "jQuery.className.has(a,m[2])",
1031                 "@": {
1032                         "=": "z==m[4]",
1033                         "!=": "z!=m[4]",
1034                         "^=": "!z.indexOf(m[4])",
1035                         "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1036                         "*=": "z.indexOf(m[4])>=0",
1037                         "": "z"
1038                 },
1039                 "[": "jQuery.find(m[2],a).length"
1040         },
1041         
1042         token: [
1043                 "\\.\\.|/\\.\\.", "a.parentNode",
1044                 ">|/", "jQuery.sibling(a.firstChild)",
1045                 "\\+", "jQuery.sibling(a).next",
1046                 "~", function(a){
1047                         var r = [];
1048                         var s = jQuery.sibling(a);
1049                         if ( s.n > 0 )
1050                                 for ( var i = s.n; i < s.length; i++ )
1051                                         r.push( s[i] );
1052                         return r;
1053                 }
1054         ],
1055         
1056         /**
1057          *
1058          * @test t( "Element Selector", "div", ["main","foo"] );
1059          * @test t( "Element Selector", "body", ["body"] );
1060          * @test t( "Element Selector", "html", ["html"] );
1061          * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1062          * @test t( "Parent Element", "div div", ["foo"] );
1063          *
1064          * @test t( "ID Selector", "#body", ["body"] );
1065          * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1066          * @test t( "ID Selector w/ Element", "ul#first", [] );
1067          *
1068          * @test t( "Class Selector", ".blog", ["mark","simon"] );
1069          * @test t( "Class Selector", ".blog.link", ["simon"] );
1070          * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1071          * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1072          *
1073          * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1074          * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1075          * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1076          * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1077          *
1078          * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1079          * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1080          * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1081          * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1082          * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1083          * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1084          * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1085          * @test t( "Adjacent", "a + a", ["groups"] );
1086          * @test t( "Adjacent", "a +a", ["groups"] );
1087          * @test t( "Adjacent", "a+ a", ["groups"] );
1088          * @test t( "Adjacent", "a+a", ["groups"] );
1089          * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1090          * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1091          * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1092    * @test t( "Attribute Exists", "a[@title]", ["google"] );
1093          * @test t( "Attribute Exists", "*[@title]", ["google"] );
1094          * @test t( "Attribute Exists", "[@title]", ["google"] );
1095          * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1096          * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1097          * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1098          * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1099          * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1100          * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1101          *
1102          * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1103          * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1104          * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1105          * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1106          * @test t( "Last Child", "p:last-child", ["sap"] );
1107          * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1108          * @test t( "Empty", "ul:empty", ["firstUL"] );
1109          * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1110          * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1111          * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1112          * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1113          * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1114          * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1115          * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1116          *
1117          * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1118          * @test t( "All Div Elements", "//div", ["main","foo"] );
1119          * @test t( "Absolute Path", "/html/body", ["body"] );
1120          * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1121          * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1122          * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1123          * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1124          * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1125          * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1126          * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1127          * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1128          * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1129          * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1130          * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1131          *
1132          * @test t( "nth Element", "p:nth(1)", ["ap"] );
1133          * @test t( "First Element", "p:first", ["firstp"] );
1134          * @test t( "Last Element", "p:last", ["first"] );
1135          * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1136          * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1137          * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1138          * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1139          * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1140          * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1141          * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1142          * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1143          *
1144          * @name jQuery.find
1145          * @private
1146          */
1147         find: function( t, context ) {
1148                 // Make sure that the context is a DOM Element
1149                 if ( context && context.nodeType == undefined )
1150                         context = null;
1151         
1152                 // Set the correct context (if none is provided)
1153                 context = context || jQuery.context || document;
1154         
1155                 if ( t.constructor != String ) return [t];
1156         
1157                 if ( !t.indexOf("//") ) {
1158                         context = context.documentElement;
1159                         t = t.substr(2,t.length);
1160                 } else if ( !t.indexOf("/") ) {
1161                         context = context.documentElement;
1162                         t = t.substr(1,t.length);
1163                         // FIX Assume the root element is right :(
1164                         if ( t.indexOf("/") >= 1 )
1165                                 t = t.substr(t.indexOf("/"),t.length);
1166                 }
1167         
1168                 var ret = [context];
1169                 var done = [];
1170                 var last = null;
1171         
1172                 while ( t.length > 0 && last != t ) {
1173                         var r = [];
1174                         last = t;
1175         
1176                         t = jQuery.trim(t).replace( /^\/\//i, "" );
1177                         
1178                         var foundToken = false;
1179                         
1180                         for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1181                                 var re = new RegExp("^(" + jQuery.token[i] + ")");
1182                                 var m = re.exec(t);
1183                                 
1184                                 if ( m ) {
1185                                         r = ret = jQuery.map( ret, jQuery.token[i+1] );
1186                                         t = jQuery.trim( t.replace( re, "" ) );
1187                                         foundToken = true;
1188                                 }
1189                         }
1190                         
1191                         if ( !foundToken ) {
1192                                 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1193                                         if ( ret[0] == context ) ret.shift();
1194                                         done = jQuery.merge( done, ret );
1195                                         r = ret = [context];
1196                                         t = " " + t.substr(1,t.length);
1197                                 } else {
1198                                         var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1199                                         var m = re2.exec(t);
1200                 
1201                                         if ( m[1] == "#" ) {
1202                                                 // Ummm, should make this work in all XML docs
1203                                                 var oid = document.getElementById(m[2]);
1204                                                 r = ret = oid ? [oid] : [];
1205                                                 t = t.replace( re2, "" );
1206                                         } else {
1207                                                 if ( !m[2] || m[1] == "." ) m[2] = "*";
1208                 
1209                                                 for ( var i = 0; i < ret.length; i++ )
1210                                                         r = jQuery.merge( r,
1211                                                                 m[2] == "*" ?
1212                                                                         jQuery.getAll(ret[i]) :
1213                                                                         ret[i].getElementsByTagName(m[2])
1214                                                         );
1215                                         }
1216                                 }
1217                         }
1218         
1219                         if ( t ) {
1220                                 var val = jQuery.filter(t,r);
1221                                 ret = r = val.r;
1222                                 t = jQuery.trim(val.t);
1223                         }
1224                 }
1225         
1226                 if ( ret && ret[0] == context ) ret.shift();
1227                 done = jQuery.merge( done, ret );
1228         
1229                 return done;
1230         },
1231         
1232         getAll: function(o,r) {
1233                 r = r || [];
1234                 var s = o.childNodes;
1235                 for ( var i = 0; i < s.length; i++ )
1236                         if ( s[i].nodeType == 1 ) {
1237                                 r.push( s[i] );
1238                                 jQuery.getAll( s[i], r );
1239                         }
1240                 return r;
1241         },
1242         
1243         attr: function(o,a,v){
1244                 if ( a && a.constructor == String ) {
1245                         var fix = {
1246                                 "for": "htmlFor",
1247                                 "class": "className",
1248                                 "float": "cssFloat"
1249                         };
1250                         
1251                         a = (fix[a] && fix[a].replace && fix[a] || a)
1252                                 .replace(/-([a-z])/ig,function(z,b){
1253                                         return b.toUpperCase();
1254                                 });
1255                         
1256                         if ( v != undefined ) {
1257                                 o[a] = v;
1258                                 if ( o.setAttribute && a != "disabled" )
1259                                         o.setAttribute(a,v);
1260                         }
1261                         
1262                         return o[a] || o.getAttribute && o.getAttribute(a) || "";
1263                 } else
1264                         return "";
1265         },
1266
1267         // The regular expressions that power the parsing engine
1268         parse: [
1269                 // Match: [@value='test'], [@foo]
1270                 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1271
1272                 // Match: [div], [div p]
1273                 [ "(\\[)Q\\]", 0 ],
1274
1275                 // Match: :contains('foo')
1276                 [ "(:)S\\(Q\\)", 0 ],
1277
1278                 // Match: :even, :last-chlid
1279                 [ "([:.#]*)S", 0 ]
1280         ],
1281         
1282         filter: function(t,r,not) {
1283                 // Figure out if we're doing regular, or inverse, filtering
1284                 var g = not !== false ? jQuery.grep :
1285                         function(a,f) {return jQuery.grep(a,f,true);};
1286                 
1287                 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1288
1289                         var p = jQuery.parse;
1290
1291                         for ( var i = 0; i < p.length; i++ ) {
1292                                 var re = new RegExp( "^" + p[i][0]
1293
1294                                         // Look for a string-like sequence
1295                                         .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1296
1297                                         // Look for something (optionally) enclosed with quotes
1298                                         .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1299
1300                                 var m = re.exec( t );
1301
1302                                 if ( m ) {
1303                                         // Re-organize the match
1304                                         if ( p[i][1] )
1305                                                 m = ["", m[1], m[3], m[2], m[4]];
1306
1307                                         // Remove what we just matched
1308                                         t = t.replace( re, "" );
1309
1310                                         break;
1311                                 }
1312                         }
1313         
1314                         // :not() is a special case that can be optomized by
1315                         // keeping it out of the expression list
1316                         if ( m[1] == ":" && m[2] == "not" )
1317                                 r = jQuery.filter(m[3],r,false).r;
1318                         
1319                         // Otherwise, find the expression to execute
1320                         else {
1321                                 var f = jQuery.expr[m[1]];
1322                                 if ( f.constructor != String )
1323                                         f = jQuery.expr[m[1]][m[2]];
1324                                         
1325                                 // Build a custom macro to enclose it
1326                                 eval("f = function(a,i){" + 
1327                                         ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) + 
1328                                         "return " + f + "}");
1329                                 
1330                                 // Execute it against the current filter
1331                                 r = g( r, f );
1332                         }
1333                 }
1334         
1335                 // Return an array of filtered elements (r)
1336                 // and the modified expression string (t)
1337                 return { r: r, t: t };
1338         },
1339         
1340         /**
1341          * Remove the whitespace from the beginning and end of a string.
1342          *
1343          * @private
1344          * @name jQuery.trim
1345          * @type String
1346          * @param String str The string to trim.
1347          */
1348         trim: function(t){
1349                 return t.replace(/^\s+|\s+$/g, "");
1350         },
1351         
1352         /**
1353          * All ancestors of a given element.
1354          *
1355          * @private
1356          * @name jQuery.parents
1357          * @type Array<Element>
1358          * @param Element elem The element to find the ancestors of.
1359          */
1360         parents: function(a){
1361                 var b = [];
1362                 var c = a.parentNode;
1363                 while ( c && c != document ) {
1364                         b.push( c );
1365                         c = c.parentNode;
1366                 }
1367                 return b;
1368         },
1369         
1370         /**
1371          * All elements on a specified axis.
1372          *
1373          * @private
1374          * @name jQuery.sibling
1375          * @type Array
1376          * @param Element elem The element to find all the siblings of (including itself).
1377          */
1378         sibling: function(a,n) {
1379                 var type = [];
1380                 var tmp = a.parentNode.childNodes;
1381                 for ( var i = 0; i < tmp.length; i++ ) {
1382                         if ( tmp[i].nodeType == 1 )
1383                                 type.push( tmp[i] );
1384                         if ( tmp[i] == a )
1385                                 type.n = type.length - 1;
1386                 }
1387                 type.last = type.n == type.length - 1;
1388                 type.cur =
1389                         n == "even" && type.n % 2 == 0 ||
1390                         n == "odd" && type.n % 2 ||
1391                         type[n] == a;
1392                 type.prev = type[type.n - 1];
1393                 type.next = type[type.n + 1];
1394                 return type;
1395         },
1396         
1397         /**
1398          * Merge two arrays together, removing all duplicates.
1399          *
1400          * @private
1401          * @name jQuery.merge
1402          * @type Array
1403          * @param Array a The first array to merge.
1404          * @param Array b The second array to merge.
1405          */
1406         merge: function(a,b) {
1407                 var d = [];
1408                 
1409                 // Move b over to the new array (this helps to avoid
1410                 // StaticNodeList instances)
1411                 for ( var k = 0; k < a.length; k++ )
1412                         d[k] = a[k];
1413         
1414                 // Now check for duplicates between a and b and only
1415                 // add the unique items
1416                 for ( var i = 0; i < b.length; i++ ) {
1417                         var c = true;
1418                         
1419                         // The collision-checking process
1420                         for ( var j = 0; j < a.length; j++ )
1421                                 if ( b[i] == a[j] )
1422                                         c = false;
1423                                 
1424                         // If the item is unique, add it
1425                         if ( c )
1426                                 d.push( b[i] );
1427                 }
1428         
1429                 return d;
1430         },
1431         
1432         /**
1433          * Remove items that aren't matched in an array. The function passed
1434          * in to this method will be passed two arguments: 'a' (which is the
1435          * array item) and 'i' (which is the index of the item in the array).
1436          *
1437          * @private
1438          * @name jQuery.grep
1439          * @type Array
1440          * @param Array array The Array to find items in.
1441          * @param Function fn The function to process each item against.
1442          * @param Boolean inv Invert the selection - select the opposite of the function.
1443          */
1444         grep: function(a,f,s) {
1445                 // If a string is passed in for the function, make a function
1446                 // for it (a handy shortcut)
1447                 if ( f.constructor == String )
1448                         f = new Function("a","i","return " + f);
1449                         
1450                 var r = [];
1451                 
1452                 // Go through the array, only saving the items
1453                 // that pass the validator function
1454                 for ( var i = 0; i < a.length; i++ )
1455                         if ( !s && f(a[i],i) || s && !f(a[i],i) )
1456                                 r.push( a[i] );
1457                 
1458                 return r;
1459         },
1460         
1461         /**
1462          * Translate all items in array to another array of items. The translation function
1463          * that is provided to this method is passed one argument: 'a' (the item to be 
1464          * translated). If an array is returned, that array is mapped out and merged into
1465          * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1466          * from the array. Both of these changes imply that the size of the array may not
1467          * be the same size upon completion, as it was when it started.
1468          *
1469          * @private
1470          * @name jQuery.map
1471          * @type Array
1472          * @param Array array The Array to translate.
1473          * @param Function fn The function to process each item against.
1474          */
1475         map: function(a,f) {
1476                 // If a string is passed in for the function, make a function
1477                 // for it (a handy shortcut)
1478                 if ( f.constructor == String )
1479                         f = new Function("a","return " + f);
1480                 
1481                 var r = [];
1482                 
1483                 // Go through the array, translating each of the items to their
1484                 // new value (or values).
1485                 for ( var i = 0; i < a.length; i++ ) {
1486                         var t = f(a[i],i);
1487                         if ( t !== null && t != undefined ) {
1488                                 if ( t.constructor != Array ) t = [t];
1489                                 r = jQuery.merge( r, t );
1490                         }
1491                 }
1492                 return r;
1493         },
1494         
1495         /*
1496          * A number of helper functions used for managing events.
1497          * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1498          */
1499         event: {
1500         
1501                 // Bind an event to an element
1502                 // Original by Dean Edwards
1503                 add: function(element, type, handler) {
1504                         // For whatever reason, IE has trouble passing the window object
1505                         // around, causing it to be cloned in the process
1506                         if ( jQuery.browser.msie && element.setInterval != undefined )
1507                                 element = window;
1508                 
1509                         // Make sure that the function being executed has a unique ID
1510                         if ( !handler.guid )
1511                                 handler.guid = this.guid++;
1512                                 
1513                         // Init the element's event structure
1514                         if (!element.events)
1515                                 element.events = {};
1516                         
1517                         // Get the current list of functions bound to this event
1518                         var handlers = element.events[type];
1519                         
1520                         // If it hasn't been initialized yet
1521                         if (!handlers) {
1522                                 // Init the event handler queue
1523                                 handlers = element.events[type] = {};
1524                                 
1525                                 // Remember an existing handler, if it's already there
1526                                 if (element["on" + type])
1527                                         handlers[0] = element["on" + type];
1528                         }
1529
1530                         // Add the function to the element's handler list
1531                         handlers[handler.guid] = handler;
1532                         
1533                         // And bind the global event handler to the element
1534                         element["on" + type] = this.handle;
1535         
1536                         // Remember the function in a global list (for triggering)
1537                         if (!this.global[type])
1538                                 this.global[type] = [];
1539                         this.global[type].push( element );
1540                 },
1541                 
1542                 guid: 1,
1543                 global: {},
1544                 
1545                 // Detach an event or set of events from an element
1546                 remove: function(element, type, handler) {
1547                         if (element.events)
1548                                 if (type && element.events[type])
1549                                         if ( handler )
1550                                                 delete element.events[type][handler.guid];
1551                                         else
1552                                                 for ( var i in element.events[type] )
1553                                                         delete element.events[type][i];
1554                                 else
1555                                         for ( var j in element.events )
1556                                                 this.remove( element, j );
1557                 },
1558                 
1559                 trigger: function(type,data,element) {
1560                         // Touch up the incoming data
1561                         data = data || [];
1562         
1563                         // Handle a global trigger
1564                         if ( !element ) {
1565                                 var g = this.global[type];
1566                                 if ( g )
1567                                         for ( var i = 0; i < g.length; i++ )
1568                                                 this.trigger( type, data, g[i] );
1569         
1570                         // Handle triggering a single element
1571                         } else if ( element["on" + type] ) {
1572                                 // Pass along a fake event
1573                                 data.unshift( this.fix({ type: type, target: element }) );
1574         
1575                                 // Trigger the event
1576                                 element["on" + type].apply( element, data );
1577                         }
1578                 },
1579                 
1580                 handle: function(event) {
1581                         if ( typeof jQuery == "undefined" ) return;
1582
1583                         event = event || jQuery.event.fix( window.event );
1584         
1585                         // If no correct event was found, fail
1586                         if ( !event ) return;
1587                 
1588                         var returnValue = true;
1589
1590                         var c = this.events[event.type];
1591                 
1592                         for ( var j in c ) {
1593                                 if ( c[j].apply( this, [event] ) === false ) {
1594                                         event.preventDefault();
1595                                         event.stopPropagation();
1596                                         returnValue = false;
1597                                 }
1598                         }
1599                         
1600                         return returnValue;
1601                 },
1602                 
1603                 fix: function(event) {
1604                         if ( event ) {
1605                                 event.preventDefault = function() {
1606                                         this.returnValue = false;
1607                                 };
1608                         
1609                                 event.stopPropagation = function() {
1610                                         this.cancelBubble = true;
1611                                 };
1612                         }
1613                         
1614                         return event;
1615                 }
1616         
1617         }
1618 });
1619
1620 new function() {
1621         var b = navigator.userAgent.toLowerCase();
1622
1623         // Figure out what browser is being used
1624         jQuery.browser = {
1625                 safari: /webkit/.test(b),
1626                 opera: /opera/.test(b),
1627                 msie: /msie/.test(b) && !/opera/.test(b),
1628                 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1629         };
1630
1631         // Check to see if the W3C box model is being used
1632         jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1633 };
1634
1635 jQuery.macros = {
1636         to: {
1637                 /**
1638                  * Append all of the matched elements to another, specified, set of elements.
1639                  * This operation is, essentially, the reverse of doing a regular
1640                  * $(A).append(B), in that instead of appending B to A, you're appending
1641                  * A to B.
1642                  * 
1643                  * @example $("p").appendTo("#foo");
1644                  * @before <p>I would like to say: </p><div id="foo"></div>
1645                  * @result <div id="foo"><p>I would like to say: </p></div>
1646                  *
1647                  * @name appendTo
1648                  * @type jQuery
1649                  * @param String expr A jQuery expression of elements to match.
1650                  * @cat DOM/Manipulation
1651                  */
1652                 appendTo: "append",
1653                 
1654                 /**
1655                  * Prepend all of the matched elements to another, specified, set of elements.
1656                  * This operation is, essentially, the reverse of doing a regular
1657                  * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1658                  * A to B.
1659                  * 
1660                  * @example $("p").prependTo("#foo");
1661                  * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1662                  * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1663                  *
1664                  * @name prependTo
1665                  * @type jQuery
1666                  * @param String expr A jQuery expression of elements to match.
1667                  * @cat DOM/Manipulation
1668                  */
1669                 prependTo: "prepend",
1670                 
1671                 /**
1672                  * Insert all of the matched elements before another, specified, set of elements.
1673                  * This operation is, essentially, the reverse of doing a regular
1674                  * $(A).before(B), in that instead of inserting B before A, you're inserting
1675                  * A before B.
1676                  * 
1677                  * @example $("p").insertBefore("#foo");
1678                  * @before <div id="foo">Hello</div><p>I would like to say: </p>
1679                  * @result <p>I would like to say: </p><div id="foo">Hello</div>
1680                  *
1681                  * @name insertBefore
1682                  * @type jQuery
1683                  * @param String expr A jQuery expression of elements to match.
1684                  * @cat DOM/Manipulation
1685                  */
1686                 insertBefore: "before",
1687                 
1688                 /**
1689                  * Insert all of the matched elements after another, specified, set of elements.
1690                  * This operation is, essentially, the reverse of doing a regular
1691                  * $(A).after(B), in that instead of inserting B after A, you're inserting
1692                  * A after B.
1693                  * 
1694                  * @example $("p").insertAfter("#foo");
1695                  * @before <p>I would like to say: </p><div id="foo">Hello</div>
1696                  * @result <div id="foo">Hello</div><p>I would like to say: </p>
1697                  *
1698                  * @name insertAfter
1699                  * @type jQuery
1700                  * @param String expr A jQuery expression of elements to match.
1701                  * @cat DOM/Manipulation
1702                  */
1703                 insertAfter: "after"
1704         },
1705         
1706         /**
1707          * Get the current CSS width of the first matched element.
1708          * 
1709          * @example $("p").width();
1710          * @before <p>This is just a test.</p>
1711          * @result "300px"
1712          *
1713          * @name width
1714          * @type String
1715          * @cat CSS
1716          */
1717          
1718         /**
1719          * Set the CSS width of every matched element. Be sure to include
1720          * the "px" (or other unit of measurement) after the number that you 
1721          * specify, otherwise you might get strange results.
1722          * 
1723          * @example $("p").width("20px");
1724          * @before <p>This is just a test.</p>
1725          * @result <p style="width:20px;">This is just a test.</p>
1726          *
1727          * @name width
1728          * @type jQuery
1729          * @param String val Set the CSS property to the specified value.
1730          * @cat CSS
1731          */
1732         
1733         /**
1734          * Get the current CSS height of the first matched element.
1735          * 
1736          * @example $("p").height();
1737          * @before <p>This is just a test.</p>
1738          * @result "14px"
1739          *
1740          * @name height
1741          * @type String
1742          * @cat CSS
1743          */
1744          
1745         /**
1746          * Set the CSS height of every matched element. Be sure to include
1747          * the "px" (or other unit of measurement) after the number that you 
1748          * specify, otherwise you might get strange results.
1749          * 
1750          * @example $("p").height("20px");
1751          * @before <p>This is just a test.</p>
1752          * @result <p style="height:20px;">This is just a test.</p>
1753          *
1754          * @name height
1755          * @type jQuery
1756          * @param String val Set the CSS property to the specified value.
1757          * @cat CSS
1758          */
1759          
1760         /**
1761          * Get the current CSS top of the first matched element.
1762          * 
1763          * @example $("p").top();
1764          * @before <p>This is just a test.</p>
1765          * @result "0px"
1766          *
1767          * @name top
1768          * @type String
1769          * @cat CSS
1770          */
1771          
1772         /**
1773          * Set the CSS top of every matched element. Be sure to include
1774          * the "px" (or other unit of measurement) after the number that you 
1775          * specify, otherwise you might get strange results.
1776          * 
1777          * @example $("p").top("20px");
1778          * @before <p>This is just a test.</p>
1779          * @result <p style="top:20px;">This is just a test.</p>
1780          *
1781          * @name top
1782          * @type jQuery
1783          * @param String val Set the CSS property to the specified value.
1784          * @cat CSS
1785          */
1786          
1787         /**
1788          * Get the current CSS left of the first matched element.
1789          * 
1790          * @example $("p").left();
1791          * @before <p>This is just a test.</p>
1792          * @result "0px"
1793          *
1794          * @name left
1795          * @type String
1796          * @cat CSS
1797          */
1798          
1799         /**
1800          * Set the CSS left of every matched element. Be sure to include
1801          * the "px" (or other unit of measurement) after the number that you 
1802          * specify, otherwise you might get strange results.
1803          * 
1804          * @example $("p").left("20px");
1805          * @before <p>This is just a test.</p>
1806          * @result <p style="left:20px;">This is just a test.</p>
1807          *
1808          * @name left
1809          * @type jQuery
1810          * @param String val Set the CSS property to the specified value.
1811          * @cat CSS
1812          */
1813          
1814         /**
1815          * Get the current CSS position of the first matched element.
1816          * 
1817          * @example $("p").position();
1818          * @before <p>This is just a test.</p>
1819          * @result "static"
1820          *
1821          * @name position
1822          * @type String
1823          * @cat CSS
1824          */
1825          
1826         /**
1827          * Set the CSS position of every matched element.
1828          * 
1829          * @example $("p").position("relative");
1830          * @before <p>This is just a test.</p>
1831          * @result <p style="position:relative;">This is just a test.</p>
1832          *
1833          * @name position
1834          * @type jQuery
1835          * @param String val Set the CSS property to the specified value.
1836          * @cat CSS
1837          */
1838          
1839         /**
1840          * Get the current CSS float of the first matched element.
1841          * 
1842          * @example $("p").float();
1843          * @before <p>This is just a test.</p>
1844          * @result "none"
1845          *
1846          * @name float
1847          * @type String
1848          * @cat CSS
1849          */
1850          
1851         /**
1852          * Set the CSS float of every matched element.
1853          * 
1854          * @example $("p").float("left");
1855          * @before <p>This is just a test.</p>
1856          * @result <p style="float:left;">This is just a test.</p>
1857          *
1858          * @name float
1859          * @type jQuery
1860          * @param String val Set the CSS property to the specified value.
1861          * @cat CSS
1862          */
1863          
1864         /**
1865          * Get the current CSS overflow of the first matched element.
1866          * 
1867          * @example $("p").overflow();
1868          * @before <p>This is just a test.</p>
1869          * @result "none"
1870          *
1871          * @name overflow
1872          * @type String
1873          * @cat CSS
1874          */
1875          
1876         /**
1877          * Set the CSS overflow of every matched element.
1878          * 
1879          * @example $("p").overflow("auto");
1880          * @before <p>This is just a test.</p>
1881          * @result <p style="overflow:auto;">This is just a test.</p>
1882          *
1883          * @name overflow
1884          * @type jQuery
1885          * @param String val Set the CSS property to the specified value.
1886          * @cat CSS
1887          */
1888          
1889         /**
1890          * Get the current CSS color of the first matched element.
1891          * 
1892          * @example $("p").color();
1893          * @before <p>This is just a test.</p>
1894          * @result "black"
1895          *
1896          * @name color
1897          * @type String
1898          * @cat CSS
1899          */
1900          
1901         /**
1902          * Set the CSS color of every matched element.
1903          * 
1904          * @example $("p").color("blue");
1905          * @before <p>This is just a test.</p>
1906          * @result <p style="color:blue;">This is just a test.</p>
1907          *
1908          * @name color
1909          * @type jQuery
1910          * @param String val Set the CSS property to the specified value.
1911          * @cat CSS
1912          */
1913          
1914         /**
1915          * Get the current CSS background of the first matched element.
1916          * 
1917          * @example $("p").background();
1918          * @before <p>This is just a test.</p>
1919          * @result ""
1920          *
1921          * @name background
1922          * @type String
1923          * @cat CSS
1924          */
1925          
1926         /**
1927          * Set the CSS background of every matched element.
1928          * 
1929          * @example $("p").background("blue");
1930          * @before <p>This is just a test.</p>
1931          * @result <p style="background:blue;">This is just a test.</p>
1932          *
1933          * @name background
1934          * @type jQuery
1935          * @param String val Set the CSS property to the specified value.
1936          * @cat CSS
1937          */
1938         
1939         css: "width,height,top,left,position,float,overflow,color,background".split(","),
1940
1941         filter: [ "eq", "lt", "gt", "contains" ],
1942
1943         attr: {
1944                 /**
1945                  * Get the current value of the first matched element.
1946                  * 
1947                  * @example $("input").val();
1948                  * @before <input type="text" value="some text"/>
1949                  * @result "some text"
1950                  *
1951                  * @name val
1952                  * @type String
1953                  * @cat DOM/Attributes
1954                  */
1955                  
1956                 /**
1957                  * Set the value of every matched element.
1958                  * 
1959                  * @example $("input").value("test");
1960                  * @before <input type="text" value="some text"/>
1961                  * @result <input type="text" value="test"/>
1962                  *
1963                  * @name val
1964                  * @type jQuery
1965                  * @param String val Set the property to the specified value.
1966                  * @cat DOM/Attributes
1967                  */
1968                 val: "value",
1969                 
1970                 /**
1971                  * Get the html contents of the first matched element.
1972                  * 
1973                  * @example $("div").html();
1974                  * @before <div><input/></div>
1975                  * @result <input/>
1976                  *
1977                  * @name html
1978                  * @type String
1979                  * @cat DOM/Attributes
1980                  */
1981                  
1982                 /**
1983                  * Set the html contents of every matched element.
1984                  * 
1985                  * @example $("div").html("<b>new stuff</b>");
1986                  * @before <div><input/></div>
1987                  * @result <div><b>new stuff</b></div>
1988                  *
1989                  * @test var div = $("div");
1990                  * div.html("<b>test</b>");
1991                  * var pass = true;
1992                  * for ( var i = 0; i < div.size(); i++ ) {
1993                  *   if ( div.get(i).childNodes.length == 0 ) pass = false;
1994                  * }
1995                  * ok( pass, "Set HTML" );
1996                  *
1997                  * @name html
1998                  * @type jQuery
1999                  * @param String val Set the html contents to the specified value.
2000                  * @cat DOM/Attributes
2001                  */
2002                 html: "innerHTML",
2003                 
2004                 /**
2005                  * Get the current id of the first matched element.
2006                  * 
2007                  * @example $("input").id();
2008                  * @before <input type="text" id="test" value="some text"/>
2009                  * @result "test"
2010                  *
2011                  * @name id
2012                  * @type String
2013                  * @cat DOM/Attributes
2014                  */
2015                  
2016                 /**
2017                  * Set the id of every matched element.
2018                  * 
2019                  * @example $("input").id("newid");
2020                  * @before <input type="text" id="test" value="some text"/>
2021                  * @result <input type="text" id="newid" value="some text"/>
2022                  *
2023                  * @name id
2024                  * @type jQuery
2025                  * @param String val Set the property to the specified value.
2026                  * @cat DOM/Attributes
2027                  */
2028                 id: null,
2029                 
2030                 /**
2031                  * Get the current title of the first matched element.
2032                  * 
2033                  * @example $("img").title();
2034                  * @before <img src="test.jpg" title="my image"/>
2035                  * @result "my image"
2036                  *
2037                  * @name title
2038                  * @type String
2039                  * @cat DOM/Attributes
2040                  */
2041                  
2042                 /**
2043                  * Set the title of every matched element.
2044                  * 
2045                  * @example $("img").title("new title");
2046                  * @before <img src="test.jpg" title="my image"/>
2047                  * @result <img src="test.jpg" title="new image"/>
2048                  *
2049                  * @name title
2050                  * @type jQuery
2051                  * @param String val Set the property to the specified value.
2052                  * @cat DOM/Attributes
2053                  */
2054                 title: null,
2055                 
2056                 /**
2057                  * Get the current name of the first matched element.
2058                  * 
2059                  * @example $("input").name();
2060                  * @before <input type="text" name="username"/>
2061                  * @result "username"
2062                  *
2063                  * @name name
2064                  * @type String
2065                  * @cat DOM/Attributes
2066                  */
2067                  
2068                 /**
2069                  * Set the name of every matched element.
2070                  * 
2071                  * @example $("input").name("user");
2072                  * @before <input type="text" name="username"/>
2073                  * @result <input type="text" name="user"/>
2074                  *
2075                  * @name name
2076                  * @type jQuery
2077                  * @param String val Set the property to the specified value.
2078                  * @cat DOM/Attributes
2079                  */
2080                 name: null,
2081                 
2082                 /**
2083                  * Get the current href of the first matched element.
2084                  * 
2085                  * @example $("a").href();
2086                  * @before <a href="test.html">my link</a>
2087                  * @result "test.html"
2088                  *
2089                  * @name href
2090                  * @type String
2091                  * @cat DOM/Attributes
2092                  */
2093                  
2094                 /**
2095                  * Set the href of every matched element.
2096                  * 
2097                  * @example $("a").href("test2.html");
2098                  * @before <a href="test.html">my link</a>
2099                  * @result <a href="test2.html">my link</a>
2100                  *
2101                  * @name href
2102                  * @type jQuery
2103                  * @param String val Set the property to the specified value.
2104                  * @cat DOM/Attributes
2105                  */
2106                 href: null,
2107                 
2108                 /**
2109                  * Get the current src of the first matched element.
2110                  * 
2111                  * @example $("img").src();
2112                  * @before <img src="test.jpg" title="my image"/>
2113                  * @result "test.jpg"
2114                  *
2115                  * @name src
2116                  * @type String
2117                  * @cat DOM/Attributes
2118                  */
2119                  
2120                 /**
2121                  * Set the src of every matched element.
2122                  * 
2123                  * @example $("img").src("test2.jpg");
2124                  * @before <img src="test.jpg" title="my image"/>
2125                  * @result <img src="test2.jpg" title="my image"/>
2126                  *
2127                  * @name src
2128                  * @type jQuery
2129                  * @param String val Set the property to the specified value.
2130                  * @cat DOM/Attributes
2131                  */
2132                 src: null,
2133                 
2134                 /**
2135                  * Get the current rel of the first matched element.
2136                  * 
2137                  * @example $("a").rel();
2138                  * @before <a href="test.html" rel="nofollow">my link</a>
2139                  * @result "nofollow"
2140                  *
2141                  * @name rel
2142                  * @type String
2143                  * @cat DOM/Attributes
2144                  */
2145                  
2146                 /**
2147                  * Set the rel of every matched element.
2148                  * 
2149                  * @example $("a").rel("nofollow");
2150                  * @before <a href="test.html">my link</a>
2151                  * @result <a href="test.html" rel="nofollow">my link</a>
2152                  *
2153                  * @name rel
2154                  * @type jQuery
2155                  * @param String val Set the property to the specified value.
2156                  * @cat DOM/Attributes
2157                  */
2158                 rel: null
2159         },
2160         
2161         axis: {
2162                 /**
2163                  * Get a set of elements containing the unique parents of the matched
2164                  * set of elements.
2165                  *
2166                  * @example $("p").parent()
2167                  * @before <div><p>Hello</p><p>Hello</p></div>
2168                  * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2169                  *
2170                  * @name parent
2171                  * @type jQuery
2172                  * @cat DOM/Traversing
2173                  */
2174
2175                 /**
2176                  * Get a set of elements containing the unique parents of the matched
2177                  * set of elements, and filtered by an expression.
2178                  *
2179                  * @example $("p").parent(".selected")
2180                  * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2181                  * @result [ <div class="selected"><p>Hello Again</p></div> ]
2182                  *
2183                  * @name parent
2184                  * @type jQuery
2185                  * @param String expr An expression to filter the parents with
2186                  * @cat DOM/Traversing
2187                  */
2188                 parent: "a.parentNode",
2189
2190                 /**
2191                  * Get a set of elements containing the unique ancestors of the matched
2192                  * set of elements.
2193                  *
2194                  * @example $("span").ancestors()
2195                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2196                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 
2197                  *
2198                  * @name ancestors
2199                  * @type jQuery
2200                  * @cat DOM/Traversing
2201                  */
2202
2203                 /**
2204                  * Get a set of elements containing the unique ancestors of the matched
2205                  * set of elements, and filtered by an expression.
2206                  *
2207                  * @example $("span").ancestors("p")
2208                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2209                  * @result [ <p><span>Hello</span></p> ] 
2210                  *
2211                  * @name ancestors
2212                  * @type jQuery
2213                  * @param String expr An expression to filter the ancestors with
2214                  * @cat DOM/Traversing
2215                  */
2216                 ancestors: jQuery.parents,
2217                 
2218                 /**
2219                  * Get a set of elements containing the unique ancestors of the matched
2220                  * set of elements.
2221                  *
2222                  * @example $("span").ancestors()
2223                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2224                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 
2225                  *
2226                  * @name parents
2227                  * @type jQuery
2228                  * @cat DOM/Traversing
2229                  */
2230
2231                 /**
2232                  * Get a set of elements containing the unique ancestors of the matched
2233                  * set of elements, and filtered by an expression.
2234                  *
2235                  * @example $("span").ancestors("p")
2236                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2237                  * @result [ <p><span>Hello</span></p> ] 
2238                  *
2239                  * @name parents
2240                  * @type jQuery
2241                  * @param String expr An expression to filter the ancestors with
2242                  * @cat DOM/Traversing
2243                  */
2244                 parents: jQuery.parents,
2245
2246                 /**
2247                  * Get a set of elements containing the unique next siblings of each of the 
2248                  * matched set of elements.
2249                  * 
2250                  * It only returns the very next sibling, not all next siblings.
2251                  *
2252                  * @example $("p").next()
2253                  * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2254                  * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2255                  *
2256                  * @name next
2257                  * @type jQuery
2258                  * @cat DOM/Traversing
2259                  */
2260
2261                 /**
2262                  * Get a set of elements containing the unique next siblings of each of the 
2263                  * matched set of elements, and filtered by an expression.
2264                  * 
2265                  * It only returns the very next sibling, not all next siblings.
2266                  *
2267                  * @example $("p").next(".selected")
2268                  * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2269                  * @result [ <p class="selected">Hello Again</p> ]
2270                  *
2271                  * @name next
2272                  * @type jQuery
2273                  * @param String expr An expression to filter the next Elements with
2274                  * @cat DOM/Traversing
2275                  */
2276                 next: "jQuery.sibling(a).next",
2277
2278                 /**
2279                  * Get a set of elements containing the unique previous siblings of each of the 
2280                  * matched set of elements.
2281                  * 
2282                  * It only returns the immediately previous sibling, not all previous siblings.
2283                  *
2284                  * @example $("p").previous()
2285                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2286                  * @result [ <div><span>Hello Again</span></div> ]
2287                  *
2288                  * @name prev
2289                  * @type jQuery
2290                  * @cat DOM/Traversing
2291                  */
2292
2293                 /**
2294                  * Get a set of elements containing the unique previous siblings of each of the 
2295                  * matched set of elements, and filtered by an expression.
2296                  * 
2297                  * It only returns the immediately previous sibling, not all previous siblings.
2298                  *
2299                  * @example $("p").previous(".selected")
2300                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2301                  * @result [ <div><span>Hello</span></div> ]
2302                  *
2303                  * @name prev
2304                  * @type jQuery
2305                  * @param String expr An expression to filter the previous Elements with
2306                  * @cat DOM/Traversing
2307                  */
2308                 prev: "jQuery.sibling(a).prev",
2309
2310                 /**
2311                  * Get a set of elements containing all of the unique siblings of each of the 
2312                  * matched set of elements.
2313                  * 
2314                  * @example $("div").siblings()
2315                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2316                  * @result [ <p>Hello</p>, <p>And Again</p> ]
2317                  *
2318                  * @name siblings
2319                  * @type jQuery
2320                  * @cat DOM/Traversing
2321                  */
2322
2323                 /**
2324                  * Get a set of elements containing all of the unique siblings of each of the 
2325                  * matched set of elements, and filtered by an expression.
2326                  *
2327                  * @example $("div").siblings(".selected")
2328                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2329                  * @result [ <p class="selected">Hello Again</p> ]
2330                  *
2331                  * @name siblings
2332                  * @type jQuery
2333                  * @param String expr An expression to filter the sibling Elements with
2334                  * @cat DOM/Traversing
2335                  */
2336                 siblings: jQuery.sibling,
2337                 
2338                 
2339                 /**
2340                  * Get a set of elements containing all of the unique children of each of the 
2341                  * matched set of elements.
2342                  * 
2343                  * @example $("div").children()
2344                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2345                  * @result [ <span>Hello Again</span> ]
2346                  *
2347                  * @name children
2348                  * @type jQuery
2349                  * @cat DOM/Traversing
2350                  */
2351
2352                 /**
2353                  * Get a set of elements containing all of the unique children of each of the 
2354                  * matched set of elements, and filtered by an expression.
2355                  *
2356                  * @example $("div").children(".selected")
2357                  * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2358                  * @result [ <p class="selected">Hello Again</p> ]
2359                  *
2360                  * @name children
2361                  * @type jQuery
2362                  * @param String expr An expression to filter the child Elements with
2363                  * @cat DOM/Traversing
2364                  */
2365                 children: "a.childNodes"
2366         },
2367
2368         each: {
2369                 /**
2370                  * Displays each of the set of matched elements if they are hidden.
2371                  * 
2372                  * @example $("p").show()
2373                  * @before <p style="display: none">Hello</p>
2374                  * @result [ <p style="display: block">Hello</p> ]
2375                  *
2376                  * @test var pass = true, div = $("div");
2377                  * div.show().each(function(){
2378                  *   if ( this.style.display == "none" ) pass = false;
2379                  * });
2380                  * ok( pass, "Show" );
2381                  *
2382                  * @name show
2383                  * @type jQuery
2384                  * @cat Effects
2385                  */
2386                 _show: function(){
2387                         this.style.display = this.oldblock ? this.oldblock : "";
2388                         if ( jQuery.css(this,"display") == "none" )
2389                                 this.style.display = "block";
2390                 },
2391
2392                 /**
2393                  * Hides each of the set of matched elements if they are shown.
2394                  *
2395                  * @example $("p").hide()
2396                  * @before <p>Hello</p>
2397                  * @result [ <p style="display: none">Hello</p> ]
2398                  *
2399                  * var pass = true, div = $("div");
2400                  * div.hide().each(function(){
2401                  *   if ( this.style.display != "none" ) pass = false;
2402                  * });
2403                  * ok( pass, "Hide" );
2404                  *
2405                  * @name hide
2406                  * @type jQuery
2407                  * @cat Effects
2408                  */
2409                 _hide: function(){
2410                         this.oldblock = this.oldblock || jQuery.css(this,"display");
2411                         if ( this.oldblock == "none" )
2412                                 this.oldblock = "block";
2413                         this.style.display = "none";
2414                 },
2415                 
2416                 /**
2417                  * Toggles each of the set of matched elements. If they are shown,
2418                  * toggle makes them hidden. If they are hidden, toggle
2419                  * makes them shown.
2420                  *
2421                  * @example $("p").toggle()
2422                  * @before <p>Hello</p><p style="display: none">Hello Again</p>
2423                  * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2424                  *
2425                  * @name toggle
2426                  * @type jQuery
2427                  * @cat Effects
2428                  */
2429                 _toggle: function(){
2430                         var d = jQuery.css(this,"display");
2431                         $(this)[ !d || d == "none" ? "show" : "hide" ]();
2432                 },
2433                 
2434                 /**
2435                  * Adds the specified class to each of the set of matched elements.
2436                  *
2437                  * @example $("p").addClass("selected")
2438                  * @before <p>Hello</p>
2439                  * @result [ <p class="selected">Hello</p> ]
2440                  *
2441                  * @test var div = $("div");
2442                  * div.addClass("test");
2443                  * var pass = true;
2444                  * for ( var i = 0; i < div.size(); i++ ) {
2445                  *  if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2446                  * }
2447                  * ok( pass, "Add Class" );
2448                  * 
2449                  * @name addClass
2450                  * @type jQuery
2451                  * @param String class A CSS class to add to the elements
2452                  * @cat DOM
2453                  */
2454                 addClass: function(c){
2455                         jQuery.className.add(this,c);
2456                 },
2457                 
2458                 /**
2459                  * Removes the specified class from the set of matched elements.
2460                  *
2461                  * @example $("p").removeClass("selected")
2462                  * @before <p class="selected">Hello</p>
2463                  * @result [ <p>Hello</p> ]
2464                  *
2465                  * @test var div = $("div").addClass("test");
2466                  * div.removeClass("test");
2467                  * var pass = true;
2468                  * for ( var i = 0; i < div.size(); i++ ) {
2469                  *  if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2470                  * }
2471                  * ok( pass, "Remove Class" );
2472                  *
2473                  * @name removeClass
2474                  * @type jQuery
2475                  * @param String class A CSS class to remove from the elements
2476                  * @cat DOM
2477                  */
2478                 removeClass: function(c){
2479                         jQuery.className.remove(this,c);
2480                 },
2481         
2482                 /**
2483                  * Adds the specified class if it is present, removes it if it is
2484                  * not present.
2485                  *
2486                  * @example $("p").toggleClass("selected")
2487                  * @before <p>Hello</p><p class="selected">Hello Again</p>
2488                  * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2489                  *
2490                  * @name toggleClass
2491                  * @type jQuery
2492                  * @param String class A CSS class with which to toggle the elements
2493                  * @cat DOM
2494                  */
2495                 toggleClass: function( c ){
2496                         jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2497                 },
2498                 
2499                 /**
2500                  * Removes all matched elements from the DOM. This does NOT remove them from the
2501                  * jQuery object, allowing you to use the matched elements further.
2502                  *
2503                  * @example $("p").remove();
2504                  * @before <p>Hello</p> how are <p>you?</p>
2505                  * @result how are
2506                  *
2507                  * @name remove
2508                  * @type jQuery
2509                  * @cat DOM/Manipulation
2510                  */
2511                  
2512                 /**
2513                  * Removes only elements (out of the list of matched elements) that match
2514                  * the specified jQuery expression. This does NOT remove them from the
2515                  * jQuery object, allowing you to use the matched elements further.
2516                  *
2517                  * @example $("p").remove(".hello");
2518                  * @before <p class="hello">Hello</p> how are <p>you?</p>
2519                  * @result how are <p>you?</p>
2520                  *
2521                  * @name remove
2522                  * @type jQuery
2523                  * @param String expr A jQuery expression to filter elements by.
2524                  * @cat DOM/Manipulation
2525                  */
2526                 remove: function(a){
2527                         if ( !a || jQuery.filter( [this], a ).r )
2528                                 this.parentNode.removeChild( this );
2529                 },
2530         
2531                 /**
2532                  * Removes all child nodes from the set of matched elements.
2533                  *
2534                  * @example $("p").empty()
2535                  * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2536                  * @result [ <p></p> ]
2537                  *
2538                  * @name empty
2539                  * @type jQuery
2540                  * @cat DOM/Manipulation
2541                  */
2542                 empty: function(){
2543                         while ( this.firstChild )
2544                                 this.removeChild( this.firstChild );
2545                 },
2546                 
2547                 /**
2548                  * Binds a particular event (like click) to a each of a set of match elements.
2549                  *
2550                  * @example $("p").bind( "click", function() { alert("Hello"); } )
2551                  * @before <p>Hello</p>
2552                  * @result [ <p>Hello</p> ]
2553                  *
2554                  * Cancel a default action and prevent it from bubbling by returning false
2555                  * from your function.
2556                  *
2557                  * @example $("form").bind( "submit", function() { return false; } )
2558                  *
2559                  * Cancel a default action by using the preventDefault method.
2560                  *
2561                  * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2562                  *
2563                  * Stop an event from bubbling by using the stopPropogation method.
2564                  *
2565                  * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2566                  *
2567                  * @name bind
2568                  * @type jQuery
2569                  * @param String type An event type
2570                  * @param Function fn A function to bind to the event on each of the set of matched elements
2571                  * @cat Events
2572                  */
2573                 bind: function( type, fn ) {
2574                         if ( fn.constructor == String )
2575                                 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2576                         jQuery.event.add( this, type, fn );
2577                 },
2578                 
2579                 /**
2580                  * The opposite of bind, removes a bound event from each of the matched
2581                  * elements. You must pass the identical function that was used in the original 
2582                  * bind method.
2583                  *
2584                  * @example $("p").unbind( "click", function() { alert("Hello"); } )
2585                  * @before <p onclick="alert('Hello');">Hello</p>
2586                  * @result [ <p>Hello</p> ]
2587                  *
2588                  * @name unbind
2589                  * @type jQuery
2590                  * @param String type An event type
2591                  * @param Function fn A function to unbind from the event on each of the set of matched elements
2592                  * @cat Events
2593                  */
2594                  
2595                 /**
2596                  * Removes all bound events of a particular type from each of the matched
2597                  * elements.
2598                  *
2599                  * @example $("p").unbind( "click" )
2600                  * @before <p onclick="alert('Hello');">Hello</p>
2601                  * @result [ <p>Hello</p> ]
2602                  *
2603                  * @name unbind
2604                  * @type jQuery
2605                  * @param String type An event type
2606                  * @cat Events
2607                  */
2608                  
2609                 /**
2610                  * Removes all bound events from each of the matched elements.
2611                  *
2612                  * @example $("p").unbind()
2613                  * @before <p onclick="alert('Hello');">Hello</p>
2614                  * @result [ <p>Hello</p> ]
2615                  *
2616                  * @name unbind
2617                  * @type jQuery
2618                  * @cat Events
2619                  */
2620                 unbind: function( type, fn ) {
2621                         jQuery.event.remove( this, type, fn );
2622                 },
2623                 
2624                 /**
2625                  * Trigger a type of event on every matched element.
2626                  *
2627                  * @example $("p").trigger("click")
2628                  * @before <p click="alert('hello')">Hello</p>
2629                  * @result alert('hello')
2630                  *
2631                  * @name trigger
2632                  * @type jQuery
2633                  * @param String type An event type to trigger.
2634                  * @cat Events
2635                  */
2636                 trigger: function( type, data ) {
2637                         jQuery.event.trigger( type, data, this );
2638                 }
2639         }
2640 };