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