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