Massive overhauls to the test suite - it is now generated dynamically, along with...
[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" ) {
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                                 if ( !a[i].indexOf("<tr") ) {
963                                         var tr = true;
964                                         a[i] = "<table>" + a[i] + "</table>";
965                                 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
966                                         var td = true;
967                                         a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
968                                 }
969         
970                                 var div = document.createElement("div");
971                                 div.innerHTML = a[i];
972         
973                                 if ( tr || td ) {
974                                         div = div.firstChild.firstChild;
975                                         if ( td ) div = div.firstChild;
976                                 }
977         
978                                 for ( var j = 0; j < div.childNodes.length; j++ )
979                                         r.push( div.childNodes[j] );
980                         } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
981                                 for ( var k = 0; k < a[i].length; k++ )
982                                         r.push( a[i][k] );
983                         else if ( a[i] !== null )
984                                 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
985                 }
986                 return r;
987         },
988         
989         expr: {
990                 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
991                 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
992                 ":": {
993                         // Position Checks
994                         lt: "i<m[3]-0",
995                         gt: "i>m[3]-0",
996                         nth: "m[3]-0==i",
997                         eq: "m[3]-0==i",
998                         first: "i==0",
999                         last: "i==r.length-1",
1000                         even: "i%2==0",
1001                         odd: "i%2",
1002                         
1003                         // Child Checks
1004                         "first-child": "jQuery.sibling(a,0).cur",
1005                         "last-child": "jQuery.sibling(a,0).last",
1006                         "only-child": "jQuery.sibling(a).length==1",
1007                         
1008                         // Parent Checks
1009                         parent: "a.childNodes.length",
1010                         empty: "!a.childNodes.length",
1011                         
1012                         // Text Check
1013                         contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1014                         
1015                         // Visibility
1016                         visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1017                         hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1018                         
1019                         // Form elements
1020                         enabled: "!a.disabled",
1021                         disabled: "a.disabled",
1022                         checked: "a.checked"
1023                 },
1024                 ".": "jQuery.className.has(a,m[2])",
1025                 "@": {
1026                         "=": "z==m[4]",
1027                         "!=": "z!=m[4]",
1028                         "^=": "!z.indexOf(m[4])",
1029                         "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1030                         "*=": "z.indexOf(m[4])>=0",
1031                         "": "z"
1032                 },
1033                 "[": "jQuery.find(m[2],a).length"
1034         },
1035         
1036         token: [
1037                 "\\.\\.|/\\.\\.", "a.parentNode",
1038                 ">|/", "jQuery.sibling(a.firstChild)",
1039                 "\\+", "jQuery.sibling(a).next",
1040                 "~", function(a){
1041                         var r = [];
1042                         var s = jQuery.sibling(a);
1043                         if ( s.n > 0 )
1044                                 for ( var i = s.n; i < s.length; i++ )
1045                                         r.push( s[i] );
1046                         return r;
1047                 }
1048         ],
1049         
1050         /**
1051          *
1052          * @test t( "Element Selector", "div", ["main","foo"] );
1053          * @test t( "Element Selector", "body", ["body"] );
1054          * @test t( "Element Selector", "html", ["html"] );
1055          * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1056          * @test t( "Parent Element", "div div", ["foo"] );
1057          *
1058          * @test t( "ID Selector", "#body", ["body"] );
1059          * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1060          * @test t( "ID Selector w/ Element", "ul#first", [] );
1061          *
1062          * @test t( "Class Selector", ".blog", ["mark","simon"] );
1063          * @test t( "Class Selector", ".blog.link", ["simon"] );
1064          * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1065          * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1066          *
1067          * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1068          * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1069          * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1070          * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1071          *
1072          * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1073          * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1074          * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1075          * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1076          * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1077          * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1078          * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1079          * @test t( "Adjacent", "a + a", ["groups"] );
1080          * @test t( "Adjacent", "a +a", ["groups"] );
1081          * @test t( "Adjacent", "a+ a", ["groups"] );
1082          * @test t( "Adjacent", "a+a", ["groups"] );
1083          * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1084          * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1085          * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1086    * @test t( "Attribute Exists", "a[@title]", ["google"] );
1087          * @test t( "Attribute Exists", "*[@title]", ["google"] );
1088          * @test t( "Attribute Exists", "[@title]", ["google"] );
1089          * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1090          * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1091          * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1092          *
1093          * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1094          * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1095          * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1096          * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1097          * @test t( "Last Child", "p:last-child", ["sap"] );
1098          * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1099          * @test t( "Empty", "ul:empty", ["firstUL"] );
1100          * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1101          * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1102          * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1103          * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1104          * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1105          * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1106          * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1107          *
1108          * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1109          * @test t( "All Div Elements", "//div", ["main","foo"] );
1110          * @test t( "Absolute Path", "/html/body", ["body"] );
1111          * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1112          * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1113          * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1114          * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1115          * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1116          * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1117          * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1118          * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1119          * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1120          * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1121          * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1122          *
1123          * @test t( "nth Element", "p:nth(1)", ["ap"] );
1124          * @test t( "First Element", "p:first", ["firstp"] );
1125          * @test t( "Last Element", "p:last", ["first"] );
1126          * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1127          * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1128          * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1129          * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1130          * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1131          * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1132          * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1133          * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1134          *
1135          * @name jQuery.find
1136          * @private
1137          */
1138         find: function( t, context ) {
1139                 // Make sure that the context is a DOM Element
1140                 if ( context && context.nodeType == undefined )
1141                         context = null;
1142         
1143                 // Set the correct context (if none is provided)
1144                 context = context || jQuery.context || document;
1145         
1146                 if ( t.constructor != String ) return [t];
1147         
1148                 if ( !t.indexOf("//") ) {
1149                         context = context.documentElement;
1150                         t = t.substr(2,t.length);
1151                 } else if ( !t.indexOf("/") ) {
1152                         context = context.documentElement;
1153                         t = t.substr(1,t.length);
1154                         // FIX Assume the root element is right :(
1155                         if ( t.indexOf("/") >= 1 )
1156                                 t = t.substr(t.indexOf("/"),t.length);
1157                 }
1158         
1159                 var ret = [context];
1160                 var done = [];
1161                 var last = null;
1162         
1163                 while ( t.length > 0 && last != t ) {
1164                         var r = [];
1165                         last = t;
1166         
1167                         t = jQuery.trim(t).replace( /^\/\//i, "" );
1168                         
1169                         var foundToken = false;
1170                         
1171                         for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1172                                 var re = new RegExp("^(" + jQuery.token[i] + ")");
1173                                 var m = re.exec(t);
1174                                 
1175                                 if ( m ) {
1176                                         r = ret = jQuery.map( ret, jQuery.token[i+1] );
1177                                         t = jQuery.trim( t.replace( re, "" ) );
1178                                         foundToken = true;
1179                                 }
1180                         }
1181                         
1182                         if ( !foundToken ) {
1183                                 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1184                                         if ( ret[0] == context ) ret.shift();
1185                                         done = jQuery.merge( done, ret );
1186                                         r = ret = [context];
1187                                         t = " " + t.substr(1,t.length);
1188                                 } else {
1189                                         var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1190                                         var m = re2.exec(t);
1191                 
1192                                         if ( m[1] == "#" ) {
1193                                                 // Ummm, should make this work in all XML docs
1194                                                 var oid = document.getElementById(m[2]);
1195                                                 r = ret = oid ? [oid] : [];
1196                                                 t = t.replace( re2, "" );
1197                                         } else {
1198                                                 if ( !m[2] || m[1] == "." ) m[2] = "*";
1199                 
1200                                                 for ( var i = 0; i < ret.length; i++ )
1201                                                         r = jQuery.merge( r,
1202                                                                 m[2] == "*" ?
1203                                                                         jQuery.getAll(ret[i]) :
1204                                                                         ret[i].getElementsByTagName(m[2])
1205                                                         );
1206                                         }
1207                                 }
1208                         }
1209         
1210                         if ( t ) {
1211                                 var val = jQuery.filter(t,r);
1212                                 ret = r = val.r;
1213                                 t = jQuery.trim(val.t);
1214                         }
1215                 }
1216         
1217                 if ( ret && ret[0] == context ) ret.shift();
1218                 done = jQuery.merge( done, ret );
1219         
1220                 return done;
1221         },
1222         
1223         getAll: function(o,r) {
1224                 r = r || [];
1225                 var s = o.childNodes;
1226                 for ( var i = 0; i < s.length; i++ )
1227                         if ( s[i].nodeType == 1 ) {
1228                                 r.push( s[i] );
1229                                 jQuery.getAll( s[i], r );
1230                         }
1231                 return r;
1232         },
1233         
1234         attr: function(o,a,v){
1235                 if ( a && a.constructor == String ) {
1236                         var fix = {
1237                                 "for": "htmlFor",
1238                                 "class": "className",
1239                                 "float": "cssFloat"
1240                         };
1241                         
1242                         a = (fix[a] && fix[a].replace && fix[a] || a)
1243                                 .replace(/-([a-z])/ig,function(z,b){
1244                                         return b.toUpperCase();
1245                                 });
1246                         
1247                         if ( v != undefined ) {
1248                                 o[a] = v;
1249                                 if ( o.setAttribute && a != "disabled" )
1250                                         o.setAttribute(a,v);
1251                         }
1252                         
1253                         return o[a] || o.getAttribute && o.getAttribute(a) || "";
1254                 } else
1255                         return "";
1256         },
1257
1258         // The regular expressions that power the parsing engine
1259         parse: [
1260                 // Match: [@value='test'], [@foo]
1261                 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1262
1263                 // Match: [div], [div p]
1264                 [ "(\\[)Q\\]", 0 ],
1265
1266                 // Match: :contains('foo')
1267                 [ "(:)S\\(Q\\)", 0 ],
1268
1269                 // Match: :even, :last-chlid
1270                 [ "([:.#]*)S", 0 ]
1271         ],
1272         
1273         filter: function(t,r,not) {
1274                 // Figure out if we're doing regular, or inverse, filtering
1275                 var g = not !== false ? jQuery.grep :
1276                         function(a,f) {return jQuery.grep(a,f,true);};
1277                 
1278                 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1279
1280                         var p = jQuery.parse;
1281
1282                         for ( var i = 0; i < p.length; i++ ) {
1283                                 var re = new RegExp( "^" + p[i][0]
1284
1285                                         // Look for a string-like sequence
1286                                         .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1287
1288                                         // Look for something (optionally) enclosed with quotes
1289                                         .replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
1290
1291                                 var m = re.exec( t );
1292
1293                                 if ( m ) {
1294                                         // Re-organize the match
1295                                         if ( p[i][1] )
1296                                                 m = ["", m[1], m[3], m[2], m[4]];
1297
1298                                         // Remove what we just matched
1299                                         t = t.replace( re, "" );
1300
1301                                         break;
1302                                 }
1303                         }
1304         
1305                         // :not() is a special case that can be optomized by
1306                         // keeping it out of the expression list
1307                         if ( m[1] == ":" && m[2] == "not" )
1308                                 r = jQuery.filter(m[3],r,false).r;
1309                         
1310                         // Otherwise, find the expression to execute
1311                         else {
1312                                 var f = jQuery.expr[m[1]];
1313                                 if ( f.constructor != String )
1314                                         f = jQuery.expr[m[1]][m[2]];
1315                                         
1316                                 // Build a custom macro to enclose it
1317                                 eval("f = function(a,i){" + 
1318                                         ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) + 
1319                                         "return " + f + "}");
1320                                 
1321                                 // Execute it against the current filter
1322                                 r = g( r, f );
1323                         }
1324                 }
1325         
1326                 // Return an array of filtered elements (r)
1327                 // and the modified expression string (t)
1328                 return { r: r, t: t };
1329         },
1330         
1331         /**
1332          * Remove the whitespace from the beginning and end of a string.
1333          *
1334          * @private
1335          * @name jQuery.trim
1336          * @type String
1337          * @param String str The string to trim.
1338          */
1339         trim: function(t){
1340                 return t.replace(/^\s+|\s+$/g, "");
1341         },
1342         
1343         /**
1344          * All ancestors of a given element.
1345          *
1346          * @private
1347          * @name jQuery.parents
1348          * @type Array<Element>
1349          * @param Element elem The element to find the ancestors of.
1350          */
1351         parents: function(a){
1352                 var b = [];
1353                 var c = a.parentNode;
1354                 while ( c && c != document ) {
1355                         b.push( c );
1356                         c = c.parentNode;
1357                 }
1358                 return b;
1359         },
1360         
1361         /**
1362          * All elements on a specified axis.
1363          *
1364          * @private
1365          * @name jQuery.sibling
1366          * @type Array
1367          * @param Element elem The element to find all the siblings of (including itself).
1368          */
1369         sibling: function(a,n) {
1370                 var type = [];
1371                 var tmp = a.parentNode.childNodes;
1372                 for ( var i = 0; i < tmp.length; i++ ) {
1373                         if ( tmp[i].nodeType == 1 )
1374                                 type.push( tmp[i] );
1375                         if ( tmp[i] == a )
1376                                 type.n = type.length - 1;
1377                 }
1378                 type.last = type.n == type.length - 1;
1379                 type.cur =
1380                         n == "even" && type.n % 2 == 0 ||
1381                         n == "odd" && type.n % 2 ||
1382                         type[n] == a;
1383                 type.prev = type[type.n - 1];
1384                 type.next = type[type.n + 1];
1385                 return type;
1386         },
1387         
1388         /**
1389          * Merge two arrays together, removing all duplicates.
1390          *
1391          * @private
1392          * @name jQuery.merge
1393          * @type Array
1394          * @param Array a The first array to merge.
1395          * @param Array b The second array to merge.
1396          */
1397         merge: function(a,b) {
1398                 var d = [];
1399                 
1400                 // Move b over to the new array (this helps to avoid
1401                 // StaticNodeList instances)
1402                 for ( var k = 0; k < a.length; k++ )
1403                         d[k] = a[k];
1404         
1405                 // Now check for duplicates between a and b and only
1406                 // add the unique items
1407                 for ( var i = 0; i < b.length; i++ ) {
1408                         var c = true;
1409                         
1410                         // The collision-checking process
1411                         for ( var j = 0; j < a.length; j++ )
1412                                 if ( b[i] == a[j] )
1413                                         c = false;
1414                                 
1415                         // If the item is unique, add it
1416                         if ( c )
1417                                 d.push( b[i] );
1418                 }
1419         
1420                 return d;
1421         },
1422         
1423         /**
1424          * Remove items that aren't matched in an array. The function passed
1425          * in to this method will be passed two arguments: 'a' (which is the
1426          * array item) and 'i' (which is the index of the item in the array).
1427          *
1428          * @private
1429          * @name jQuery.grep
1430          * @type Array
1431          * @param Array array The Array to find items in.
1432          * @param Function fn The function to process each item against.
1433          * @param Boolean inv Invert the selection - select the opposite of the function.
1434          */
1435         grep: function(a,f,s) {
1436                 // If a string is passed in for the function, make a function
1437                 // for it (a handy shortcut)
1438                 if ( f.constructor == String )
1439                         f = new Function("a","i","return " + f);
1440                         
1441                 var r = [];
1442                 
1443                 // Go through the array, only saving the items
1444                 // that pass the validator function
1445                 for ( var i = 0; i < a.length; i++ )
1446                         if ( !s && f(a[i],i) || s && !f(a[i],i) )
1447                                 r.push( a[i] );
1448                 
1449                 return r;
1450         },
1451         
1452         /**
1453          * Translate all items in array to another array of items. The translation function
1454          * that is provided to this method is passed one argument: 'a' (the item to be 
1455          * translated). If an array is returned, that array is mapped out and merged into
1456          * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1457          * from the array. Both of these changes imply that the size of the array may not
1458          * be the same size upon completion, as it was when it started.
1459          *
1460          * @private
1461          * @name jQuery.map
1462          * @type Array
1463          * @param Array array The Array to translate.
1464          * @param Function fn The function to process each item against.
1465          */
1466         map: function(a,f) {
1467                 // If a string is passed in for the function, make a function
1468                 // for it (a handy shortcut)
1469                 if ( f.constructor == String )
1470                         f = new Function("a","return " + f);
1471                 
1472                 var r = [];
1473                 
1474                 // Go through the array, translating each of the items to their
1475                 // new value (or values).
1476                 for ( var i = 0; i < a.length; i++ ) {
1477                         var t = f(a[i],i);
1478                         if ( t !== null && t != undefined ) {
1479                                 if ( t.constructor != Array ) t = [t];
1480                                 r = jQuery.merge( r, t );
1481                         }
1482                 }
1483                 return r;
1484         },
1485         
1486         /*
1487          * A number of helper functions used for managing events.
1488          * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1489          */
1490         event: {
1491         
1492                 // Bind an event to an element
1493                 // Original by Dean Edwards
1494                 add: function(element, type, handler) {
1495                         // For whatever reason, IE has trouble passing the window object
1496                         // around, causing it to be cloned in the process
1497                         if ( jQuery.browser.msie && element.setInterval != undefined )
1498                                 element = window;
1499                 
1500                         // Make sure that the function being executed has a unique ID
1501                         if ( !handler.guid )
1502                                 handler.guid = this.guid++;
1503                                 
1504                         // Init the element's event structure
1505                         if (!element.events)
1506                                 element.events = {};
1507                         
1508                         // Get the current list of functions bound to this event
1509                         var handlers = element.events[type];
1510                         
1511                         // If it hasn't been initialized yet
1512                         if (!handlers) {
1513                                 // Init the event handler queue
1514                                 handlers = element.events[type] = {};
1515                                 
1516                                 // Remember an existing handler, if it's already there
1517                                 if (element["on" + type])
1518                                         handlers[0] = element["on" + type];
1519                         }
1520
1521                         // Add the function to the element's handler list
1522                         handlers[handler.guid] = handler;
1523                         
1524                         // And bind the global event handler to the element
1525                         element["on" + type] = this.handle;
1526         
1527                         // Remember the function in a global list (for triggering)
1528                         if (!this.global[type])
1529                                 this.global[type] = [];
1530                         this.global[type].push( element );
1531                 },
1532                 
1533                 guid: 1,
1534                 global: {},
1535                 
1536                 // Detach an event or set of events from an element
1537                 remove: function(element, type, handler) {
1538                         if (element.events)
1539                                 if (type && element.events[type])
1540                                         if ( handler )
1541                                                 delete element.events[type][handler.guid];
1542                                         else
1543                                                 for ( var i in element.events[type] )
1544                                                         delete element.events[type][i];
1545                                 else
1546                                         for ( var j in element.events )
1547                                                 this.remove( element, j );
1548                 },
1549                 
1550                 trigger: function(type,data,element) {
1551                         // Touch up the incoming data
1552                         data = data || [];
1553         
1554                         // Handle a global trigger
1555                         if ( !element ) {
1556                                 var g = this.global[type];
1557                                 if ( g )
1558                                         for ( var i = 0; i < g.length; i++ )
1559                                                 this.trigger( type, data, g[i] );
1560         
1561                         // Handle triggering a single element
1562                         } else if ( element["on" + type] ) {
1563                                 // Pass along a fake event
1564                                 data.unshift( this.fix({ type: type, target: element }) );
1565         
1566                                 // Trigger the event
1567                                 element["on" + type].apply( element, data );
1568                         }
1569                 },
1570                 
1571                 handle: function(event) {
1572                         if ( typeof jQuery == "undefined" ) return;
1573
1574                         event = event || jQuery.event.fix( window.event );
1575         
1576                         // If no correct event was found, fail
1577                         if ( !event ) return;
1578                 
1579                         var returnValue = true;
1580
1581                         var c = this.events[event.type];
1582                 
1583                         for ( var j in c ) {
1584                                 if ( c[j].apply( this, [event] ) === false ) {
1585                                         event.preventDefault();
1586                                         event.stopPropagation();
1587                                         returnValue = false;
1588                                 }
1589                         }
1590                         
1591                         return returnValue;
1592                 },
1593                 
1594                 fix: function(event) {
1595                         if ( event ) {
1596                                 event.preventDefault = function() {
1597                                         this.returnValue = false;
1598                                 };
1599                         
1600                                 event.stopPropagation = function() {
1601                                         this.cancelBubble = true;
1602                                 };
1603                         }
1604                         
1605                         return event;
1606                 }
1607         
1608         }
1609 });
1610
1611 new function() {
1612         var b = navigator.userAgent.toLowerCase();
1613
1614         // Figure out what browser is being used
1615         jQuery.browser = {
1616                 safari: /webkit/.test(b),
1617                 opera: /opera/.test(b),
1618                 msie: /msie/.test(b) && !/opera/.test(b),
1619                 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1620         };
1621
1622         // Check to see if the W3C box model is being used
1623         jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1624 };
1625
1626 jQuery.macros = {
1627         to: {
1628                 /**
1629                  * Append all of the matched elements to another, specified, set of elements.
1630                  * This operation is, essentially, the reverse of doing a regular
1631                  * $(A).append(B), in that instead of appending B to A, you're appending
1632                  * A to B.
1633                  * 
1634                  * @example $("p").appendTo("#foo");
1635                  * @before <p>I would like to say: </p><div id="foo"></div>
1636                  * @result <div id="foo"><p>I would like to say: </p></div>
1637                  *
1638                  * @name appendTo
1639                  * @type jQuery
1640                  * @param String expr A jQuery expression of elements to match.
1641                  * @cat DOM/Manipulation
1642                  */
1643                 appendTo: "append",
1644                 
1645                 /**
1646                  * Prepend all of the matched elements to another, specified, set of elements.
1647                  * This operation is, essentially, the reverse of doing a regular
1648                  * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1649                  * A to B.
1650                  * 
1651                  * @example $("p").prependTo("#foo");
1652                  * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1653                  * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1654                  *
1655                  * @name prependTo
1656                  * @type jQuery
1657                  * @param String expr A jQuery expression of elements to match.
1658                  * @cat DOM/Manipulation
1659                  */
1660                 prependTo: "prepend",
1661                 
1662                 /**
1663                  * Insert all of the matched elements before another, specified, set of elements.
1664                  * This operation is, essentially, the reverse of doing a regular
1665                  * $(A).before(B), in that instead of inserting B before A, you're inserting
1666                  * A before B.
1667                  * 
1668                  * @example $("p").insertBefore("#foo");
1669                  * @before <div id="foo">Hello</div><p>I would like to say: </p>
1670                  * @result <p>I would like to say: </p><div id="foo">Hello</div>
1671                  *
1672                  * @name insertBefore
1673                  * @type jQuery
1674                  * @param String expr A jQuery expression of elements to match.
1675                  * @cat DOM/Manipulation
1676                  */
1677                 insertBefore: "before",
1678                 
1679                 /**
1680                  * Insert all of the matched elements after another, specified, set of elements.
1681                  * This operation is, essentially, the reverse of doing a regular
1682                  * $(A).after(B), in that instead of inserting B after A, you're inserting
1683                  * A after B.
1684                  * 
1685                  * @example $("p").insertAfter("#foo");
1686                  * @before <p>I would like to say: </p><div id="foo">Hello</div>
1687                  * @result <div id="foo">Hello</div><p>I would like to say: </p>
1688                  *
1689                  * @name insertAfter
1690                  * @type jQuery
1691                  * @param String expr A jQuery expression of elements to match.
1692                  * @cat DOM/Manipulation
1693                  */
1694                 insertAfter: "after"
1695         },
1696         
1697         /**
1698          * Get the current CSS width of the first matched element.
1699          * 
1700          * @example $("p").width();
1701          * @before <p>This is just a test.</p>
1702          * @result "300px"
1703          *
1704          * @name width
1705          * @type String
1706          * @cat CSS
1707          */
1708          
1709         /**
1710          * Set the CSS width of every matched element. Be sure to include
1711          * the "px" (or other unit of measurement) after the number that you 
1712          * specify, otherwise you might get strange results.
1713          * 
1714          * @example $("p").width("20px");
1715          * @before <p>This is just a test.</p>
1716          * @result <p style="width:20px;">This is just a test.</p>
1717          *
1718          * @name width
1719          * @type jQuery
1720          * @param String val Set the CSS property to the specified value.
1721          * @cat CSS
1722          */
1723         
1724         /**
1725          * Get the current CSS height of the first matched element.
1726          * 
1727          * @example $("p").height();
1728          * @before <p>This is just a test.</p>
1729          * @result "14px"
1730          *
1731          * @name height
1732          * @type String
1733          * @cat CSS
1734          */
1735          
1736         /**
1737          * Set the CSS height of every matched element. Be sure to include
1738          * the "px" (or other unit of measurement) after the number that you 
1739          * specify, otherwise you might get strange results.
1740          * 
1741          * @example $("p").height("20px");
1742          * @before <p>This is just a test.</p>
1743          * @result <p style="height:20px;">This is just a test.</p>
1744          *
1745          * @name height
1746          * @type jQuery
1747          * @param String val Set the CSS property to the specified value.
1748          * @cat CSS
1749          */
1750          
1751         /**
1752          * Get the current CSS top of the first matched element.
1753          * 
1754          * @example $("p").top();
1755          * @before <p>This is just a test.</p>
1756          * @result "0px"
1757          *
1758          * @name top
1759          * @type String
1760          * @cat CSS
1761          */
1762          
1763         /**
1764          * Set the CSS top of every matched element. Be sure to include
1765          * the "px" (or other unit of measurement) after the number that you 
1766          * specify, otherwise you might get strange results.
1767          * 
1768          * @example $("p").top("20px");
1769          * @before <p>This is just a test.</p>
1770          * @result <p style="top:20px;">This is just a test.</p>
1771          *
1772          * @name top
1773          * @type jQuery
1774          * @param String val Set the CSS property to the specified value.
1775          * @cat CSS
1776          */
1777          
1778         /**
1779          * Get the current CSS left of the first matched element.
1780          * 
1781          * @example $("p").left();
1782          * @before <p>This is just a test.</p>
1783          * @result "0px"
1784          *
1785          * @name left
1786          * @type String
1787          * @cat CSS
1788          */
1789          
1790         /**
1791          * Set the CSS left of every matched element. Be sure to include
1792          * the "px" (or other unit of measurement) after the number that you 
1793          * specify, otherwise you might get strange results.
1794          * 
1795          * @example $("p").left("20px");
1796          * @before <p>This is just a test.</p>
1797          * @result <p style="left:20px;">This is just a test.</p>
1798          *
1799          * @name left
1800          * @type jQuery
1801          * @param String val Set the CSS property to the specified value.
1802          * @cat CSS
1803          */
1804          
1805         /**
1806          * Get the current CSS position of the first matched element.
1807          * 
1808          * @example $("p").position();
1809          * @before <p>This is just a test.</p>
1810          * @result "static"
1811          *
1812          * @name position
1813          * @type String
1814          * @cat CSS
1815          */
1816          
1817         /**
1818          * Set the CSS position of every matched element.
1819          * 
1820          * @example $("p").position("relative");
1821          * @before <p>This is just a test.</p>
1822          * @result <p style="position:relative;">This is just a test.</p>
1823          *
1824          * @name position
1825          * @type jQuery
1826          * @param String val Set the CSS property to the specified value.
1827          * @cat CSS
1828          */
1829          
1830         /**
1831          * Get the current CSS float of the first matched element.
1832          * 
1833          * @example $("p").float();
1834          * @before <p>This is just a test.</p>
1835          * @result "none"
1836          *
1837          * @name float
1838          * @type String
1839          * @cat CSS
1840          */
1841          
1842         /**
1843          * Set the CSS float of every matched element.
1844          * 
1845          * @example $("p").float("left");
1846          * @before <p>This is just a test.</p>
1847          * @result <p style="float:left;">This is just a test.</p>
1848          *
1849          * @name float
1850          * @type jQuery
1851          * @param String val Set the CSS property to the specified value.
1852          * @cat CSS
1853          */
1854          
1855         /**
1856          * Get the current CSS overflow of the first matched element.
1857          * 
1858          * @example $("p").overflow();
1859          * @before <p>This is just a test.</p>
1860          * @result "none"
1861          *
1862          * @name overflow
1863          * @type String
1864          * @cat CSS
1865          */
1866          
1867         /**
1868          * Set the CSS overflow of every matched element.
1869          * 
1870          * @example $("p").overflow("auto");
1871          * @before <p>This is just a test.</p>
1872          * @result <p style="overflow:auto;">This is just a test.</p>
1873          *
1874          * @name overflow
1875          * @type jQuery
1876          * @param String val Set the CSS property to the specified value.
1877          * @cat CSS
1878          */
1879          
1880         /**
1881          * Get the current CSS color of the first matched element.
1882          * 
1883          * @example $("p").color();
1884          * @before <p>This is just a test.</p>
1885          * @result "black"
1886          *
1887          * @name color
1888          * @type String
1889          * @cat CSS
1890          */
1891          
1892         /**
1893          * Set the CSS color of every matched element.
1894          * 
1895          * @example $("p").color("blue");
1896          * @before <p>This is just a test.</p>
1897          * @result <p style="color:blue;">This is just a test.</p>
1898          *
1899          * @name color
1900          * @type jQuery
1901          * @param String val Set the CSS property to the specified value.
1902          * @cat CSS
1903          */
1904          
1905         /**
1906          * Get the current CSS background of the first matched element.
1907          * 
1908          * @example $("p").background();
1909          * @before <p>This is just a test.</p>
1910          * @result ""
1911          *
1912          * @name background
1913          * @type String
1914          * @cat CSS
1915          */
1916          
1917         /**
1918          * Set the CSS background of every matched element.
1919          * 
1920          * @example $("p").background("blue");
1921          * @before <p>This is just a test.</p>
1922          * @result <p style="background:blue;">This is just a test.</p>
1923          *
1924          * @name background
1925          * @type jQuery
1926          * @param String val Set the CSS property to the specified value.
1927          * @cat CSS
1928          */
1929         
1930         css: "width,height,top,left,position,float,overflow,color,background".split(","),
1931
1932         filter: [ "eq", "lt", "gt", "contains" ],
1933
1934         attr: {
1935                 /**
1936                  * Get the current value of the first matched element.
1937                  * 
1938                  * @example $("input").val();
1939                  * @before <input type="text" value="some text"/>
1940                  * @result "some text"
1941                  *
1942                  * @name val
1943                  * @type String
1944                  * @cat DOM/Attributes
1945                  */
1946                  
1947                 /**
1948                  * Set the value of every matched element.
1949                  * 
1950                  * @example $("input").value("test");
1951                  * @before <input type="text" value="some text"/>
1952                  * @result <input type="text" value="test"/>
1953                  *
1954                  * @name val
1955                  * @type jQuery
1956                  * @param String val Set the property to the specified value.
1957                  * @cat DOM/Attributes
1958                  */
1959                 val: "value",
1960                 
1961                 /**
1962                  * Get the html contents of the first matched element.
1963                  * 
1964                  * @example $("div").html();
1965                  * @before <div><input/></div>
1966                  * @result <input/>
1967                  *
1968                  * @name html
1969                  * @type String
1970                  * @cat DOM/Attributes
1971                  */
1972                  
1973                 /**
1974                  * Set the html contents of every matched element.
1975                  * 
1976                  * @example $("div").html("<b>new stuff</b>");
1977                  * @before <div><input/></div>
1978                  * @result <div><b>new stuff</b></div>
1979                  *
1980                  * @test var div = $("div");
1981                  * div.html("<b>test</b>");
1982                  * var pass = true;
1983                  * for ( var i = 0; i < div.size(); i++ ) {
1984                  *   if ( div.get(i).childNodes.length == 0 ) pass = false;
1985                  * }
1986                  * ok( pass, "Set HTML" );
1987                  *
1988                  * @name html
1989                  * @type jQuery
1990                  * @param String val Set the html contents to the specified value.
1991                  * @cat DOM/Attributes
1992                  */
1993                 html: "innerHTML",
1994                 
1995                 /**
1996                  * Get the current id of the first matched element.
1997                  * 
1998                  * @example $("input").id();
1999                  * @before <input type="text" id="test" value="some text"/>
2000                  * @result "test"
2001                  *
2002                  * @name id
2003                  * @type String
2004                  * @cat DOM/Attributes
2005                  */
2006                  
2007                 /**
2008                  * Set the id of every matched element.
2009                  * 
2010                  * @example $("input").id("newid");
2011                  * @before <input type="text" id="test" value="some text"/>
2012                  * @result <input type="text" id="newid" value="some text"/>
2013                  *
2014                  * @name id
2015                  * @type jQuery
2016                  * @param String val Set the property to the specified value.
2017                  * @cat DOM/Attributes
2018                  */
2019                 id: null,
2020                 
2021                 /**
2022                  * Get the current title of the first matched element.
2023                  * 
2024                  * @example $("img").title();
2025                  * @before <img src="test.jpg" title="my image"/>
2026                  * @result "my image"
2027                  *
2028                  * @name title
2029                  * @type String
2030                  * @cat DOM/Attributes
2031                  */
2032                  
2033                 /**
2034                  * Set the title of every matched element.
2035                  * 
2036                  * @example $("img").title("new title");
2037                  * @before <img src="test.jpg" title="my image"/>
2038                  * @result <img src="test.jpg" title="new image"/>
2039                  *
2040                  * @name title
2041                  * @type jQuery
2042                  * @param String val Set the property to the specified value.
2043                  * @cat DOM/Attributes
2044                  */
2045                 title: null,
2046                 
2047                 /**
2048                  * Get the current name of the first matched element.
2049                  * 
2050                  * @example $("input").name();
2051                  * @before <input type="text" name="username"/>
2052                  * @result "username"
2053                  *
2054                  * @name name
2055                  * @type String
2056                  * @cat DOM/Attributes
2057                  */
2058                  
2059                 /**
2060                  * Set the name of every matched element.
2061                  * 
2062                  * @example $("input").name("user");
2063                  * @before <input type="text" name="username"/>
2064                  * @result <input type="text" name="user"/>
2065                  *
2066                  * @name name
2067                  * @type jQuery
2068                  * @param String val Set the property to the specified value.
2069                  * @cat DOM/Attributes
2070                  */
2071                 name: null,
2072                 
2073                 /**
2074                  * Get the current href of the first matched element.
2075                  * 
2076                  * @example $("a").href();
2077                  * @before <a href="test.html">my link</a>
2078                  * @result "test.html"
2079                  *
2080                  * @name href
2081                  * @type String
2082                  * @cat DOM/Attributes
2083                  */
2084                  
2085                 /**
2086                  * Set the href of every matched element.
2087                  * 
2088                  * @example $("a").href("test2.html");
2089                  * @before <a href="test.html">my link</a>
2090                  * @result <a href="test2.html">my link</a>
2091                  *
2092                  * @name href
2093                  * @type jQuery
2094                  * @param String val Set the property to the specified value.
2095                  * @cat DOM/Attributes
2096                  */
2097                 href: null,
2098                 
2099                 /**
2100                  * Get the current src of the first matched element.
2101                  * 
2102                  * @example $("img").src();
2103                  * @before <img src="test.jpg" title="my image"/>
2104                  * @result "test.jpg"
2105                  *
2106                  * @name src
2107                  * @type String
2108                  * @cat DOM/Attributes
2109                  */
2110                  
2111                 /**
2112                  * Set the src of every matched element.
2113                  * 
2114                  * @example $("img").src("test2.jpg");
2115                  * @before <img src="test.jpg" title="my image"/>
2116                  * @result <img src="test2.jpg" title="my image"/>
2117                  *
2118                  * @name src
2119                  * @type jQuery
2120                  * @param String val Set the property to the specified value.
2121                  * @cat DOM/Attributes
2122                  */
2123                 src: null,
2124                 
2125                 /**
2126                  * Get the current rel of the first matched element.
2127                  * 
2128                  * @example $("a").rel();
2129                  * @before <a href="test.html" rel="nofollow">my link</a>
2130                  * @result "nofollow"
2131                  *
2132                  * @name rel
2133                  * @type String
2134                  * @cat DOM/Attributes
2135                  */
2136                  
2137                 /**
2138                  * Set the rel of every matched element.
2139                  * 
2140                  * @example $("a").rel("nofollow");
2141                  * @before <a href="test.html">my link</a>
2142                  * @result <a href="test.html" rel="nofollow">my link</a>
2143                  *
2144                  * @name rel
2145                  * @type jQuery
2146                  * @param String val Set the property to the specified value.
2147                  * @cat DOM/Attributes
2148                  */
2149                 rel: null
2150         },
2151         
2152         axis: {
2153                 /**
2154                  * Get a set of elements containing the unique parents of the matched
2155                  * set of elements.
2156                  *
2157                  * @example $("p").parent()
2158                  * @before <div><p>Hello</p><p>Hello</p></div>
2159                  * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2160                  *
2161                  * @name parent
2162                  * @type jQuery
2163                  * @cat DOM/Traversing
2164                  */
2165
2166                 /**
2167                  * Get a set of elements containing the unique parents of the matched
2168                  * set of elements, and filtered by an expression.
2169                  *
2170                  * @example $("p").parent(".selected")
2171                  * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2172                  * @result [ <div class="selected"><p>Hello Again</p></div> ]
2173                  *
2174                  * @name parent
2175                  * @type jQuery
2176                  * @param String expr An expression to filter the parents with
2177                  * @cat DOM/Traversing
2178                  */
2179                 parent: "a.parentNode",
2180
2181                 /**
2182                  * Get a set of elements containing the unique ancestors of the matched
2183                  * set of elements.
2184                  *
2185                  * @example $("span").ancestors()
2186                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2187                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 
2188                  *
2189                  * @name ancestors
2190                  * @type jQuery
2191                  * @cat DOM/Traversing
2192                  */
2193
2194                 /**
2195                  * Get a set of elements containing the unique ancestors of the matched
2196                  * set of elements, and filtered by an expression.
2197                  *
2198                  * @example $("span").ancestors("p")
2199                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2200                  * @result [ <p><span>Hello</span></p> ] 
2201                  *
2202                  * @name ancestors
2203                  * @type jQuery
2204                  * @param String expr An expression to filter the ancestors with
2205                  * @cat DOM/Traversing
2206                  */
2207                 ancestors: jQuery.parents,
2208                 
2209                 /**
2210                  * Get a set of elements containing the unique ancestors of the matched
2211                  * set of elements.
2212                  *
2213                  * @example $("span").ancestors()
2214                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2215                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 
2216                  *
2217                  * @name parents
2218                  * @type jQuery
2219                  * @cat DOM/Traversing
2220                  */
2221
2222                 /**
2223                  * Get a set of elements containing the unique ancestors of the matched
2224                  * set of elements, and filtered by an expression.
2225                  *
2226                  * @example $("span").ancestors("p")
2227                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2228                  * @result [ <p><span>Hello</span></p> ] 
2229                  *
2230                  * @name parents
2231                  * @type jQuery
2232                  * @param String expr An expression to filter the ancestors with
2233                  * @cat DOM/Traversing
2234                  */
2235                 parents: jQuery.parents,
2236
2237                 /**
2238                  * Get a set of elements containing the unique next siblings of each of the 
2239                  * matched set of elements.
2240                  * 
2241                  * It only returns the very next sibling, not all next siblings.
2242                  *
2243                  * @example $("p").next()
2244                  * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2245                  * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2246                  *
2247                  * @name next
2248                  * @type jQuery
2249                  * @cat DOM/Traversing
2250                  */
2251
2252                 /**
2253                  * Get a set of elements containing the unique next siblings of each of the 
2254                  * matched set of elements, and filtered by an expression.
2255                  * 
2256                  * It only returns the very next sibling, not all next siblings.
2257                  *
2258                  * @example $("p").next(".selected")
2259                  * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2260                  * @result [ <p class="selected">Hello Again</p> ]
2261                  *
2262                  * @name next
2263                  * @type jQuery
2264                  * @param String expr An expression to filter the next Elements with
2265                  * @cat DOM/Traversing
2266                  */
2267                 next: "jQuery.sibling(a).next",
2268
2269                 /**
2270                  * Get a set of elements containing the unique previous siblings of each of the 
2271                  * matched set of elements.
2272                  * 
2273                  * It only returns the immediately previous sibling, not all previous siblings.
2274                  *
2275                  * @example $("p").previous()
2276                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2277                  * @result [ <div><span>Hello Again</span></div> ]
2278                  *
2279                  * @name prev
2280                  * @type jQuery
2281                  * @cat DOM/Traversing
2282                  */
2283
2284                 /**
2285                  * Get a set of elements containing the unique previous siblings of each of the 
2286                  * matched set of elements, and filtered by an expression.
2287                  * 
2288                  * It only returns the immediately previous sibling, not all previous siblings.
2289                  *
2290                  * @example $("p").previous(".selected")
2291                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2292                  * @result [ <div><span>Hello</span></div> ]
2293                  *
2294                  * @name prev
2295                  * @type jQuery
2296                  * @param String expr An expression to filter the previous Elements with
2297                  * @cat DOM/Traversing
2298                  */
2299                 prev: "jQuery.sibling(a).prev",
2300
2301                 /**
2302                  * Get a set of elements containing all of the unique siblings of each of the 
2303                  * matched set of elements.
2304                  * 
2305                  * @example $("div").siblings()
2306                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2307                  * @result [ <p>Hello</p>, <p>And Again</p> ]
2308                  *
2309                  * @name siblings
2310                  * @type jQuery
2311                  * @cat DOM/Traversing
2312                  */
2313
2314                 /**
2315                  * Get a set of elements containing all of the unique siblings of each of the 
2316                  * matched set of elements, and filtered by an expression.
2317                  *
2318                  * @example $("div").siblings(".selected")
2319                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2320                  * @result [ <p class="selected">Hello Again</p> ]
2321                  *
2322                  * @name siblings
2323                  * @type jQuery
2324                  * @param String expr An expression to filter the sibling Elements with
2325                  * @cat DOM/Traversing
2326                  */
2327                 siblings: jQuery.sibling,
2328                 
2329                 
2330                 /**
2331                  * Get a set of elements containing all of the unique children of each of the 
2332                  * matched set of elements.
2333                  * 
2334                  * @example $("div").children()
2335                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2336                  * @result [ <span>Hello Again</span> ]
2337                  *
2338                  * @name children
2339                  * @type jQuery
2340                  * @cat DOM/Traversing
2341                  */
2342
2343                 /**
2344                  * Get a set of elements containing all of the unique children of each of the 
2345                  * matched set of elements, and filtered by an expression.
2346                  *
2347                  * @example $("div").children(".selected")
2348                  * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2349                  * @result [ <p class="selected">Hello Again</p> ]
2350                  *
2351                  * @name children
2352                  * @type jQuery
2353                  * @param String expr An expression to filter the child Elements with
2354                  * @cat DOM/Traversing
2355                  */
2356                 children: "a.childNodes"
2357         },
2358
2359         each: {
2360                 /**
2361                  * Displays each of the set of matched elements if they are hidden.
2362                  * 
2363                  * @example $("p").show()
2364                  * @before <p style="display: none">Hello</p>
2365                  * @result [ <p style="display: block">Hello</p> ]
2366                  *
2367                  * @test var pass = true, div = $("div");
2368                  * div.show().each(function(){
2369                  *   if ( this.style.display == "none" ) pass = false;
2370                  * });
2371                  * ok( pass, "Show" );
2372                  *
2373                  * @name show
2374                  * @type jQuery
2375                  * @cat Effects
2376                  */
2377                 _show: function(){
2378                         this.style.display = this.oldblock ? this.oldblock : "";
2379                         if ( jQuery.css(this,"display") == "none" )
2380                                 this.style.display = "block";
2381                 },
2382
2383                 /**
2384                  * Hides each of the set of matched elements if they are shown.
2385                  *
2386                  * @example $("p").hide()
2387                  * @before <p>Hello</p>
2388                  * @result [ <p style="display: none">Hello</p> ]
2389                  *
2390                  * var pass = true, div = $("div");
2391                  * div.hide().each(function(){
2392                  *   if ( this.style.display != "none" ) pass = false;
2393                  * });
2394                  * ok( pass, "Hide" );
2395                  *
2396                  * @name hide
2397                  * @type jQuery
2398                  * @cat Effects
2399                  */
2400                 _hide: function(){
2401                         this.oldblock = this.oldblock || jQuery.css(this,"display");
2402                         if ( this.oldblock == "none" )
2403                                 this.oldblock = "block";
2404                         this.style.display = "none";
2405                 },
2406                 
2407                 /**
2408                  * Toggles each of the set of matched elements. If they are shown,
2409                  * toggle makes them hidden. If they are hidden, toggle
2410                  * makes them shown.
2411                  *
2412                  * @example $("p").toggle()
2413                  * @before <p>Hello</p><p style="display: none">Hello Again</p>
2414                  * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2415                  *
2416                  * @name toggle
2417                  * @type jQuery
2418                  * @cat Effects
2419                  */
2420                 _toggle: function(){
2421                         var d = jQuery.css(this,"display");
2422                         $(this)[ !d || d == "none" ? "show" : "hide" ]();
2423                 },
2424                 
2425                 /**
2426                  * Adds the specified class to each of the set of matched elements.
2427                  *
2428                  * @example $("p").addClass("selected")
2429                  * @before <p>Hello</p>
2430                  * @result [ <p class="selected">Hello</p> ]
2431                  *
2432                  * @test var div = $("div");
2433                  * div.addClass("test");
2434                  * var pass = true;
2435                  * for ( var i = 0; i < div.size(); i++ ) {
2436                  *  if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2437                  * }
2438                  * ok( pass, "Add Class" );
2439                  * 
2440                  * @name addClass
2441                  * @type jQuery
2442                  * @param String class A CSS class to add to the elements
2443                  * @cat DOM
2444                  */
2445                 addClass: function(c){
2446                         jQuery.className.add(this,c);
2447                 },
2448                 
2449                 /**
2450                  * Removes the specified class from the set of matched elements.
2451                  *
2452                  * @example $("p").removeClass("selected")
2453                  * @before <p class="selected">Hello</p>
2454                  * @result [ <p>Hello</p> ]
2455                  *
2456                  * @test var div = $("div").addClass("test");
2457                  * div.removeClass("test");
2458                  * var pass = true;
2459                  * for ( var i = 0; i < div.size(); i++ ) {
2460                  *  if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2461                  * }
2462                  * ok( pass, "Remove Class" );
2463                  *
2464                  * @name removeClass
2465                  * @type jQuery
2466                  * @param String class A CSS class to remove from the elements
2467                  * @cat DOM
2468                  */
2469                 removeClass: function(c){
2470                         jQuery.className.remove(this,c);
2471                 },
2472         
2473                 /**
2474                  * Adds the specified class if it is present, removes it if it is
2475                  * not present.
2476                  *
2477                  * @example $("p").toggleClass("selected")
2478                  * @before <p>Hello</p><p class="selected">Hello Again</p>
2479                  * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2480                  *
2481                  * @name toggleClass
2482                  * @type jQuery
2483                  * @param String class A CSS class with which to toggle the elements
2484                  * @cat DOM
2485                  */
2486                 toggleClass: function( c ){
2487                         jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2488                 },
2489                 
2490                 /**
2491                  * Removes all matched elements from the DOM. This does NOT remove them from the
2492                  * jQuery object, allowing you to use the matched elements further.
2493                  *
2494                  * @example $("p").remove();
2495                  * @before <p>Hello</p> how are <p>you?</p>
2496                  * @result how are
2497                  *
2498                  * @name remove
2499                  * @type jQuery
2500                  * @cat DOM/Manipulation
2501                  */
2502                  
2503                 /**
2504                  * Removes only elements (out of the list of matched elements) that match
2505                  * the specified jQuery expression. This does NOT remove them from the
2506                  * jQuery object, allowing you to use the matched elements further.
2507                  *
2508                  * @example $("p").remove(".hello");
2509                  * @before <p class="hello">Hello</p> how are <p>you?</p>
2510                  * @result how are <p>you?</p>
2511                  *
2512                  * @name remove
2513                  * @type jQuery
2514                  * @param String expr A jQuery expression to filter elements by.
2515                  * @cat DOM/Manipulation
2516                  */
2517                 remove: function(a){
2518                         if ( !a || jQuery.filter( [this], a ).r )
2519                                 this.parentNode.removeChild( this );
2520                 },
2521         
2522                 /**
2523                  * Removes all child nodes from the set of matched elements.
2524                  *
2525                  * @example $("p").empty()
2526                  * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2527                  * @result [ <p></p> ]
2528                  *
2529                  * @name empty
2530                  * @type jQuery
2531                  * @cat DOM/Manipulation
2532                  */
2533                 empty: function(){
2534                         while ( this.firstChild )
2535                                 this.removeChild( this.firstChild );
2536                 },
2537                 
2538                 /**
2539                  * Binds a particular event (like click) to a each of a set of match elements.
2540                  *
2541                  * @example $("p").bind( "click", function() { alert("Hello"); } )
2542                  * @before <p>Hello</p>
2543                  * @result [ <p>Hello</p> ]
2544                  *
2545                  * Cancel a default action and prevent it from bubbling by returning false
2546                  * from your function.
2547                  *
2548                  * @example $("form").bind( "submit", function() { return false; } )
2549                  *
2550                  * Cancel a default action by using the preventDefault method.
2551                  *
2552                  * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2553                  *
2554                  * Stop an event from bubbling by using the stopPropogation method.
2555                  *
2556                  * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2557                  *
2558                  * @name bind
2559                  * @type jQuery
2560                  * @param String type An event type
2561                  * @param Function fn A function to bind to the event on each of the set of matched elements
2562                  * @cat Events
2563                  */
2564                 bind: function( type, fn ) {
2565                         if ( fn.constructor == String )
2566                                 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2567                         jQuery.event.add( this, type, fn );
2568                 },
2569                 
2570                 /**
2571                  * The opposite of bind, removes a bound event from each of the matched
2572                  * elements. You must pass the identical function that was used in the original 
2573                  * bind method.
2574                  *
2575                  * @example $("p").unbind( "click", function() { alert("Hello"); } )
2576                  * @before <p onclick="alert('Hello');">Hello</p>
2577                  * @result [ <p>Hello</p> ]
2578                  *
2579                  * @name unbind
2580                  * @type jQuery
2581                  * @param String type An event type
2582                  * @param Function fn A function to unbind from the event on each of the set of matched elements
2583                  * @cat Events
2584                  */
2585                  
2586                 /**
2587                  * Removes all bound events of a particular type from each of the matched
2588                  * elements.
2589                  *
2590                  * @example $("p").unbind( "click" )
2591                  * @before <p onclick="alert('Hello');">Hello</p>
2592                  * @result [ <p>Hello</p> ]
2593                  *
2594                  * @name unbind
2595                  * @type jQuery
2596                  * @param String type An event type
2597                  * @cat Events
2598                  */
2599                  
2600                 /**
2601                  * Removes all bound events from each of the matched elements.
2602                  *
2603                  * @example $("p").unbind()
2604                  * @before <p onclick="alert('Hello');">Hello</p>
2605                  * @result [ <p>Hello</p> ]
2606                  *
2607                  * @name unbind
2608                  * @type jQuery
2609                  * @cat Events
2610                  */
2611                 unbind: function( type, fn ) {
2612                         jQuery.event.remove( this, type, fn );
2613                 },
2614                 
2615                 /**
2616                  * Trigger a type of event on every matched element.
2617                  *
2618                  * @example $("p").trigger("click")
2619                  * @before <p click="alert('hello')">Hello</p>
2620                  * @result alert('hello')
2621                  *
2622                  * @name trigger
2623                  * @type jQuery
2624                  * @param String type An event type to trigger.
2625                  * @cat Events
2626                  */
2627                 trigger: function( type, data ) {
2628                         jQuery.event.trigger( type, data, this );
2629                 }
2630         }
2631 };