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