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