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