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