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