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