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