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