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