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