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