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