Fixed issue with .val() not working properly.
[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 ( typeof $ != "undefined" )
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          * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
641          *
642          * @name not
643          * @type jQuery
644          * @param String expr An expression with which to remove matching elements
645          * @cat DOM/Traversing
646          */
647         not: function(t) {
648                 return this.pushStack( t.constructor == String ?
649                         jQuery.filter(t,this,false).r :
650                         jQuery.grep(this,function(a){ return a != t; }), arguments );
651         },
652
653         /**
654          * Adds the elements matched by the expression to the jQuery object. This
655          * can be used to concatenate the result sets of two expressions.
656          *
657          * @example $("p").add("span")
658          * @before <p>Hello</p><p><span>Hello Again</span></p>
659          * @result [ <p>Hello</p>, <span>Hello Again</span> ]
660          *
661          * @name add
662          * @type jQuery
663          * @param String expr An expression whose matched elements are added
664          * @cat DOM/Traversing
665          */
666
667         /**
668          * Adds each of the Elements in the array to the set of matched elements.
669          * This is used to add a set of Elements to a jQuery object.
670          *
671          * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
672          * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
673          * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
674          *
675          * @name add
676          * @type jQuery
677          * @param Array<Element> els An array of Elements to add
678          * @cat DOM/Traversing
679          */
680
681         /**
682          * Adds a single Element to the set of matched elements. This is used to
683          * add a single Element to a jQuery object.
684          *
685          * @example $("p").add( document.getElementById("a") )
686          * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
687          * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
688          *
689          * @name add
690          * @type jQuery
691          * @param Element el An Element to add
692          * @cat DOM/Traversing
693          */
694         add: function(t) {
695                 return this.pushStack( jQuery.merge( this, t.constructor == String ?
696                         jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
697         },
698         
699         /**
700          * A wrapper function for each() to be used by append and prepend.
701          * Handles cases where you're trying to modify the inner contents of
702          * a table, when you actually need to work with the tbody.
703          *
704          * @member jQuery
705          * @param {String} expr The expression with which to filter
706          * @type Boolean
707          * @cat DOM/Traversing
708          */
709         is: function(expr) {
710                 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
711         },
712         
713         /**
714          * 
715          *
716          * @private
717          * @name domManip
718          * @param Array args
719          * @param Boolean table
720          * @param Number int
721          * @param Function fn The function doing the DOM manipulation.
722          * @type jQuery
723          */
724         domManip: function(args, table, dir, fn){
725                 var clone = this.size() > 1;
726                 var a = jQuery.clean(args);
727                 
728                 return this.each(function(){
729                         var obj = this;
730                         
731                         if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
732                                 var tbody = this.getElementsByTagName("tbody");
733
734                                 if ( !tbody.length ) {
735                                         obj = document.createElement("tbody");
736                                         this.appendChild( obj );
737                                 } else
738                                         obj = tbody[0];
739                         }
740
741                         for ( var i = ( dir < 0 ? a.length - 1 : 0 );
742                                 i != ( dir < 0 ? dir : a.length ); i += dir ) {
743                                         fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
744                         }
745                 });
746         },
747         
748         /**
749          * 
750          *
751          * @private
752          * @name pushStack
753          * @param Array a
754          * @param Array args
755          * @type jQuery
756          */
757         pushStack: function(a,args) {
758                 var fn = args && args[args.length-1];
759
760                 if ( !fn || fn.constructor != Function ) {
761                         if ( !this.stack ) this.stack = [];
762                         this.stack.push( this.get() );
763                         this.get( a );
764                 } else {
765                         var old = this.get();
766                         this.get( a );
767                         if ( fn.constructor == Function )
768                                 return this.each( fn );
769                         this.get( old );
770                 }
771
772                 return this;
773         }
774 };
775
776 /**
777  * 
778  *
779  * @private
780  * @name extend
781  * @param Object obj
782  * @param Object prop
783  * @type Object
784  */
785  
786 /**
787  * Extend one object with another, returning the original,
788  * modified, object. This is a great utility for simple inheritance.
789  *
790  * @name jQuery.extend
791  * @param Object obj The object to extend
792  * @param Object prop The object that will be merged into the first.
793  * @type Object
794  * @cat Javascript
795  */
796 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
797         if ( !prop ) { prop = obj; obj = this; }
798         for ( var i in prop ) obj[i] = prop[i];
799         return obj;
800 };
801
802 jQuery.extend({
803         /**
804          * @private
805          * @name init
806          * @type undefined
807          */
808         init: function(){
809                 jQuery.initDone = true;
810                 
811                 jQuery.each( jQuery.macros.axis, function(i,n){
812                         jQuery.fn[ i ] = function(a) {
813                                 var ret = jQuery.map(this,n);
814                                 if ( a && a.constructor == String )
815                                         ret = jQuery.filter(a,ret).r;
816                                 return this.pushStack( ret, arguments );
817                         };
818                 });
819                 
820                 jQuery.each( jQuery.macros.to, function(i,n){
821                         jQuery.fn[ i ] = function(){
822                                 var a = arguments;
823                                 return this.each(function(){
824                                         for ( var j = 0; j < a.length; j++ )
825                                                 $(a[j])[n]( this );
826                                 });
827                         };
828                 });
829                 
830                 jQuery.each( jQuery.macros.each, function(i,n){
831                         jQuery.fn[ i ] = function() {
832                                 return this.each( n, arguments );
833                         };
834                 });
835
836                 jQuery.each( jQuery.macros.filter, function(i,n){
837                         jQuery.fn[ n ] = function(num,fn) {
838                                 return this.filter( ":" + n + "(" + num + ")", fn );
839                         };
840                 });
841                 
842                 jQuery.each( jQuery.macros.attr, function(i,n){
843                         n = n || i;
844                         jQuery.fn[ i ] = function(h) {
845                                 return h == undefined ?
846                                         this.length ? this[0][n] : null :
847                                         this.attr( n, h );
848                         };
849                 });
850         
851                 jQuery.each( jQuery.macros.css, function(i,n){
852                         jQuery.fn[ n ] = function(h) {
853                                 return h == undefined ?
854                                         ( this.length ? jQuery.css( this[0], n ) : null ) :
855                                         this.css( n, h );
856                         };
857                 });
858         
859         },
860         
861         /**
862          * A generic iterator function, which can be used to seemlessly
863          * iterate over both objects and arrays.
864          *
865          * @name jQuery.each
866          * @param Object obj The object, or array, to iterate over.
867          * @param Object fn The function that will be executed on every object.
868          * @type Object
869          * @cat Javascript
870          */
871         each: function( obj, fn, args ) {
872                 if ( obj.length == undefined )
873                         for ( var i in obj )
874                                 fn.apply( obj[i], args || [i, obj[i]] );
875                 else
876                         for ( var i = 0; i < obj.length; i++ )
877                                 fn.apply( obj[i], args || [i, obj[i]] );
878                 return obj;
879         },
880         
881         className: {
882                 add: function(o,c){
883                         if (jQuery.className.has(o,c)) return;
884                         o.className += ( o.className ? " " : "" ) + c;
885                 },
886                 remove: function(o,c){
887                         o.className = !c ? "" :
888                                 o.className.replace(
889                                         new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
890                 },
891                 has: function(e,a) {
892                         if ( e.className != undefined )
893                                 e = e.className;
894                         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
895                 }
896         },
897         
898         /**
899          * Swap in/out style options.
900          * @private
901          */
902         swap: function(e,o,f) {
903                 for ( var i in o ) {
904                         e.style["old"+i] = e.style[i];
905                         e.style[i] = o[i];
906                 }
907                 f.apply( e, [] );
908                 for ( var i in o )
909                         e.style[i] = e.style["old"+i];
910         },
911         
912         css: function(e,p) {
913                 if ( p == "height" || p == "width" ) {
914                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
915         
916                         for ( var i in d ) {
917                                 old["padding" + d[i]] = 0;
918                                 old["border" + d[i] + "Width"] = 0;
919                         }
920         
921                         jQuery.swap( e, old, function() {
922                                 if (jQuery.css(e,"display") != "none") {
923                                         oHeight = e.offsetHeight;
924                                         oWidth = e.offsetWidth;
925                                 } else {
926                                         e = $(e.cloneNode(true)).css({
927                                                 visibility: "hidden", position: "absolute", display: "block"
928                                         }).prependTo("body")[0];
929
930                                         oHeight = e.clientHeight;
931                                         oWidth = e.clientWidth;
932                                         
933                                         e.parentNode.removeChild(e);
934                                 }
935                         });
936         
937                         return p == "height" ? oHeight : oWidth;
938                 } else if ( p == "opacity" && jQuery.browser.msie )
939                         return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
940
941                 return jQuery.curCSS( e, p );
942         },
943
944         curCSS: function(elem, prop, force) {
945                 var ret;
946         
947                 if (!force && elem.style[prop]) {
948
949                         ret = elem.style[prop];
950
951                 } else if (elem.currentStyle) {
952
953                         var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); 
954                         ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
955
956                 } else if (document.defaultView && document.defaultView.getComputedStyle) {
957
958                         prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
959                         var cur = document.defaultView.getComputedStyle(elem, null);
960
961                         if ( cur )
962                                 ret = cur.getPropertyValue(prop);
963                         else if ( prop == 'display' )
964                                 ret = 'none';
965                         else
966                                 jQuery.swap(elem, { display: 'block' }, function() {
967                                         ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
968                                 });
969
970                 }
971                 
972                 return ret;
973         },
974         
975         clean: function(a) {
976                 var r = [];
977                 for ( var i = 0; i < a.length; i++ ) {
978                         if ( a[i].constructor == String ) {
979
980                                 var table = "";
981         
982                                 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
983                                         table = "thead";
984                                         a[i] = "<table>" + a[i] + "</table>";
985                                 } else if ( !a[i].indexOf("<tr") ) {
986                                         table = "tr";
987                                         a[i] = "<table>" + a[i] + "</table>";
988                                 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
989                                         table = "td";
990                                         a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
991                                 }
992         
993                                 var div = document.createElement("div");
994                                 div.innerHTML = a[i];
995         
996                                 if ( table ) {
997                                         div = div.firstChild;
998                                         if ( table != "thead" ) div = div.firstChild;
999                                         if ( table == "td" ) div = div.firstChild;
1000                                 }
1001         
1002                                 for ( var j = 0; j < div.childNodes.length; j++ )
1003                                         r.push( div.childNodes[j] );
1004                                 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1005                                         for ( var k = 0; k < a[i].length; k++ )
1006                                                 r.push( a[i][k] );
1007                                 else if ( a[i] !== null )
1008                                         r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1009                 }
1010                 return r;
1011         },
1012         
1013         expr: {
1014                 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1015                 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1016                 ":": {
1017                         // Position Checks
1018                         lt: "i<m[3]-0",
1019                         gt: "i>m[3]-0",
1020                         nth: "m[3]-0==i",
1021                         eq: "m[3]-0==i",
1022                         first: "i==0",
1023                         last: "i==r.length-1",
1024                         even: "i%2==0",
1025                         odd: "i%2",
1026                         
1027                         // Child Checks
1028                         "nth-child": "jQuery.sibling(a,m[3]).cur",
1029                         "first-child": "jQuery.sibling(a,0).cur",
1030                         "last-child": "jQuery.sibling(a,0).last",
1031                         "only-child": "jQuery.sibling(a).length==1",
1032                         
1033                         // Parent Checks
1034                         parent: "a.childNodes.length",
1035                         empty: "!a.childNodes.length",
1036                         
1037                         // Text Check
1038                         contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1039                         
1040                         // Visibility
1041                         visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1042                         hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1043                         
1044                         // Form elements
1045                         enabled: "!a.disabled",
1046                         disabled: "a.disabled",
1047                         checked: "a.checked",
1048                         selected: "a.selected"
1049                 },
1050                 ".": "jQuery.className.has(a,m[2])",
1051                 "@": {
1052                         "=": "z==m[4]",
1053                         "!=": "z!=m[4]",
1054                         "^=": "!z.indexOf(m[4])",
1055                         "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1056                         "*=": "z.indexOf(m[4])>=0",
1057                         "": "z"
1058                 },
1059                 "[": "jQuery.find(m[2],a).length"
1060         },
1061         
1062         token: [
1063                 "\\.\\.|/\\.\\.", "a.parentNode",
1064                 ">|/", "jQuery.sibling(a.firstChild)",
1065                 "\\+", "jQuery.sibling(a).next",
1066                 "~", function(a){
1067                         var r = [];
1068                         var s = jQuery.sibling(a);
1069                         if ( s.n > 0 )
1070                                 for ( var i = s.n; i < s.length; i++ )
1071                                         r.push( s[i] );
1072                         return r;
1073                 }
1074         ],
1075         
1076         /**
1077          *
1078          * @test t( "Element Selector", "div", ["main","foo"] );
1079          * @test t( "Element Selector", "body", ["body"] );
1080          * @test t( "Element Selector", "html", ["html"] );
1081          * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1082          * @test t( "Parent Element", "div div", ["foo"] );
1083          *
1084          * @test t( "ID Selector", "#body", ["body"] );
1085          * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1086          * @test t( "ID Selector w/ Element", "ul#first", [] );
1087          *
1088          * @test t( "Class Selector", ".blog", ["mark","simon"] );
1089          * @test t( "Class Selector", ".blog.link", ["simon"] );
1090          * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1091          * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1092          *
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          * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1096          * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1097          *
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", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1101          * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1102          * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1103          * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1104          * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1105          * @test t( "Adjacent", "a + a", ["groups"] );
1106          * @test t( "Adjacent", "a +a", ["groups"] );
1107          * @test t( "Adjacent", "a+ a", ["groups"] );
1108          * @test t( "Adjacent", "a+a", ["groups"] );
1109          * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1110          * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1111          * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1112    * @test t( "Attribute Exists", "a[@title]", ["google"] );
1113          * @test t( "Attribute Exists", "*[@title]", ["google"] );
1114          * @test t( "Attribute Exists", "[@title]", ["google"] );
1115          * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1116          * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1117          * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1118          * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1119          * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1120          * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1121          *
1122          * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1123          * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1124          * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1125          * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1126          * @test t( "Last Child", "p:last-child", ["sap"] );
1127          * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1128          * @test t( "Empty", "ul:empty", ["firstUL"] );
1129          * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1130          * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1131          * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1132          * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1133          * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1134          * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1135          * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1136          *
1137          * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1138          * @test t( "All Div Elements", "//div", ["main","foo"] );
1139          * @test t( "Absolute Path", "/html/body", ["body"] );
1140          * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1141          * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1142          * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1143          * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1144          * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1145          * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1146          * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1147          * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1148          * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1149          * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1150          * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1151          *
1152          * @test t( "nth Element", "p:nth(1)", ["ap"] );
1153          * @test t( "First Element", "p:first", ["firstp"] );
1154          * @test t( "Last Element", "p:last", ["first"] );
1155          * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1156          * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1157          * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1158          * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1159          * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1160          * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1161          * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1162          * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1163          *
1164          * @name jQuery.find
1165          * @private
1166          */
1167         find: function( t, context ) {
1168                 // Make sure that the context is a DOM Element
1169                 if ( context && context.nodeType == undefined )
1170                         context = null;
1171         
1172                 // Set the correct context (if none is provided)
1173                 context = context || jQuery.context || document;
1174         
1175                 if ( t.constructor != String ) return [t];
1176         
1177                 if ( !t.indexOf("//") ) {
1178                         context = context.documentElement;
1179                         t = t.substr(2,t.length);
1180                 } else if ( !t.indexOf("/") ) {
1181                         context = context.documentElement;
1182                         t = t.substr(1,t.length);
1183                         // FIX Assume the root element is right :(
1184                         if ( t.indexOf("/") >= 1 )
1185                                 t = t.substr(t.indexOf("/"),t.length);
1186                 }
1187         
1188                 var ret = [context];
1189                 var done = [];
1190                 var last = null;
1191         
1192                 while ( t.length > 0 && last != t ) {
1193                         var r = [];
1194                         last = t;
1195         
1196                         t = jQuery.trim(t).replace( /^\/\//i, "" );
1197                         
1198                         var foundToken = false;
1199                         
1200                         for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1201                                 var re = new RegExp("^(" + jQuery.token[i] + ")");
1202                                 var m = re.exec(t);
1203                                 
1204                                 if ( m ) {
1205                                         r = ret = jQuery.map( ret, jQuery.token[i+1] );
1206                                         t = jQuery.trim( t.replace( re, "" ) );
1207                                         foundToken = true;
1208                                 }
1209                         }
1210                         
1211                         if ( !foundToken ) {
1212                                 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1213                                         if ( ret[0] == context ) ret.shift();
1214                                         done = jQuery.merge( done, ret );
1215                                         r = ret = [context];
1216                                         t = " " + t.substr(1,t.length);
1217                                 } else {
1218                                         var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1219                                         var m = re2.exec(t);
1220                 
1221                                         if ( m[1] == "#" ) {
1222                                                 // Ummm, should make this work in all XML docs
1223                                                 var oid = document.getElementById(m[2]);
1224                                                 r = ret = oid ? [oid] : [];
1225                                                 t = t.replace( re2, "" );
1226                                         } else {
1227                                                 if ( !m[2] || m[1] == "." ) m[2] = "*";
1228                 
1229                                                 for ( var i = 0; i < ret.length; i++ )
1230                                                         r = jQuery.merge( r,
1231                                                                 m[2] == "*" ?
1232                                                                         jQuery.getAll(ret[i]) :
1233                                                                         ret[i].getElementsByTagName(m[2])
1234                                                         );
1235                                         }
1236                                 }
1237                         }
1238         
1239                         if ( t ) {
1240                                 var val = jQuery.filter(t,r);
1241                                 ret = r = val.r;
1242                                 t = jQuery.trim(val.t);
1243                         }
1244                 }
1245         
1246                 if ( ret && ret[0] == context ) ret.shift();
1247                 done = jQuery.merge( done, ret );
1248         
1249                 return done;
1250         },
1251         
1252         getAll: function(o,r) {
1253                 r = r || [];
1254                 var s = o.childNodes;
1255                 for ( var i = 0; i < s.length; i++ )
1256                         if ( s[i].nodeType == 1 ) {
1257                                 r.push( s[i] );
1258                                 jQuery.getAll( s[i], r );
1259                         }
1260                 return r;
1261         },
1262         
1263         attr: function(elem, name, value){
1264                 var fix = {
1265                         "for": "htmlFor",
1266                         "class": "className",
1267                         "float": "cssFloat",
1268                         innerHTML: "innerHTML",
1269                         className: "className",
1270                         value: "value"
1271                 };
1272
1273                 if ( fix[name] ) {
1274                         if ( value != undefined ) elem[fix[name]] = value;
1275                         return elem[fix[name]];
1276                 } else if ( elem.getAttribute ) {
1277                         if ( value != undefined ) elem.setAttribute( name, value );
1278                         return elem.getAttribute( name, 2 );
1279                 } else {
1280                         name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1281                         if ( value != undefined ) elem[name] = value;
1282                         return elem[name];
1283                 }
1284         },
1285
1286         // The regular expressions that power the parsing engine
1287         parse: [
1288                 // Match: [@value='test'], [@foo]
1289                 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1290
1291                 // Match: [div], [div p]
1292                 [ "(\\[)Q\\]", 0 ],
1293
1294                 // Match: :contains('foo')
1295                 [ "(:)S\\(Q\\)", 0 ],
1296
1297                 // Match: :even, :last-chlid
1298                 [ "([:.#]*)S", 0 ]
1299         ],
1300         
1301         filter: function(t,r,not) {
1302                 // Figure out if we're doing regular, or inverse, filtering
1303                 var g = not !== false ? jQuery.grep :
1304                         function(a,f) {return jQuery.grep(a,f,true);};
1305                 
1306                 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1307
1308                         var p = jQuery.parse;
1309
1310                         for ( var i = 0; i < p.length; i++ ) {
1311                                 var re = new RegExp( "^" + p[i][0]
1312
1313                                         // Look for a string-like sequence
1314                                         .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1315
1316                                         // Look for something (optionally) enclosed with quotes
1317                                         .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1318
1319                                 var m = re.exec( t );
1320
1321                                 if ( m ) {
1322                                         // Re-organize the match
1323                                         if ( p[i][1] )
1324                                                 m = ["", m[1], m[3], m[2], m[4]];
1325
1326                                         // Remove what we just matched
1327                                         t = t.replace( re, "" );
1328
1329                                         break;
1330                                 }
1331                         }
1332         
1333                         // :not() is a special case that can be optomized by
1334                         // keeping it out of the expression list
1335                         if ( m[1] == ":" && m[2] == "not" )
1336                                 r = jQuery.filter(m[3],r,false).r;
1337                         
1338                         // Otherwise, find the expression to execute
1339                         else {
1340                                 var f = jQuery.expr[m[1]];
1341                                 if ( f.constructor != String )
1342                                         f = jQuery.expr[m[1]][m[2]];
1343                                         
1344                                 // Build a custom macro to enclose it
1345                                 eval("f = function(a,i){" + 
1346                                         ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) + 
1347                                         "return " + f + "}");
1348                                 
1349                                 // Execute it against the current filter
1350                                 r = g( r, f );
1351                         }
1352                 }
1353         
1354                 // Return an array of filtered elements (r)
1355                 // and the modified expression string (t)
1356                 return { r: r, t: t };
1357         },
1358         
1359         /**
1360          * Remove the whitespace from the beginning and end of a string.
1361          *
1362          * @private
1363          * @name jQuery.trim
1364          * @type String
1365          * @param String str The string to trim.
1366          */
1367         trim: function(t){
1368                 return t.replace(/^\s+|\s+$/g, "");
1369         },
1370         
1371         /**
1372          * All ancestors of a given element.
1373          *
1374          * @private
1375          * @name jQuery.parents
1376          * @type Array<Element>
1377          * @param Element elem The element to find the ancestors of.
1378          */
1379         parents: function( elem ){
1380                 var matched = [];
1381                 var cur = elem.parentNode;
1382                 while ( cur && cur != document ) {
1383                         matched.push( cur );
1384                         cur = cur.parentNode;
1385                 }
1386                 return matched;
1387         },
1388         
1389         /**
1390          * All elements on a specified axis.
1391          *
1392          * @private
1393          * @name jQuery.sibling
1394          * @type Array
1395          * @param Element elem The element to find all the siblings of (including itself).
1396          */
1397         sibling: function(elem, pos, not) {
1398                 var elems = [];
1399
1400                 var siblings = elem.parentNode.childNodes;
1401                 for ( var i = 0; i < siblings.length; i++ ) {
1402                         if ( not === true && siblings[i] == elem ) continue;
1403
1404                         if ( siblings[i].nodeType == 1 )
1405                                 elems.push( siblings[i] );
1406                         if ( siblings[i] == elem )
1407                                 elems.n = elems.length - 1;
1408                 }
1409
1410                 return jQuery.extend( elems, {
1411                         last: elems.n == elems.length - 1,
1412                         cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1413                         prev: elems[elems.n - 1],
1414                         next: elems[elems.n + 1]
1415                 });
1416         },
1417         
1418         /**
1419          * Merge two arrays together, removing all duplicates.
1420          *
1421          * @private
1422          * @name jQuery.merge
1423          * @type Array
1424          * @param Array a The first array to merge.
1425          * @param Array b The second array to merge.
1426          */
1427         merge: function(first, second) {
1428                 var result = [];
1429                 
1430                 // Move b over to the new array (this helps to avoid
1431                 // StaticNodeList instances)
1432                 for ( var k = 0; k < first.length; k++ )
1433                         result[k] = first[k];
1434         
1435                 // Now check for duplicates between a and b and only
1436                 // add the unique items
1437                 for ( var i = 0; i < second.length; i++ ) {
1438                         var noCollision = true;
1439                         
1440                         // The collision-checking process
1441                         for ( var j = 0; j < first.length; j++ )
1442                                 if ( second[i] == first[j] )
1443                                         noCollision = false;
1444                                 
1445                         // If the item is unique, add it
1446                         if ( noCollision )
1447                                 result.push( second[i] );
1448                 }
1449         
1450                 return result;
1451         },
1452         
1453         /**
1454          * Remove items that aren't matched in an array. The function passed
1455          * in to this method will be passed two arguments: 'a' (which is the
1456          * array item) and 'i' (which is the index of the item in the array).
1457          *
1458          * @private
1459          * @name jQuery.grep
1460          * @type Array
1461          * @param Array array The Array to find items in.
1462          * @param Function fn The function to process each item against.
1463          * @param Boolean inv Invert the selection - select the opposite of the function.
1464          */
1465         grep: function(elems, fn, inv) {
1466                 // If a string is passed in for the function, make a function
1467                 // for it (a handy shortcut)
1468                 if ( fn.constructor == String )
1469                         fn = new Function("a","i","return " + fn);
1470                         
1471                 var result = [];
1472                 
1473                 // Go through the array, only saving the items
1474                 // that pass the validator function
1475                 for ( var i = 0; i < elems.length; i++ )
1476                         if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1477                                 result.push( elems[i] );
1478                 
1479                 return result;
1480         },
1481         
1482         /**
1483          * Translate all items in array to another array of items. The translation function
1484          * that is provided to this method is passed one argument: 'a' (the item to be 
1485          * translated). If an array is returned, that array is mapped out and merged into
1486          * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1487          * from the array. Both of these changes imply that the size of the array may not
1488          * be the same size upon completion, as it was when it started.
1489          *
1490          * @private
1491          * @name jQuery.map
1492          * @type Array
1493          * @param Array array The Array to translate.
1494          * @param Function fn The function to process each item against.
1495          */
1496         map: function(elems, fn) {
1497                 // If a string is passed in for the function, make a function
1498                 // for it (a handy shortcut)
1499                 if ( fn.constructor == String )
1500                         fn = new Function("a","return " + fn);
1501                 
1502                 var result = [];
1503                 
1504                 // Go through the array, translating each of the items to their
1505                 // new value (or values).
1506                 for ( var i = 0; i < elems.length; i++ ) {
1507                         var val = fn(elems[i],i);
1508
1509                         if ( val !== null && val != undefined ) {
1510                                 if ( val.constructor != Array ) val = [val];
1511                                 result = jQuery.merge( result, val );
1512                         }
1513                 }
1514
1515                 return result;
1516         },
1517         
1518         /*
1519          * A number of helper functions used for managing events.
1520          * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1521          */
1522         event: {
1523         
1524                 // Bind an event to an element
1525                 // Original by Dean Edwards
1526                 add: function(element, type, handler) {
1527                         // For whatever reason, IE has trouble passing the window object
1528                         // around, causing it to be cloned in the process
1529                         if ( jQuery.browser.msie && element.setInterval != undefined )
1530                                 element = window;
1531                 
1532                         // Make sure that the function being executed has a unique ID
1533                         if ( !handler.guid )
1534                                 handler.guid = this.guid++;
1535                                 
1536                         // Init the element's event structure
1537                         if (!element.events)
1538                                 element.events = {};
1539                         
1540                         // Get the current list of functions bound to this event
1541                         var handlers = element.events[type];
1542                         
1543                         // If it hasn't been initialized yet
1544                         if (!handlers) {
1545                                 // Init the event handler queue
1546                                 handlers = element.events[type] = {};
1547                                 
1548                                 // Remember an existing handler, if it's already there
1549                                 if (element["on" + type])
1550                                         handlers[0] = element["on" + type];
1551                         }
1552
1553                         // Add the function to the element's handler list
1554                         handlers[handler.guid] = handler;
1555                         
1556                         // And bind the global event handler to the element
1557                         element["on" + type] = this.handle;
1558         
1559                         // Remember the function in a global list (for triggering)
1560                         if (!this.global[type])
1561                                 this.global[type] = [];
1562                         this.global[type].push( element );
1563                 },
1564                 
1565                 guid: 1,
1566                 global: {},
1567                 
1568                 // Detach an event or set of events from an element
1569                 remove: function(element, type, handler) {
1570                         if (element.events)
1571                                 if (type && element.events[type])
1572                                         if ( handler )
1573                                                 delete element.events[type][handler.guid];
1574                                         else
1575                                                 for ( var i in element.events[type] )
1576                                                         delete element.events[type][i];
1577                                 else
1578                                         for ( var j in element.events )
1579                                                 this.remove( element, j );
1580                 },
1581                 
1582                 trigger: function(type,data,element) {
1583                         // Touch up the incoming data
1584                         data = data || [];
1585         
1586                         // Handle a global trigger
1587                         if ( !element ) {
1588                                 var g = this.global[type];
1589                                 if ( g )
1590                                         for ( var i = 0; i < g.length; i++ )
1591                                                 this.trigger( type, data, g[i] );
1592         
1593                         // Handle triggering a single element
1594                         } else if ( element["on" + type] ) {
1595                                 // Pass along a fake event
1596                                 data.unshift( this.fix({ type: type, target: element }) );
1597         
1598                                 // Trigger the event
1599                                 element["on" + type].apply( element, data );
1600                         }
1601                 },
1602                 
1603                 handle: function(event) {
1604                         if ( typeof jQuery == "undefined" ) return;
1605
1606                         event = event || jQuery.event.fix( window.event );
1607         
1608                         // If no correct event was found, fail
1609                         if ( !event ) return;
1610                 
1611                         var returnValue = true;
1612
1613                         var c = this.events[event.type];
1614                 
1615                         for ( var j in c ) {
1616                                 if ( c[j].apply( this, [event] ) === false ) {
1617                                         event.preventDefault();
1618                                         event.stopPropagation();
1619                                         returnValue = false;
1620                                 }
1621                         }
1622                         
1623                         return returnValue;
1624                 },
1625                 
1626                 fix: function(event) {
1627                         if ( event ) {
1628                                 event.preventDefault = function() {
1629                                         this.returnValue = false;
1630                                 };
1631                         
1632                                 event.stopPropagation = function() {
1633                                         this.cancelBubble = true;
1634                                 };
1635                         }
1636                         
1637                         return event;
1638                 }
1639         
1640         }
1641 });
1642
1643 new function() {
1644         var b = navigator.userAgent.toLowerCase();
1645
1646         // Figure out what browser is being used
1647         jQuery.browser = {
1648                 safari: /webkit/.test(b),
1649                 opera: /opera/.test(b),
1650                 msie: /msie/.test(b) && !/opera/.test(b),
1651                 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1652         };
1653
1654         // Check to see if the W3C box model is being used
1655         jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1656 };
1657
1658 jQuery.macros = {
1659         to: {
1660                 /**
1661                  * Append all of the matched elements to another, specified, set of elements.
1662                  * This operation is, essentially, the reverse of doing a regular
1663                  * $(A).append(B), in that instead of appending B to A, you're appending
1664                  * A to B.
1665                  * 
1666                  * @example $("p").appendTo("#foo");
1667                  * @before <p>I would like to say: </p><div id="foo"></div>
1668                  * @result <div id="foo"><p>I would like to say: </p></div>
1669                  *
1670                  * @name appendTo
1671                  * @type jQuery
1672                  * @param String expr A jQuery expression of elements to match.
1673                  * @cat DOM/Manipulation
1674                  */
1675                 appendTo: "append",
1676                 
1677                 /**
1678                  * Prepend all of the matched elements to another, specified, set of elements.
1679                  * This operation is, essentially, the reverse of doing a regular
1680                  * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1681                  * A to B.
1682                  * 
1683                  * @example $("p").prependTo("#foo");
1684                  * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1685                  * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1686                  *
1687                  * @name prependTo
1688                  * @type jQuery
1689                  * @param String expr A jQuery expression of elements to match.
1690                  * @cat DOM/Manipulation
1691                  */
1692                 prependTo: "prepend",
1693                 
1694                 /**
1695                  * Insert all of the matched elements before another, specified, set of elements.
1696                  * This operation is, essentially, the reverse of doing a regular
1697                  * $(A).before(B), in that instead of inserting B before A, you're inserting
1698                  * A before B.
1699                  * 
1700                  * @example $("p").insertBefore("#foo");
1701                  * @before <div id="foo">Hello</div><p>I would like to say: </p>
1702                  * @result <p>I would like to say: </p><div id="foo">Hello</div>
1703                  *
1704                  * @name insertBefore
1705                  * @type jQuery
1706                  * @param String expr A jQuery expression of elements to match.
1707                  * @cat DOM/Manipulation
1708                  */
1709                 insertBefore: "before",
1710                 
1711                 /**
1712                  * Insert all of the matched elements after another, specified, set of elements.
1713                  * This operation is, essentially, the reverse of doing a regular
1714                  * $(A).after(B), in that instead of inserting B after A, you're inserting
1715                  * A after B.
1716                  * 
1717                  * @example $("p").insertAfter("#foo");
1718                  * @before <p>I would like to say: </p><div id="foo">Hello</div>
1719                  * @result <div id="foo">Hello</div><p>I would like to say: </p>
1720                  *
1721                  * @name insertAfter
1722                  * @type jQuery
1723                  * @param String expr A jQuery expression of elements to match.
1724                  * @cat DOM/Manipulation
1725                  */
1726                 insertAfter: "after"
1727         },
1728         
1729         /**
1730          * Get the current CSS width of the first matched element.
1731          * 
1732          * @example $("p").width();
1733          * @before <p>This is just a test.</p>
1734          * @result "300px"
1735          *
1736          * @name width
1737          * @type String
1738          * @cat CSS
1739          */
1740          
1741         /**
1742          * Set the CSS width of every matched element. Be sure to include
1743          * the "px" (or other unit of measurement) after the number that you 
1744          * specify, otherwise you might get strange results.
1745          * 
1746          * @example $("p").width("20px");
1747          * @before <p>This is just a test.</p>
1748          * @result <p style="width:20px;">This is just a test.</p>
1749          *
1750          * @name width
1751          * @type jQuery
1752          * @param String val Set the CSS property to the specified value.
1753          * @cat CSS
1754          */
1755         
1756         /**
1757          * Get the current CSS height of the first matched element.
1758          * 
1759          * @example $("p").height();
1760          * @before <p>This is just a test.</p>
1761          * @result "14px"
1762          *
1763          * @name height
1764          * @type String
1765          * @cat CSS
1766          */
1767          
1768         /**
1769          * Set the CSS height of every matched element. Be sure to include
1770          * the "px" (or other unit of measurement) after the number that you 
1771          * specify, otherwise you might get strange results.
1772          * 
1773          * @example $("p").height("20px");
1774          * @before <p>This is just a test.</p>
1775          * @result <p style="height:20px;">This is just a test.</p>
1776          *
1777          * @name height
1778          * @type jQuery
1779          * @param String val Set the CSS property to the specified value.
1780          * @cat CSS
1781          */
1782          
1783         /**
1784          * Get the current CSS top of the first matched element.
1785          * 
1786          * @example $("p").top();
1787          * @before <p>This is just a test.</p>
1788          * @result "0px"
1789          *
1790          * @name top
1791          * @type String
1792          * @cat CSS
1793          */
1794          
1795         /**
1796          * Set the CSS top of every matched element. Be sure to include
1797          * the "px" (or other unit of measurement) after the number that you 
1798          * specify, otherwise you might get strange results.
1799          * 
1800          * @example $("p").top("20px");
1801          * @before <p>This is just a test.</p>
1802          * @result <p style="top:20px;">This is just a test.</p>
1803          *
1804          * @name top
1805          * @type jQuery
1806          * @param String val Set the CSS property to the specified value.
1807          * @cat CSS
1808          */
1809          
1810         /**
1811          * Get the current CSS left of the first matched element.
1812          * 
1813          * @example $("p").left();
1814          * @before <p>This is just a test.</p>
1815          * @result "0px"
1816          *
1817          * @name left
1818          * @type String
1819          * @cat CSS
1820          */
1821          
1822         /**
1823          * Set the CSS left of every matched element. Be sure to include
1824          * the "px" (or other unit of measurement) after the number that you 
1825          * specify, otherwise you might get strange results.
1826          * 
1827          * @example $("p").left("20px");
1828          * @before <p>This is just a test.</p>
1829          * @result <p style="left:20px;">This is just a test.</p>
1830          *
1831          * @name left
1832          * @type jQuery
1833          * @param String val Set the CSS property to the specified value.
1834          * @cat CSS
1835          */
1836          
1837         /**
1838          * Get the current CSS position of the first matched element.
1839          * 
1840          * @example $("p").position();
1841          * @before <p>This is just a test.</p>
1842          * @result "static"
1843          *
1844          * @name position
1845          * @type String
1846          * @cat CSS
1847          */
1848          
1849         /**
1850          * Set the CSS position of every matched element.
1851          * 
1852          * @example $("p").position("relative");
1853          * @before <p>This is just a test.</p>
1854          * @result <p style="position:relative;">This is just a test.</p>
1855          *
1856          * @name position
1857          * @type jQuery
1858          * @param String val Set the CSS property to the specified value.
1859          * @cat CSS
1860          */
1861          
1862         /**
1863          * Get the current CSS float of the first matched element.
1864          * 
1865          * @example $("p").float();
1866          * @before <p>This is just a test.</p>
1867          * @result "none"
1868          *
1869          * @name float
1870          * @type String
1871          * @cat CSS
1872          */
1873          
1874         /**
1875          * Set the CSS float of every matched element.
1876          * 
1877          * @example $("p").float("left");
1878          * @before <p>This is just a test.</p>
1879          * @result <p style="float:left;">This is just a test.</p>
1880          *
1881          * @name float
1882          * @type jQuery
1883          * @param String val Set the CSS property to the specified value.
1884          * @cat CSS
1885          */
1886          
1887         /**
1888          * Get the current CSS overflow of the first matched element.
1889          * 
1890          * @example $("p").overflow();
1891          * @before <p>This is just a test.</p>
1892          * @result "none"
1893          *
1894          * @name overflow
1895          * @type String
1896          * @cat CSS
1897          */
1898          
1899         /**
1900          * Set the CSS overflow of every matched element.
1901          * 
1902          * @example $("p").overflow("auto");
1903          * @before <p>This is just a test.</p>
1904          * @result <p style="overflow:auto;">This is just a test.</p>
1905          *
1906          * @name overflow
1907          * @type jQuery
1908          * @param String val Set the CSS property to the specified value.
1909          * @cat CSS
1910          */
1911          
1912         /**
1913          * Get the current CSS color of the first matched element.
1914          * 
1915          * @example $("p").color();
1916          * @before <p>This is just a test.</p>
1917          * @result "black"
1918          *
1919          * @name color
1920          * @type String
1921          * @cat CSS
1922          */
1923          
1924         /**
1925          * Set the CSS color of every matched element.
1926          * 
1927          * @example $("p").color("blue");
1928          * @before <p>This is just a test.</p>
1929          * @result <p style="color:blue;">This is just a test.</p>
1930          *
1931          * @name color
1932          * @type jQuery
1933          * @param String val Set the CSS property to the specified value.
1934          * @cat CSS
1935          */
1936          
1937         /**
1938          * Get the current CSS background of the first matched element.
1939          * 
1940          * @example $("p").background();
1941          * @before <p>This is just a test.</p>
1942          * @result ""
1943          *
1944          * @name background
1945          * @type String
1946          * @cat CSS
1947          */
1948          
1949         /**
1950          * Set the CSS background of every matched element.
1951          * 
1952          * @example $("p").background("blue");
1953          * @before <p>This is just a test.</p>
1954          * @result <p style="background:blue;">This is just a test.</p>
1955          *
1956          * @name background
1957          * @type jQuery
1958          * @param String val Set the CSS property to the specified value.
1959          * @cat CSS
1960          */
1961         
1962         css: "width,height,top,left,position,float,overflow,color,background".split(","),
1963
1964         filter: [ "eq", "lt", "gt", "contains" ],
1965
1966         attr: {
1967                 /**
1968                  * Get the current value of the first matched element.
1969                  * 
1970                  * @example $("input").val();
1971                  * @before <input type="text" value="some text"/>
1972                  * @result "some text"
1973                  *
1974                  * @name val
1975                  * @type String
1976                  * @cat DOM/Attributes
1977                  */
1978                  
1979                 /**
1980                  * Set the value of every matched element.
1981                  * 
1982                  * @example $("input").value("test");
1983                  * @before <input type="text" value="some text"/>
1984                  * @result <input type="text" value="test"/>
1985                  *
1986                  * @name val
1987                  * @type jQuery
1988                  * @param String val Set the property to the specified value.
1989                  * @cat DOM/Attributes
1990                  */
1991                 val: "value",
1992                 
1993                 /**
1994                  * Get the html contents of the first matched element.
1995                  * 
1996                  * @example $("div").html();
1997                  * @before <div><input/></div>
1998                  * @result <input/>
1999                  *
2000                  * @name html
2001                  * @type String
2002                  * @cat DOM/Attributes
2003                  */
2004                  
2005                 /**
2006                  * Set the html contents of every matched element.
2007                  * 
2008                  * @example $("div").html("<b>new stuff</b>");
2009                  * @before <div><input/></div>
2010                  * @result <div><b>new stuff</b></div>
2011                  *
2012                  * @test var div = $("div");
2013                  * div.html("<b>test</b>");
2014                  * var pass = true;
2015                  * for ( var i = 0; i < div.size(); i++ ) {
2016                  *   if ( div.get(i).childNodes.length == 0 ) pass = false;
2017                  * }
2018                  * ok( pass, "Set HTML" );
2019                  *
2020                  * @name html
2021                  * @type jQuery
2022                  * @param String val Set the html contents to the specified value.
2023                  * @cat DOM/Attributes
2024                  */
2025                 html: "innerHTML",
2026                 
2027                 /**
2028                  * Get the current id of the first matched element.
2029                  * 
2030                  * @example $("input").id();
2031                  * @before <input type="text" id="test" value="some text"/>
2032                  * @result "test"
2033                  *
2034                  * @name id
2035                  * @type String
2036                  * @cat DOM/Attributes
2037                  */
2038                  
2039                 /**
2040                  * Set the id of every matched element.
2041                  * 
2042                  * @example $("input").id("newid");
2043                  * @before <input type="text" id="test" value="some text"/>
2044                  * @result <input type="text" id="newid" value="some text"/>
2045                  *
2046                  * @name id
2047                  * @type jQuery
2048                  * @param String val Set the property to the specified value.
2049                  * @cat DOM/Attributes
2050                  */
2051                 id: null,
2052                 
2053                 /**
2054                  * Get the current title of the first matched element.
2055                  * 
2056                  * @example $("img").title();
2057                  * @before <img src="test.jpg" title="my image"/>
2058                  * @result "my image"
2059                  *
2060                  * @name title
2061                  * @type String
2062                  * @cat DOM/Attributes
2063                  */
2064                  
2065                 /**
2066                  * Set the title of every matched element.
2067                  * 
2068                  * @example $("img").title("new title");
2069                  * @before <img src="test.jpg" title="my image"/>
2070                  * @result <img src="test.jpg" title="new image"/>
2071                  *
2072                  * @name title
2073                  * @type jQuery
2074                  * @param String val Set the property to the specified value.
2075                  * @cat DOM/Attributes
2076                  */
2077                 title: null,
2078                 
2079                 /**
2080                  * Get the current name of the first matched element.
2081                  * 
2082                  * @example $("input").name();
2083                  * @before <input type="text" name="username"/>
2084                  * @result "username"
2085                  *
2086                  * @name name
2087                  * @type String
2088                  * @cat DOM/Attributes
2089                  */
2090                  
2091                 /**
2092                  * Set the name of every matched element.
2093                  * 
2094                  * @example $("input").name("user");
2095                  * @before <input type="text" name="username"/>
2096                  * @result <input type="text" name="user"/>
2097                  *
2098                  * @name name
2099                  * @type jQuery
2100                  * @param String val Set the property to the specified value.
2101                  * @cat DOM/Attributes
2102                  */
2103                 name: null,
2104                 
2105                 /**
2106                  * Get the current href of the first matched element.
2107                  * 
2108                  * @example $("a").href();
2109                  * @before <a href="test.html">my link</a>
2110                  * @result "test.html"
2111                  *
2112                  * @name href
2113                  * @type String
2114                  * @cat DOM/Attributes
2115                  */
2116                  
2117                 /**
2118                  * Set the href of every matched element.
2119                  * 
2120                  * @example $("a").href("test2.html");
2121                  * @before <a href="test.html">my link</a>
2122                  * @result <a href="test2.html">my link</a>
2123                  *
2124                  * @name href
2125                  * @type jQuery
2126                  * @param String val Set the property to the specified value.
2127                  * @cat DOM/Attributes
2128                  */
2129                 href: null,
2130                 
2131                 /**
2132                  * Get the current src of the first matched element.
2133                  * 
2134                  * @example $("img").src();
2135                  * @before <img src="test.jpg" title="my image"/>
2136                  * @result "test.jpg"
2137                  *
2138                  * @name src
2139                  * @type String
2140                  * @cat DOM/Attributes
2141                  */
2142                  
2143                 /**
2144                  * Set the src of every matched element.
2145                  * 
2146                  * @example $("img").src("test2.jpg");
2147                  * @before <img src="test.jpg" title="my image"/>
2148                  * @result <img src="test2.jpg" title="my image"/>
2149                  *
2150                  * @name src
2151                  * @type jQuery
2152                  * @param String val Set the property to the specified value.
2153                  * @cat DOM/Attributes
2154                  */
2155                 src: null,
2156                 
2157                 /**
2158                  * Get the current rel of the first matched element.
2159                  * 
2160                  * @example $("a").rel();
2161                  * @before <a href="test.html" rel="nofollow">my link</a>
2162                  * @result "nofollow"
2163                  *
2164                  * @name rel
2165                  * @type String
2166                  * @cat DOM/Attributes
2167                  */
2168                  
2169                 /**
2170                  * Set the rel of every matched element.
2171                  * 
2172                  * @example $("a").rel("nofollow");
2173                  * @before <a href="test.html">my link</a>
2174                  * @result <a href="test.html" rel="nofollow">my link</a>
2175                  *
2176                  * @name rel
2177                  * @type jQuery
2178                  * @param String val Set the property to the specified value.
2179                  * @cat DOM/Attributes
2180                  */
2181                 rel: null
2182         },
2183         
2184         axis: {
2185                 /**
2186                  * Get a set of elements containing the unique parents of the matched
2187                  * set of elements.
2188                  *
2189                  * @example $("p").parent()
2190                  * @before <div><p>Hello</p><p>Hello</p></div>
2191                  * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2192                  *
2193                  * @name parent
2194                  * @type jQuery
2195                  * @cat DOM/Traversing
2196                  */
2197
2198                 /**
2199                  * Get a set of elements containing the unique parents of the matched
2200                  * set of elements, and filtered by an expression.
2201                  *
2202                  * @example $("p").parent(".selected")
2203                  * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2204                  * @result [ <div class="selected"><p>Hello Again</p></div> ]
2205                  *
2206                  * @name parent
2207                  * @type jQuery
2208                  * @param String expr An expression to filter the parents with
2209                  * @cat DOM/Traversing
2210                  */
2211                 parent: "a.parentNode",
2212
2213                 /**
2214                  * Get a set of elements containing the unique ancestors of the matched
2215                  * set of elements (except for the root element).
2216                  *
2217                  * @example $("span").ancestors()
2218                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2219                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 
2220                  *
2221                  * @name ancestors
2222                  * @type jQuery
2223                  * @cat DOM/Traversing
2224                  */
2225
2226                 /**
2227                  * Get a set of elements containing the unique ancestors of the matched
2228                  * set of elements, and filtered by an expression.
2229                  *
2230                  * @example $("span").ancestors("p")
2231                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2232                  * @result [ <p><span>Hello</span></p> ] 
2233                  *
2234                  * @name ancestors
2235                  * @type jQuery
2236                  * @param String expr An expression to filter the ancestors with
2237                  * @cat DOM/Traversing
2238                  */
2239                 ancestors: jQuery.parents,
2240                 
2241                 /**
2242                  * Get a set of elements containing the unique ancestors of the matched
2243                  * set of elements (except for the root element).
2244                  *
2245                  * @example $("span").ancestors()
2246                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2247                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 
2248                  *
2249                  * @name parents
2250                  * @type jQuery
2251                  * @cat DOM/Traversing
2252                  */
2253
2254                 /**
2255                  * Get a set of elements containing the unique ancestors of the matched
2256                  * set of elements, and filtered by an expression.
2257                  *
2258                  * @example $("span").ancestors("p")
2259                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2260                  * @result [ <p><span>Hello</span></p> ] 
2261                  *
2262                  * @name parents
2263                  * @type jQuery
2264                  * @param String expr An expression to filter the ancestors with
2265                  * @cat DOM/Traversing
2266                  */
2267                 parents: jQuery.parents,
2268
2269                 /**
2270                  * Get a set of elements containing the unique next siblings of each of the 
2271                  * matched set of elements.
2272                  * 
2273                  * It only returns the very next sibling, not all next siblings.
2274                  *
2275                  * @example $("p").next()
2276                  * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2277                  * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2278                  *
2279                  * @name next
2280                  * @type jQuery
2281                  * @cat DOM/Traversing
2282                  */
2283
2284                 /**
2285                  * Get a set of elements containing the unique next siblings of each of the 
2286                  * matched set of elements, and filtered by an expression.
2287                  * 
2288                  * It only returns the very next sibling, not all next siblings.
2289                  *
2290                  * @example $("p").next(".selected")
2291                  * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2292                  * @result [ <p class="selected">Hello Again</p> ]
2293                  *
2294                  * @name next
2295                  * @type jQuery
2296                  * @param String expr An expression to filter the next Elements with
2297                  * @cat DOM/Traversing
2298                  */
2299                 next: "jQuery.sibling(a).next",
2300
2301                 /**
2302                  * Get a set of elements containing the unique previous siblings of each of the 
2303                  * matched set of elements.
2304                  * 
2305                  * It only returns the immediately previous sibling, not all previous siblings.
2306                  *
2307                  * @example $("p").previous()
2308                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2309                  * @result [ <div><span>Hello Again</span></div> ]
2310                  *
2311                  * @name prev
2312                  * @type jQuery
2313                  * @cat DOM/Traversing
2314                  */
2315
2316                 /**
2317                  * Get a set of elements containing the unique previous siblings of each of the 
2318                  * matched set of elements, and filtered by an expression.
2319                  * 
2320                  * It only returns the immediately previous sibling, not all previous siblings.
2321                  *
2322                  * @example $("p").previous(".selected")
2323                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2324                  * @result [ <div><span>Hello</span></div> ]
2325                  *
2326                  * @name prev
2327                  * @type jQuery
2328                  * @param String expr An expression to filter the previous Elements with
2329                  * @cat DOM/Traversing
2330                  */
2331                 prev: "jQuery.sibling(a).prev",
2332
2333                 /**
2334                  * Get a set of elements containing all of the unique siblings of each of the 
2335                  * matched set of elements.
2336                  * 
2337                  * @example $("div").siblings()
2338                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2339                  * @result [ <p>Hello</p>, <p>And Again</p> ]
2340                  *
2341                  * @name siblings
2342                  * @type jQuery
2343                  * @cat DOM/Traversing
2344                  */
2345
2346                 /**
2347                  * Get a set of elements containing all of the unique siblings of each of the 
2348                  * matched set of elements, and filtered by an expression.
2349                  *
2350                  * @example $("div").siblings(".selected")
2351                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2352                  * @result [ <p class="selected">Hello Again</p> ]
2353                  *
2354                  * @name siblings
2355                  * @type jQuery
2356                  * @param String expr An expression to filter the sibling Elements with
2357                  * @cat DOM/Traversing
2358                  */
2359                 siblings: jQuery.sibling,
2360                 
2361                 
2362                 /**
2363                  * Get a set of elements containing all of the unique children of each of the 
2364                  * matched set of elements.
2365                  * 
2366                  * @example $("div").children()
2367                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2368                  * @result [ <span>Hello Again</span> ]
2369                  *
2370                  * @name children
2371                  * @type jQuery
2372                  * @cat DOM/Traversing
2373                  */
2374
2375                 /**
2376                  * Get a set of elements containing all of the unique children of each of the 
2377                  * matched set of elements, and filtered by an expression.
2378                  *
2379                  * @example $("div").children(".selected")
2380                  * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2381                  * @result [ <p class="selected">Hello Again</p> ]
2382                  *
2383                  * @name children
2384                  * @type jQuery
2385                  * @param String expr An expression to filter the child Elements with
2386                  * @cat DOM/Traversing
2387                  */
2388                 children: "jQuery.sibling(a.firstChild)"
2389         },
2390
2391         each: {
2392
2393                 removeAttr: function( key ) {
2394                         this.removeAttribute( key );
2395                 },
2396
2397                 /**
2398                  * Displays each of the set of matched elements if they are hidden.
2399                  * 
2400                  * @example $("p").show()
2401                  * @before <p style="display: none">Hello</p>
2402                  * @result [ <p style="display: block">Hello</p> ]
2403                  *
2404                  * @test var pass = true, div = $("div");
2405                  * div.show().each(function(){
2406                  *   if ( this.style.display == "none" ) pass = false;
2407                  * });
2408                  * ok( pass, "Show" );
2409                  *
2410                  * @name show
2411                  * @type jQuery
2412                  * @cat Effects
2413                  */
2414                 show: function(){
2415                         this.style.display = this.oldblock ? this.oldblock : "";
2416                         if ( jQuery.css(this,"display") == "none" )
2417                                 this.style.display = "block";
2418                 },
2419
2420                 /**
2421                  * Hides each of the set of matched elements if they are shown.
2422                  *
2423                  * @example $("p").hide()
2424                  * @before <p>Hello</p>
2425                  * @result [ <p style="display: none">Hello</p> ]
2426                  *
2427                  * var pass = true, div = $("div");
2428                  * div.hide().each(function(){
2429                  *   if ( this.style.display != "none" ) pass = false;
2430                  * });
2431                  * ok( pass, "Hide" );
2432                  *
2433                  * @name hide
2434                  * @type jQuery
2435                  * @cat Effects
2436                  */
2437                 hide: function(){
2438                         this.oldblock = this.oldblock || jQuery.css(this,"display");
2439                         if ( this.oldblock == "none" )
2440                                 this.oldblock = "block";
2441                         this.style.display = "none";
2442                 },
2443                 
2444                 /**
2445                  * Toggles each of the set of matched elements. If they are shown,
2446                  * toggle makes them hidden. If they are hidden, toggle
2447                  * makes them shown.
2448                  *
2449                  * @example $("p").toggle()
2450                  * @before <p>Hello</p><p style="display: none">Hello Again</p>
2451                  * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2452                  *
2453                  * @name toggle
2454                  * @type jQuery
2455                  * @cat Effects
2456                  */
2457                 toggle: function(){
2458                         $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
2459                 },
2460                 
2461                 /**
2462                  * Adds the specified class to each of the set of matched elements.
2463                  *
2464                  * @example $("p").addClass("selected")
2465                  * @before <p>Hello</p>
2466                  * @result [ <p class="selected">Hello</p> ]
2467                  *
2468                  * @test var div = $("div");
2469                  * div.addClass("test");
2470                  * var pass = true;
2471                  * for ( var i = 0; i < div.size(); i++ ) {
2472                  *  if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2473                  * }
2474                  * ok( pass, "Add Class" );
2475                  * 
2476                  * @name addClass
2477                  * @type jQuery
2478                  * @param String class A CSS class to add to the elements
2479                  * @cat DOM
2480                  */
2481                 addClass: function(c){
2482                         jQuery.className.add(this,c);
2483                 },
2484                 
2485                 /**
2486                  * Removes the specified class from the set of matched elements.
2487                  *
2488                  * @example $("p").removeClass("selected")
2489                  * @before <p class="selected">Hello</p>
2490                  * @result [ <p>Hello</p> ]
2491                  *
2492                  * @test var div = $("div").addClass("test");
2493                  * div.removeClass("test");
2494                  * var pass = true;
2495                  * for ( var i = 0; i < div.size(); i++ ) {
2496                  *  if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2497                  * }
2498                  * ok( pass, "Remove Class" );
2499                  *
2500                  * @name removeClass
2501                  * @type jQuery
2502                  * @param String class A CSS class to remove from the elements
2503                  * @cat DOM
2504                  */
2505                 removeClass: function(c){
2506                         jQuery.className.remove(this,c);
2507                 },
2508         
2509                 /**
2510                  * Adds the specified class if it is present, removes it if it is
2511                  * not present.
2512                  *
2513                  * @example $("p").toggleClass("selected")
2514                  * @before <p>Hello</p><p class="selected">Hello Again</p>
2515                  * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2516                  *
2517                  * @name toggleClass
2518                  * @type jQuery
2519                  * @param String class A CSS class with which to toggle the elements
2520                  * @cat DOM
2521                  */
2522                 toggleClass: function( c ){
2523                         jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2524                 },
2525                 
2526                 /**
2527                  * Removes all matched elements from the DOM. This does NOT remove them from the
2528                  * jQuery object, allowing you to use the matched elements further.
2529                  *
2530                  * @example $("p").remove();
2531                  * @before <p>Hello</p> how are <p>you?</p>
2532                  * @result how are
2533                  *
2534                  * @name remove
2535                  * @type jQuery
2536                  * @cat DOM/Manipulation
2537                  */
2538                  
2539                 /**
2540                  * Removes only elements (out of the list of matched elements) that match
2541                  * the specified jQuery expression. This does NOT remove them from the
2542                  * jQuery object, allowing you to use the matched elements further.
2543                  *
2544                  * @example $("p").remove(".hello");
2545                  * @before <p class="hello">Hello</p> how are <p>you?</p>
2546                  * @result how are <p>you?</p>
2547                  *
2548                  * @name remove
2549                  * @type jQuery
2550                  * @param String expr A jQuery expression to filter elements by.
2551                  * @cat DOM/Manipulation
2552                  */
2553                 remove: function(a){
2554                         if ( !a || jQuery.filter( a, [this] ).r )
2555                                 this.parentNode.removeChild( this );
2556                 },
2557         
2558                 /**
2559                  * Removes all child nodes from the set of matched elements.
2560                  *
2561                  * @example $("p").empty()
2562                  * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2563                  * @result [ <p></p> ]
2564                  *
2565                  * @name empty
2566                  * @type jQuery
2567                  * @cat DOM/Manipulation
2568                  */
2569                 empty: function(){
2570                         while ( this.firstChild )
2571                                 this.removeChild( this.firstChild );
2572                 },
2573                 
2574                 /**
2575                  * Binds a particular event (like click) to a each of a set of match elements.
2576                  *
2577                  * @example $("p").bind( "click", function() { alert("Hello"); } )
2578                  * @before <p>Hello</p>
2579                  * @result [ <p>Hello</p> ]
2580                  *
2581                  * Cancel a default action and prevent it from bubbling by returning false
2582                  * from your function.
2583                  *
2584                  * @example $("form").bind( "submit", function() { return false; } )
2585                  *
2586                  * Cancel a default action by using the preventDefault method.
2587                  *
2588                  * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2589                  *
2590                  * Stop an event from bubbling by using the stopPropogation method.
2591                  *
2592                  * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2593                  *
2594                  * @name bind
2595                  * @type jQuery
2596                  * @param String type An event type
2597                  * @param Function fn A function to bind to the event on each of the set of matched elements
2598                  * @cat Events
2599                  */
2600                 bind: function( type, fn ) {
2601                         if ( fn.constructor == String )
2602                                 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2603                         jQuery.event.add( this, type, fn );
2604                 },
2605                 
2606                 /**
2607                  * The opposite of bind, removes a bound event from each of the matched
2608                  * elements. You must pass the identical function that was used in the original 
2609                  * bind method.
2610                  *
2611                  * @example $("p").unbind( "click", function() { alert("Hello"); } )
2612                  * @before <p onclick="alert('Hello');">Hello</p>
2613                  * @result [ <p>Hello</p> ]
2614                  *
2615                  * @name unbind
2616                  * @type jQuery
2617                  * @param String type An event type
2618                  * @param Function fn A function to unbind from the event on each of the set of matched elements
2619                  * @cat Events
2620                  */
2621                  
2622                 /**
2623                  * Removes all bound events of a particular type from each of the matched
2624                  * elements.
2625                  *
2626                  * @example $("p").unbind( "click" )
2627                  * @before <p onclick="alert('Hello');">Hello</p>
2628                  * @result [ <p>Hello</p> ]
2629                  *
2630                  * @name unbind
2631                  * @type jQuery
2632                  * @param String type An event type
2633                  * @cat Events
2634                  */
2635                  
2636                 /**
2637                  * Removes all bound events from each of the matched elements.
2638                  *
2639                  * @example $("p").unbind()
2640                  * @before <p onclick="alert('Hello');">Hello</p>
2641                  * @result [ <p>Hello</p> ]
2642                  *
2643                  * @name unbind
2644                  * @type jQuery
2645                  * @cat Events
2646                  */
2647                 unbind: function( type, fn ) {
2648                         jQuery.event.remove( this, type, fn );
2649                 },
2650                 
2651                 /**
2652                  * Trigger a type of event on every matched element.
2653                  *
2654                  * @example $("p").trigger("click")
2655                  * @before <p click="alert('hello')">Hello</p>
2656                  * @result alert('hello')
2657                  *
2658                  * @name trigger
2659                  * @type jQuery
2660                  * @param String type An event type to trigger.
2661                  * @cat Events
2662                  */
2663                 trigger: function( type, data ) {
2664                         jQuery.event.trigger( type, data, this );
2665                 }
2666         }
2667 };
2668
2669 jQuery.init();