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