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