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