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