Fixed bug with parents/siblings, etc.
[jquery.git] / 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          */
95         jquery: "$Rev$",
96         
97         /**
98          * The number of elements currently matched.
99          *
100          * @example $("img").length;
101          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
102          * @result 2
103          *
104          * @property
105          * @name length
106          * @type Number
107          */
108         
109         /**
110          * The number of elements currently matched.
111          *
112          * @example $("img").size();
113          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
114          * @result 2
115          *
116          * @name size
117          * @type Number
118          */
119         size: function() {
120                 return this.length;
121         },
122         
123         /**
124          * Access all matched elements. This serves as a backwards-compatible
125          * way of accessing all matched elements (other than the jQuery object
126          * itself, which is, in fact, an array of elements).
127          *
128          * @example $("img").get();
129          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
130          * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
131          *
132          * @name get
133          * @type Array<Element>
134          */
135          
136         /**
137          * Access a single matched element. <tt>num</tt> is used to access the 
138          * <tt>num</tt>th element matched.
139          *
140          * @example $("img").get(1);
141          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
142          * @result [ <img src="test1.jpg"/> ]
143          *
144          * @name get
145          * @type Element
146          * @param Number num Access the element in the <tt>num</tt>th position.
147          */
148          
149         /**
150          * Set the jQuery object to an array of elements.
151          *
152          * @example $("img").get([ document.body ]);
153          * @result $("img").get() == [ document.body ]
154          *
155          * @private
156          * @name get
157          * @type jQuery
158          * @param Elements elems An array of elements
159          */
160         get: function( num ) {
161                 // Watch for when an array (of elements) is passed in
162                 if ( num && num.constructor == Array ) {
163
164                         // Use a tricky hack to make the jQuery object
165                         // look and feel like an array
166                         this.length = 0;
167                         [].push.apply( this, num );
168                         
169                         return this;
170                 } else
171                         return num == undefined ?
172
173                                 // Return a 'clean' array
174                                 jQuery.map( this, function(a){ return a } ) :
175
176                                 // Return just the object
177                                 this[num];
178         },
179
180         /**
181          * Execute a function within the context of every matched element.
182          * This means that every time the passed-in function is executed
183          * (which is once for every element matched) the 'this' keyword
184          * points to the specific element.
185          *
186          * Additionally, the function, when executed, is passed a single
187          * argument representing the position of the element in the matched
188          * set.
189          *
190          * @example $("img").each(function(){ this.src = "test.jpg"; });
191          * @before <img/> <img/>
192          * @result <img src="test.jpg"/> <img src="test.jpg"/>
193          *
194          * @name each
195          * @type jQuery
196          * @param Function fn A function to execute
197          */
198         each: function( fn, args ) {
199                 // Iterate through all of the matched elements
200                 for ( var i = 0; i < this.length; i++ )
201                 
202                         // Execute the function within the context of each element
203                         fn.apply( this[i], args || [i] );
204                 
205                 return this;
206         },
207         
208         /**
209          * Access a property on the first matched element.
210          * This method makes it easy to retreive a property value
211          * from the first matched element.
212          *
213          * @example $("img").attr("src");
214          * @before <img src="test.jpg"/>
215          * @result test.jpg
216          *
217          * @name attr
218          * @type Object
219          * @param String name The name of the property to access.
220          */
221          
222         /**
223          * Set a hash of key/value object properties to all matched elements.
224          * This serves as the best way to set a large number of properties
225          * on all matched elements.
226          *
227          * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
228          * @before <img/>
229          * @result <img src="test.jpg" alt="Test Image"/>
230          *
231          * @name attr
232          * @type jQuery
233          * @param Hash prop A set of key/value pairs to set as object properties.
234          */
235          
236         /**
237          * Set a single property to a value, on all matched elements.
238          *
239          * @example $("img").attr("src","test.jpg");
240          * @before <img/>
241          * @result <img src="test.jpg"/>
242          *
243          * @name attr
244          * @type jQuery
245          * @param String key The name of the property to set.
246          * @param Object value The value to set the property to.
247          */
248         attr: function( key, value, type ) {
249                 // Check to see if we're setting style values
250                 return key.constructor != String || value ?
251                         this.each(function(){
252                                 // See if we're setting a hash of styles
253                                 if ( value == undefined )
254                                         // Set all the styles
255                                         for ( var prop in key )
256                                                 jQuery.attr(
257                                                         type ? this.style : this,
258                                                         prop, key[prop]
259                                                 );
260                                 
261                                 // See if we're setting a single key/value style
262                                 else
263                                         jQuery.attr(
264                                                 type ? this.style : this,
265                                                 key, value
266                                         );
267                         }) :
268                         
269                         // Look for the case where we're accessing a style value
270                         jQuery[ type || "attr" ]( this[0], key );
271         },
272         
273         /**
274          * Access a style property on the first matched element.
275          * This method makes it easy to retreive a style property value
276          * from the first matched element.
277          *
278          * @example $("p").css("red");
279          * @before <p style="color:red;">Test Paragraph.</p>
280          * @result red
281          *
282          * @name css
283          * @type Object
284          * @param String name The name of the property to access.
285          */
286          
287         /**
288          * Set a hash of key/value style properties to all matched elements.
289          * This serves as the best way to set a large number of style properties
290          * on all matched elements.
291          *
292          * @example $("p").css({ color: "red", background: "blue" });
293          * @before <p>Test Paragraph.</p>
294          * @result <p style="color:red; background:blue;">Test Paragraph.</p>
295          *
296          * @name css
297          * @type jQuery
298          * @param Hash prop A set of key/value pairs to set as style properties.
299          */
300          
301         /**
302          * Set a single style property to a value, on all matched elements.
303          *
304          * @example $("p").css("color","red");
305          * @before <p>Test Paragraph.</p>
306          * @result <p style="color:red;">Test Paragraph.</p>
307          *
308          * @name css
309          * @type jQuery
310          * @param String key The name of the property to set.
311          * @param Object value The value to set the property to.
312          */
313         css: function( key, value ) {
314                 return this.attr( key, value, "curCSS" );
315         },
316         
317         /**
318          * Retreive the text contents of all matched elements. The result is
319          * a string that contains the combined text contents of all matched
320          * elements. This method works on both HTML and XML documents.
321          *
322          * @example $("p").text();
323          * @before <p>Test Paragraph.</p>
324          * @result Test Paragraph.
325          *
326          * @name text
327          * @type String
328          */
329         text: function(e) {
330                 e = e || this;
331                 var t = "";
332                 for ( var j = 0; j < e.length; j++ ) {
333                         var r = e[j].childNodes;
334                         for ( var i = 0; i < r.length; i++ )
335                                 t += r[i].nodeType != 1 ?
336                                         r[i].nodeValue : jQuery.fn.text([ r[i] ]);
337                 }
338                 return t;
339         },
340         
341         /**
342          * Wrap all matched elements with a structure of other elements.
343          * This wrapping process is most useful for injecting additional
344          * stucture into a document, without ruining the original semantic
345          * qualities of a document.
346          *
347          * The way that is works is that it goes through the first element argument
348          * provided and finds the deepest element within the structure - it is that
349          * element that will en-wrap everything else.
350          *
351          * @example $("p").wrap("<div class='wrap'></div>");
352          * @before <p>Test Paragraph.</p>
353          * @result <div class='wrap'><p>Test Paragraph.</p></div>
354          *
355          * @name wrap
356          * @type jQuery
357          * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
358          * @any Element elem A DOM element that will be wrapped.
359          * @any Array<Element> elems An array of elements, the first of which will be wrapped.
360          * @any Object obj Any object, converted to a string, then a text node.
361          */
362         wrap: function() {
363                 // The elements to wrap the target around
364                 var a = jQuery.clean(arguments);
365                 
366                 // Wrap each of the matched elements individually
367                 return this.each(function(){
368                         // Clone the structure that we're using to wrap
369                         var b = a[0].cloneNode(true);
370                         
371                         // Insert it before the element to be wrapped
372                         this.parentNode.insertBefore( b, this );
373                         
374                         // Find he deepest point in the wrap structure
375                         while ( b.firstChild )
376                                 b = b.firstChild;
377                         
378                         // Move the matched element to within the wrap structure
379                         b.appendChild( this );
380                 });
381         },
382         
383         /**
384          * Append any number of elements to the inside of all matched elements.
385          * This operation is similar to doing an <tt>appendChild</tt> to all the 
386          * specified elements, adding them into the document.
387          * 
388          * @example $("p").append("<b>Hello</b>");
389          * @before <p>I would like to say: </p>
390          * @result <p>I would like to say: <b>Hello</b></p>
391          *
392          * @name append
393          * @type jQuery
394          * @any String html A string of HTML, that will be created on the fly and appended to the target.
395          * @any Element elem A DOM element that will be appended.
396          * @any Array<Element> elems An array of elements, all of which will be appended.
397          * @any Object obj Any object, converted to a string, then a text node.
398          */
399         append: function() {
400                 return this.domManip(arguments, true, 1, function(a){
401                         this.appendChild( a );
402                 });
403         },
404         
405         /**
406          * Prepend any number of elements to the inside of all matched elements.
407          * This operation is the best way to insert a set of elements inside, at the 
408          * beginning, of all the matched element.
409          * 
410          * @example $("p").prepend("<b>Hello</b>");
411          * @before <p>, how are you?</p>
412          * @result <p><b>Hello</b>, how are you?</p>
413          *
414          * @name prepend
415          * @type jQuery
416          * @any String html A string of HTML, that will be created on the fly and prepended to the target.
417          * @any Element elem A DOM element that will be prepended.
418          * @any Array<Element> elems An array of elements, all of which will be prepended.
419          * @any Object obj Any object, converted to a string, then a text node.
420          */
421         prepend: function() {
422                 return this.domManip(arguments, true, -1, function(a){
423                         this.insertBefore( a, this.firstChild );
424                 });
425         },
426         
427         /**
428          * Insert any number of elements before each of the matched elements.
429          * 
430          * @example $("p").before("<b>Hello</b>");
431          * @before <p>how are you?</p>
432          * @result <b>Hello</b><p>how are you?</p>
433          *
434          * @name before
435          * @type jQuery
436          * @any String html A string of HTML, that will be created on the fly and inserted.
437          * @any Element elem A DOM element that will beinserted.
438          * @any Array<Element> elems An array of elements, all of which will be inserted.
439          * @any Object obj Any object, converted to a string, then a text node.
440          */
441         before: function() {
442                 return this.domManip(arguments, false, 1, function(a){
443                         this.parentNode.insertBefore( a, this );
444                 });
445         },
446         
447         /**
448          * Insert any number of elements after each of the matched elements.
449          * 
450          * @example $("p").after("<p>I'm doing fine.</p>");
451          * @before <p>How are you?</p>
452          * @result <p>How are you?</p><p>I'm doing fine.</p>
453          *
454          * @name after
455          * @type jQuery
456          * @any String html A string of HTML, that will be created on the fly and inserted.
457          * @any Element elem A DOM element that will beinserted.
458          * @any Array<Element> elems An array of elements, all of which will be inserted.
459          * @any Object obj Any object, converted to a string, then a text node.
460          */
461         after: function() {
462                 return this.domManip(arguments, false, -1, function(a){
463                         this.parentNode.insertBefore( a, this.nextSibling );
464                 });
465         },
466         
467         /**
468          * End the most recent 'destructive' operation, reverting the list of matched elements
469          * back to its previous state. After an end operation, the list of matched elements will 
470          * revert to the last state of matched elements.
471          *
472          * @example $("p").find("span").end();
473          * @before <p><span>Hello</span>, how are you?</p>
474          * @result $("p").find("span").end() == [ <p>...</p> ]
475          *
476          * @name end
477          * @type jQuery
478          */
479         end: function() {
480                 return this.get( this.stack.pop() );
481         },
482         
483         /**
484          * Searches for all elements that match the specified expression.
485          * This method is the optimal way of finding additional descendant
486          * elements with which to process.
487          *
488          * All searching is done using a jQuery expression. The expression can be 
489          * written using CSS 1-3 Selector syntax, or basic XPath.
490          *
491          * @example $("p").find("span");
492          * @before <p><span>Hello</span>, how are you?</p>
493          * @result $("p").find("span") == [ <span>Hello</span> ]
494          *
495          * @name find
496          * @type jQuery
497          * @param String expr An expression to search with.
498          */
499         find: function(t) {
500                 return this.pushStack( jQuery.map( this, function(a){
501                         return jQuery.find(t,a);
502                 }), arguments );
503         },
504         
505         /**
506          * Removes all elements from the set of matched elements that do not 
507          * match the specified expression. This method is used to narrow down
508          * the results of a search.
509          *
510          * All searching is done using a jQuery expression. The expression
511          * can be written using CSS 1-3 Selector syntax, or basic XPath.
512          * 
513          * @example $("p").filter(".selected")
514          * @before <p class="selected">Hello</p><p>How are you?</p>
515          * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
516          *
517          * @name filter
518          * @type jQuery
519          * @param String expr An expression to search with.
520          */
521
522         /**
523          * Removes all elements from the set of matched elements that do not
524          * match at least one of the expressions passed to the function. This 
525          * method is used when you want to filter the set of matched elements 
526          * through more than one expression.
527          *
528          * Elements will be retained in the jQuery object if they match at
529          * least one of the expressions passed.
530          *
531          * @example $("p").filter([".selected", ":first"])
532          * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
533          * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
534          *
535          * @name filter
536          * @type jQuery
537          * @param Array<String> exprs A set of expressions to evaluate against
538          */
539         filter: function(t) {
540                 return this.pushStack(
541                         t.constructor == Array &&
542                         jQuery.map(this,function(a){
543                                 for ( var i = 0; i < t.length; i++ )
544                                         if ( jQuery.filter(t[i],[a]).r.length )
545                                                 return a;
546                         }) ||
547
548                         t.constructor == Boolean &&
549                         ( t ? this.get() : [] ) ||
550
551                         t.constructor == Function &&
552                         jQuery.grep( this, t ) ||
553
554                         jQuery.filter(t,this).r, arguments );
555         },
556         
557         /**
558          * Removes the specified Element from the set of matched elements. This
559          * method is used to remove a single Element from a jQuery object.
560          *
561          * @example $("p").not( document.getElementById("selected") )
562          * @before <p>Hello</p><p id="selected">Hello Again</p>
563          * @result [ <p>Hello</p> ]
564          *
565          * @name not
566          * @type jQuery
567          * @param Element el An element to remove from the set
568          */
569
570         /**
571          * Removes elements matching the specified expression from the set
572          * of matched elements. This method is used to remove one or more
573          * elements from a jQuery object.
574          * 
575          * @example $("p").not("#selected")
576          * @before <p>Hello</p><p id="selected">Hello Again</p>
577          * @result [ <p>Hello</p> ]
578          *
579          * @name not
580          * @type jQuery
581          * @param String expr An expression with which to remove matching elements
582          */
583         not: function(t) {
584                 return this.pushStack( t.constructor == String ?
585                         jQuery.filter(t,this,false).r :
586                         jQuery.grep(this,function(a){ return a != t; }), arguments );
587         },
588
589         /**
590          * Adds the elements matched by the expression to the jQuery object. This
591          * can be used to concatenate the result sets of two expressions.
592          *
593          * @example $("p").add("span")
594          * @before <p>Hello</p><p><span>Hello Again</span></p>
595          * @result [ <p>Hello</p>, <span>Hello Again</span> ]
596          *
597          * @name add
598          * @type jQuery
599          * @param String expr An expression whose matched elements are added
600          */
601
602         /**
603          * Adds each of the Elements in the array to the set of matched elements.
604          * This is used to add a set of Elements to a jQuery object.
605          *
606          * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
607          * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
608          * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
609          *
610          * @name add
611          * @type jQuery
612          * @param Array<Element> els An array of Elements to add
613          */
614
615         /**
616          * Adds a single Element to the set of matched elements. This is used to
617          * add a single Element to a jQuery object.
618          *
619          * @example $("p").add( document.getElementById("a") )
620          * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
621          * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
622          *
623          * @name add
624          * @type jQuery
625          * @param Element el An Element to add
626          */
627         add: function(t) {
628                 return this.pushStack( jQuery.merge( this, t.constructor == String ?
629                         jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
630         },
631         
632         /**
633          * A wrapper function for each() to be used by append and prepend.
634          * Handles cases where you're trying to modify the inner contents of
635          * a table, when you actually need to work with the tbody.
636          *
637          * @member jQuery
638          * @param {String} expr The expression with which to filter
639          * @type Boolean
640          */
641         is: function(expr) {
642                 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
643         },
644         
645         /**
646          * 
647          *
648          * @private
649          * @name domManip
650          * @param Array args
651          * @param Boolean table
652          * @param Number int
653          * @param Function fn The function doing the DOM manipulation.
654          * @type jQuery
655          */
656         domManip: function(args, table, dir, fn){
657                 var clone = this.size() > 1;
658                 var a = jQuery.clean(args);
659                 
660                 return this.each(function(){
661                         var obj = this;
662                         
663                         if ( table && this.nodeName == "TABLE" ) {
664                                 var tbody = this.getElementsByTagName("tbody");
665
666                                 if ( !tbody.length ) {
667                                         obj = document.createElement("tbody");
668                                         this.appendChild( obj );
669                                 } else
670                                         obj = tbody[0];
671                         }
672                         //alert( obj );
673                         for ( var i = ( dir < 0 ? a.length - 1 : 0 );
674                                 i != ( dir < 0 ? dir : a.length ); i += dir ) {
675                                         fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
676                                         //alert( fn );
677                         }
678                 });
679         },
680         
681         /**
682          * 
683          *
684          * @private
685          * @name pushStack
686          * @param Array a
687          * @param Array args
688          * @type jQuery
689          */
690         pushStack: function(a,args) {
691                 var fn = args && args[args.length-1];
692
693                 if ( !fn || fn.constructor != Function ) {
694                         if ( !this.stack ) this.stack = [];
695                         this.stack.push( this.get() );
696                         this.get( a );
697                 } else {
698                         var old = this.get();
699                         this.get( a );
700                         if ( fn.constructor == Function )
701                                 return this.each( fn );
702                         this.get( old );
703                 }
704
705                 return this;
706         }
707 };
708
709 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
710         if ( !prop ) { prop = obj; obj = this; }
711         for ( var i in prop ) obj[i] = prop[i];
712         return obj;
713 };
714
715 jQuery.extend({
716         init: function(){
717                 jQuery.initDone = true;
718                 
719                 for ( var i in jQuery.macros.axis ) new function(){
720                         var t = jQuery.macros.axis[i];
721
722                         jQuery.fn[ i ] = function(a) {
723                                 var ret = jQuery.map(this,t);
724                                 if ( a && a.constructor == String )
725                                         ret = jQuery.filter(a,ret).r;
726                                 return this.pushStack( ret, arguments );
727                         };
728                 };
729         
730                 // appendTo, prependTo, beforeTo, afterTo
731                 
732                 for ( var i = 0; i < jQuery.macros.to.length; i++ ) new function(){
733                         var n = jQuery.macros.to[i];
734                         jQuery.fn[ n + "To" ] = function(){
735                                 var a = arguments;
736                                 return this.each(function(){
737                                         for ( var i = 0; i < a.length; i++ )
738                                                 $(a[i])[n]( this );
739                                 });
740                         };
741                 };
742                 
743                 for ( var i in jQuery.macros.each ) new function() {
744                         var n = jQuery.macros.each[i];
745                         jQuery.fn[ i ] = function() {
746                                 return this.each( n, arguments );
747                         };
748                 };
749                 
750                 for ( var i in jQuery.macros.attr ) new function() {
751                         var n = jQuery.macros.attr[i] || i;
752                         jQuery.fn[ i ] = function(h) {
753                                 return h == undefined ?
754                                         this.length ? this[0][n] : null :
755                                         this.attr( n, h );
756                         };
757                 };
758         
759                 for ( var i = 0; i < jQuery.macros.css.length; i++ ) new function() {
760                         var n = jQuery.macros.css[i];
761                         jQuery.fn[ i ] = function(h) {
762                                 return h == undefined ?
763                                         ( this.length ? jQuery.css( this[0], n ) : null ) :
764                                         this.css( n, h );
765                         };
766                 };
767         
768         },
769         
770         className: {
771                 add: function(o,c){
772                         if (jQuery.className.has(o,c)) return;
773                         o.className += ( o.className ? " " : "" ) + c;
774                 },
775                 remove: function(o,c){
776                         o.className = !c ? "" :
777                                 o.className.replace(
778                                         new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
779                 },
780                 has: function(e,a) {
781                         if ( e.className )
782                                 e = e.className;
783                         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
784                 }
785         },
786         
787         /**
788          * Swap in/out style options.
789          * @private
790          */
791         swap: function(e,o,f) {
792                 for ( var i in o ) {
793                         e.style["old"+i] = e.style[i];
794                         e.style[i] = o[i];
795                 }
796                 f.apply( e, [] );
797                 for ( var i in o )
798                         e.style[i] = e.style["old"+i];
799         },
800         
801         css: function(e,p) {
802                 if ( p == "height" || p == "width" ) {
803                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
804         
805                         for ( var i in d ) {
806                                 old["padding" + d[i]] = 0;
807                                 old["border" + d[i] + "Width"] = 0;
808                         }
809         
810                         jQuery.swap( e, old, function() {
811                                 if (jQuery.css(e,"display") != "none") {
812                                         oHeight = e.offsetHeight;
813                                         oWidth = e.offsetWidth;
814                                 } else
815                                         jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
816                                                 function(){
817                                                         oHeight = e.clientHeight;
818                                                         oWidth = e.clientWidth;
819                                                 });
820                         });
821         
822                         return p == "height" ? oHeight : oWidth;
823                 } else if ( p == "opacity" && jQuery.browser.msie )
824                         return parseFloat(  jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
825
826                 return jQuery.curCSS( e, p );
827         },
828
829         curCSS: function(e,p,force) {
830                 var r;
831         
832                 if (!force && e.style[p])
833                         r = e.style[p];
834                 else if (e.currentStyle) {
835                         p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); 
836                         r = e.currentStyle[p];
837                 } else if (document.defaultView && document.defaultView.getComputedStyle) {
838                         p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
839                         var s = document.defaultView.getComputedStyle(e,"");
840                         r = s ? s.getPropertyValue(p) : null;
841                 }
842                 
843                 return r;
844         },
845         
846         clean: function(a) {
847                 var r = [];
848                 for ( var i = 0; i < a.length; i++ ) {
849                         if ( a[i].constructor == String ) {
850         
851                                 if ( !a[i].indexOf("<tr") ) {
852                                         var tr = true;
853                                         a[i] = "<table>" + a[i] + "</table>";
854                                 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
855                                         var td = true;
856                                         a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
857                                 }
858         
859                                 var div = document.createElement("div");
860                                 div.innerHTML = a[i];
861         
862                                 if ( tr || td ) {
863                                         div = div.firstChild.firstChild;
864                                         if ( td ) div = div.firstChild;
865                                 }
866         
867                                 for ( var j = 0; j < div.childNodes.length; j++ )
868                                         r.push( div.childNodes[j] );
869                         } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
870                                 for ( var k = 0; k < a[i].length; k++ )
871                                         r.push( a[i][k] );
872                         else if ( a[i] !== null )
873                                 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
874                 }
875                 return r;
876         },
877         
878         expr: {
879                 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
880                 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
881                 ":": {
882                         // Position Checks
883                         lt: "i<m[3]-0",
884                         gt: "i>m[3]-0",
885                         nth: "m[3]-0==i",
886                         eq: "m[3]-0==i",
887                         first: "i==0",
888                         last: "i==r.length-1",
889                         even: "i%2==0",
890                         odd: "i%2",
891                         
892                         // Child Checks
893                         "first-child": "jQuery.sibling(a,0).cur",
894                         "last-child": "jQuery.sibling(a,0).last",
895                         "only-child": "jQuery.sibling(a).length==1",
896                         
897                         // Parent Checks
898                         parent: "a.childNodes.length",
899                         empty: "!a.childNodes.length",
900                         
901                         // Text Check
902                         contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
903                         
904                         // Visibility
905                         visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
906                         hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
907                         
908                         // Form elements
909                         enabled: "!a.disabled",
910                         disabled: "a.disabled",
911                         checked: "a.checked"
912                 },
913                 ".": "jQuery.className.has(a,m[2])",
914                 "@": {
915                         "=": "z==m[4]",
916                         "!=": "z!=m[4]",
917                         "^=": "!z.indexOf(m[4])",
918                         "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
919                         "*=": "z.indexOf(m[4])>=0",
920                         "": "z"
921                 },
922                 "[": "jQuery.find(m[2],a).length"
923         },
924         
925         token: [
926                 "\\.\\.|/\\.\\.", "a.parentNode",
927                 ">|/", "jQuery.sibling(a.firstChild)",
928                 "\\+", "jQuery.sibling(a).next",
929                 "~", function(a){
930                         var r = [];
931                         var s = jQuery.sibling(a);
932                         if ( s.n > 0 )
933                                 for ( var i = s.n; i < s.length; i++ )
934                                         r.push( s[i] );
935                         return r;
936                 }
937         ],
938         
939         find: function( t, context ) {
940                 // Make sure that the context is a DOM Element
941                 if ( context && context.nodeType == undefined )
942                         context = null;
943         
944                 // Set the correct context (if none is provided)
945                 context = context || jQuery.context || document;
946         
947                 if ( t.constructor != String ) return [t];
948         
949                 if ( !t.indexOf("//") ) {
950                         context = context.documentElement;
951                         t = t.substr(2,t.length);
952                 } else if ( !t.indexOf("/") ) {
953                         context = context.documentElement;
954                         t = t.substr(1,t.length);
955                         // FIX Assume the root element is right :(
956                         if ( t.indexOf("/") >= 1 )
957                                 t = t.substr(t.indexOf("/"),t.length);
958                 }
959         
960                 var ret = [context];
961                 var done = [];
962                 var last = null;
963         
964                 while ( t.length > 0 && last != t ) {
965                         var r = [];
966                         last = t;
967         
968                         t = jQuery.trim(t).replace( /^\/\//i, "" );
969                         
970                         var foundToken = false;
971                         
972                         for ( var i = 0; i < jQuery.token.length; i += 2 ) {
973                                 var re = new RegExp("^(" + jQuery.token[i] + ")");
974                                 var m = re.exec(t);
975                                 
976                                 if ( m ) {
977                                         r = ret = jQuery.map( ret, jQuery.token[i+1] );
978                                         t = jQuery.trim( t.replace( re, "" ) );
979                                         foundToken = true;
980                                 }
981                         }
982                         
983                         if ( !foundToken ) {
984                                 if ( !t.indexOf(",") || !t.indexOf("|") ) {
985                                         if ( ret[0] == context ) ret.shift();
986                                         done = jQuery.merge( done, ret );
987                                         r = ret = [context];
988                                         t = " " + t.substr(1,t.length);
989                                 } else {
990                                         var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
991                                         var m = re2.exec(t);
992                 
993                                         if ( m[1] == "#" ) {
994                                                 // Ummm, should make this work in all XML docs
995                                                 var oid = document.getElementById(m[2]);
996                                                 r = ret = oid ? [oid] : [];
997                                                 t = t.replace( re2, "" );
998                                         } else {
999                                                 if ( !m[2] || m[1] == "." ) m[2] = "*";
1000                 
1001                                                 for ( var i = 0; i < ret.length; i++ )
1002                                                         r = jQuery.merge( r,
1003                                                                 m[2] == "*" ?
1004                                                                         jQuery.getAll(ret[i]) :
1005                                                                         ret[i].getElementsByTagName(m[2])
1006                                                         );
1007                                         }
1008                                 }
1009                         }
1010         
1011                         if ( t ) {
1012                                 var val = jQuery.filter(t,r);
1013                                 ret = r = val.r;
1014                                 t = jQuery.trim(val.t);
1015                         }
1016                 }
1017         
1018                 if ( ret && ret[0] == context ) ret.shift();
1019                 done = jQuery.merge( done, ret );
1020         
1021                 return done;
1022         },
1023         
1024         getAll: function(o,r) {
1025                 r = r || [];
1026                 var s = o.childNodes;
1027                 for ( var i = 0; i < s.length; i++ )
1028                         if ( s[i].nodeType == 1 ) {
1029                                 r.push( s[i] );
1030                                 jQuery.getAll( s[i], r );
1031                         }
1032                 return r;
1033         },
1034         
1035         attr: function(o,a,v){
1036                 if ( a && a.constructor == String ) {
1037                         var fix = {
1038                                 "for": "htmlFor",
1039                                 "class": "className",
1040                                 "float": "cssFloat"
1041                         };
1042                         
1043                         a = (fix[a] && fix[a].replace && fix[a] || a)
1044                                 .replace(/-([a-z])/ig,function(z,b){
1045                                         return b.toUpperCase();
1046                                 });
1047                         
1048                         if ( v != undefined ) {
1049                                 o[a] = v;
1050                                 if ( o.setAttribute && a != "disabled" )
1051                                         o.setAttribute(a,v);
1052                         }
1053                         
1054                         return o[a] || o.getAttribute && o.getAttribute(a) || "";
1055                 } else
1056                         return "";
1057         },
1058
1059         // The regular expressions that power the parsing engine
1060         parse: [
1061                 // Match: [@value='test'], [@foo]
1062                 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1063
1064                 // Match: [div], [div p]
1065                 [ "(\\[)Q\\]", 0 ],
1066
1067                 // Match: :contains('foo')
1068                 [ "(:)S\\(Q\\)", 0 ],
1069
1070                 // Match: :even, :last-chlid
1071                 [ "([:.#]*)S", 0 ]
1072         ],
1073         
1074         filter: function(t,r,not) {
1075                 // Figure out if we're doing regular, or inverse, filtering
1076                 var g = not !== false ? jQuery.grep :
1077                         function(a,f) {return jQuery.grep(a,f,true);};
1078                 
1079                 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1080
1081                         var p = jQuery.parse;
1082
1083                         for ( var i = 0; i < p.length; i++ ) {
1084                                 var re = new RegExp( "^" + p[i][0]
1085
1086                                         // Look for a string-like sequence
1087                                         .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1088
1089                                         // Look for something (optionally) enclosed with quotes
1090                                         .replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
1091
1092                                 var m = re.exec( t );
1093
1094                                 if ( m ) {
1095                                         // Re-organize the match
1096                                         if ( p[i][1] )
1097                                                 m = ["", m[1], m[3], m[2], m[4]];
1098
1099                                         // Remove what we just matched
1100                                         t = t.replace( re, "" );
1101
1102                                         break;
1103                                 }
1104                         }
1105         
1106                         // :not() is a special case that can be optomized by
1107                         // keeping it out of the expression list
1108                         if ( m[1] == ":" && m[2] == "not" )
1109                                 r = jQuery.filter(m[3],r,false).r;
1110                         
1111                         // Otherwise, find the expression to execute
1112                         else {
1113                                 var f = jQuery.expr[m[1]];
1114                                 if ( f.constructor != String )
1115                                         f = jQuery.expr[m[1]][m[2]];
1116                                         
1117                                 // Build a custom macro to enclose it
1118                                 eval("f = function(a,i){" + 
1119                                         ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) + 
1120                                         "return " + f + "}");
1121                                 
1122                                 // Execute it against the current filter
1123                                 r = g( r, f );
1124                         }
1125                 }
1126         
1127                 // Return an array of filtered elements (r)
1128                 // and the modified expression string (t)
1129                 return { r: r, t: t };
1130         },
1131         
1132         /**
1133          * Remove the whitespace from the beginning and end of a string.
1134          *
1135          * @private
1136          * @name $.trim
1137          * @type String
1138          * @param String str The string to trim.
1139          */
1140         trim: function(t){
1141                 return t.replace(/^\s+|\s+$/g, "");
1142         },
1143         
1144         /**
1145          * All ancestors of a given element.
1146          *
1147          * @private
1148          * @name $.parents
1149          * @type Array<Element>
1150          * @param Element elem The element to find the ancestors of.
1151          */
1152         parents: function(a){
1153                 var b = [];
1154                 var c = a.parentNode;
1155                 while ( c && c != document ) {
1156                         b.push( c );
1157                         c = c.parentNode;
1158                 }
1159                 return b;
1160         },
1161         
1162         /**
1163          * All elements on a specified axis.
1164          *
1165          * @private
1166          * @name $.sibling
1167          * @type Array
1168          * @param Element elem The element to find all the siblings of (including itself).
1169          */
1170         sibling: function(a,n) {
1171                 var type = [];
1172                 var tmp = a.parentNode.childNodes;
1173                 for ( var i = 0; i < tmp.length; i++ ) {
1174                         if ( tmp[i].nodeType == 1 )
1175                                 type.push( tmp[i] );
1176                         if ( tmp[i] == a )
1177                                 type.n = type.length - 1;
1178                 }
1179                 type.last = type.n == type.length - 1;
1180                 type.cur =
1181                         n == "even" && type.n % 2 == 0 ||
1182                         n == "odd" && type.n % 2 ||
1183                         type[n] == a;
1184                 type.prev = type[type.n - 1];
1185                 type.next = type[type.n + 1];
1186                 return type;
1187         },
1188         
1189         /**
1190          * Merge two arrays together, removing all duplicates.
1191          *
1192          * @private
1193          * @name $.merge
1194          * @type Array
1195          * @param Array a The first array to merge.
1196          * @param Array b The second array to merge.
1197          */
1198         merge: function(a,b) {
1199                 var d = [];
1200                 
1201                 // Move b over to the new array (this helps to avoid
1202                 // StaticNodeList instances)
1203                 for ( var k = 0; k < b.length; k++ )
1204                         d[k] = b[k];
1205         
1206                 // Now check for duplicates between a and b and only
1207                 // add the unique items
1208                 for ( var i = 0; i < a.length; i++ ) {
1209                         var c = true;
1210                         
1211                         // The collision-checking process
1212                         for ( var j = 0; j < b.length; j++ )
1213                                 if ( a[i] == b[j] )
1214                                         c = false;
1215                                 
1216                         // If the item is unique, add it
1217                         if ( c )
1218                                 d.push( a[i] );
1219                 }
1220         
1221                 return d;
1222         },
1223         
1224         /**
1225          * Remove items that aren't matched in an array. The function passed
1226          * in to this method will be passed two arguments: 'a' (which is the
1227          * array item) and 'i' (which is the index of the item in the array).
1228          *
1229          * @private
1230          * @name $.grep
1231          * @type Array
1232          * @param Array array The Array to find items in.
1233          * @param Function fn The function to process each item against.
1234          * @param Boolean inv Invert the selection - select the opposite of the function.
1235          */
1236         grep: function(a,f,s) {
1237                 // If a string is passed in for the function, make a function
1238                 // for it (a handy shortcut)
1239                 if ( f.constructor == String )
1240                         f = new Function("a","i","return " + f);
1241                         
1242                 var r = [];
1243                 
1244                 // Go through the array, only saving the items
1245                 // that pass the validator function
1246                 for ( var i = 0; i < a.length; i++ )
1247                         if ( !s && f(a[i],i) || s && !f(a[i],i) )
1248                                 r.push( a[i] );
1249                 
1250                 return r;
1251         },
1252         
1253         /**
1254          * Translate all items in array to another array of items. The translation function
1255          * that is provided to this method is passed one argument: 'a' (the item to be 
1256          * translated). If an array is returned, that array is mapped out and merged into
1257          * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1258          * from the array. Both of these changes imply that the size of the array may not
1259          * be the same size upon completion, as it was when it started.
1260          *
1261          * @private
1262          * @name $.map
1263          * @type Array
1264          * @param Array array The Array to translate.
1265          * @param Function fn The function to process each item against.
1266          */
1267         map: function(a,f) {
1268                 // If a string is passed in for the function, make a function
1269                 // for it (a handy shortcut)
1270                 if ( f.constructor == String )
1271                         f = new Function("a","return " + f);
1272                 
1273                 var r = [];
1274                 
1275                 // Go through the array, translating each of the items to their
1276                 // new value (or values).
1277                 for ( var i = 0; i < a.length; i++ ) {
1278                         var t = f(a[i],i);
1279                         if ( t !== null && t != undefined ) {
1280                                 if ( t.constructor != Array ) t = [t];
1281                                 r = jQuery.merge( t, r );
1282                         }
1283                 }
1284                 return r;
1285         },
1286         
1287         /*
1288          * A number of helper functions used for managing events.
1289          * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1290          */
1291         event: {
1292         
1293                 // Bind an event to an element
1294                 // Original by Dean Edwards
1295                 add: function(element, type, handler) {
1296                         // For whatever reason, IE has trouble passing the window object
1297                         // around, causing it to be cloned in the process
1298                         if ( jQuery.browser.msie && element.setInterval != undefined )
1299                                 element = window;
1300                 
1301                         // Make sure that the function being executed has a unique ID
1302                         if ( !handler.guid )
1303                                 handler.guid = this.guid++;
1304                                 
1305                         // Init the element's event structure
1306                         if (!element.events)
1307                                 element.events = {};
1308                         
1309                         // Get the current list of functions bound to this event
1310                         var handlers = element.events[type];
1311                         
1312                         // If it hasn't been initialized yet
1313                         if (!handlers) {
1314                                 // Init the event handler queue
1315                                 handlers = element.events[type] = {};
1316                                 
1317                                 // Remember an existing handler, if it's already there
1318                                 if (element["on" + type])
1319                                         handlers[0] = element["on" + type];
1320                         }
1321
1322                         // Add the function to the element's handler list
1323                         handlers[handler.guid] = handler;
1324                         
1325                         // And bind the global event handler to the element
1326                         element["on" + type] = this.handle;
1327         
1328                         // Remember the function in a global list (for triggering)
1329                         if (!this.global[type])
1330                                 this.global[type] = [];
1331                         this.global[type].push( element );
1332                 },
1333                 
1334                 guid: 1,
1335                 global: {},
1336                 
1337                 // Detach an event or set of events from an element
1338                 remove: function(element, type, handler) {
1339                         if (element.events)
1340                                 if (type && element.events[type])
1341                                         if ( handler )
1342                                                 delete element.events[type][handler.guid];
1343                                         else
1344                                                 for ( var i in element.events[type] )
1345                                                         delete element.events[type][i];
1346                                 else
1347                                         for ( var j in element.events )
1348                                                 this.remove( element, j );
1349                 },
1350                 
1351                 trigger: function(type,data,element) {
1352                         // Touch up the incoming data
1353                         data = data || [];
1354         
1355                         // Handle a global trigger
1356                         if ( !element ) {
1357                                 var g = this.global[type];
1358                                 if ( g )
1359                                         for ( var i = 0; i < g.length; i++ )
1360                                                 this.trigger( type, data, g[i] );
1361         
1362                         // Handle triggering a single element
1363                         } else if ( element["on" + type] ) {
1364                                 // Pass along a fake event
1365                                 data.unshift( this.fix({ type: type, target: element }) );
1366         
1367                                 // Trigger the event
1368                                 element["on" + type].apply( element, data );
1369                         }
1370                 },
1371                 
1372                 handle: function(event) {
1373                         if ( typeof jQuery == "undefined" ) return;
1374
1375                         event = event || jQuery.event.fix( window.event );
1376         
1377                         // If no correct event was found, fail
1378                         if ( !event ) return;
1379                 
1380                         var returnValue = true;
1381
1382                         var c = this.events[event.type];
1383                 
1384                         for ( var j in c ) {
1385                                 if ( c[j].apply( this, [event] ) === false ) {
1386                                         event.preventDefault();
1387                                         event.stopPropagation();
1388                                         returnValue = false;
1389                                 }
1390                         }
1391                         
1392                         return returnValue;
1393                 },
1394                 
1395                 fix: function(event) {
1396                         if ( event ) {
1397                                 event.preventDefault = function() {
1398                                         this.returnValue = false;
1399                                 };
1400                         
1401                                 event.stopPropagation = function() {
1402                                         this.cancelBubble = true;
1403                                 };
1404                         }
1405                         
1406                         return event;
1407                 }
1408         
1409         }
1410 });
1411
1412 new function() {
1413         var b = navigator.userAgent.toLowerCase();
1414
1415         // Figure out what browser is being used
1416         jQuery.browser = {
1417                 safari: /webkit/.test(b),
1418                 opera: /opera/.test(b),
1419                 msie: /msie/.test(b) && !/opera/.test(b),
1420                 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1421         };
1422
1423         // Check to see if the W3C box model is being used
1424         jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1425 };
1426
1427 jQuery.macros = {
1428         to: ["append","prepend","before","after"],
1429         css: "width,height,top,left,position,float,overflow,color,background".split(","),
1430         attr: {
1431                 val: "value",
1432                 html: "innerHTML",
1433                 value: null,
1434                 id: null,
1435                 title: null,
1436                 name: null,
1437                 href: null,
1438                 src: null,
1439                 rel: null
1440         },
1441         axis: {
1442                 /**
1443                  * Get a set of elements containing the unique parents of the matched
1444                  * set of elements.
1445                  *
1446                  * @example $("p").parent()
1447                  * @before <div><p>Hello</p><p>Hello</p></div>
1448                  * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1449                  *
1450                  * @name parent
1451                  * @type jQuery
1452                  */
1453
1454                 /**
1455                  * Get a set of elements containing the unique parents of the matched
1456                  * set of elements, and filtered by an expression.
1457                  *
1458                  * @example $("p").parent(".selected")
1459                  * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1460                  * @result [ <div class="selected"><p>Hello Again</p></div> ]
1461                  *
1462                  * @name parent
1463                  * @type jQuery
1464                  * @param String expr An expression to filter the parents with
1465                  */
1466                 parent: "a.parentNode",
1467
1468                 /**
1469                  * Get a set of elements containing the unique ancestors of the matched
1470                  * set of elements.
1471                  *
1472                  * @example $("span").ancestors()
1473                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1474                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ] 
1475                  *
1476                  * @name ancestors
1477                  * @type jQuery
1478                  */
1479
1480                 /**
1481                  * Get a set of elements containing the unique ancestors of the matched
1482                  * set of elements, and filtered by an expression.
1483                  *
1484                  * @example $("span").ancestors("p")
1485                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1486                  * @result [ <p><span>Hello</span></p> ] 
1487                  *
1488                  * @name ancestors
1489                  * @type jQuery
1490                  * @param String expr An expression to filter the ancestors with
1491                  */
1492                 ancestors: jQuery.parents,
1493                 
1494                 /**
1495                  * A synonym for ancestors
1496                  */
1497                 parents: jQuery.parents,
1498
1499                 /**
1500                  * Get a set of elements containing the unique next siblings of each of the 
1501                  * matched set of elements.
1502                  * 
1503                  * It only returns the very next sibling, not all next siblings.
1504                  *
1505                  * @example $("p").next()
1506                  * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1507                  * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1508                  *
1509                  * @name next
1510                  * @type jQuery
1511                  */
1512
1513                 /**
1514                  * Get a set of elements containing the unique next siblings of each of the 
1515                  * matched set of elements, and filtered by an expression.
1516                  * 
1517                  * It only returns the very next sibling, not all next siblings.
1518                  *
1519                  * @example $("p").next(".selected")
1520                  * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1521                  * @result [ <p class="selected">Hello Again</p> ]
1522                  *
1523                  * @name next
1524                  * @type jQuery
1525                  * @param String expr An expression to filter the next Elements with
1526                  */
1527                 next: "jQuery.sibling(a).next",
1528
1529                 /**
1530                  * Get a set of elements containing the unique previous siblings of each of the 
1531                  * matched set of elements.
1532                  * 
1533                  * It only returns the immediately previous sibling, not all previous siblings.
1534                  *
1535                  * @example $("p").previous()
1536                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1537                  * @result [ <div><span>Hello Again</span></div> ]
1538                  *
1539                  * @name prev
1540                  * @type jQuery
1541                  */
1542
1543                 /**
1544                  * Get a set of elements containing the unique previous siblings of each of the 
1545                  * matched set of elements, and filtered by an expression.
1546                  * 
1547                  * It only returns the immediately previous sibling, not all previous siblings.
1548                  *
1549                  * @example $("p").previous("selected")
1550                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1551                  * @result [ <div><span>Hello</span></div> ]
1552                  *
1553                  * @name prev
1554                  * @type jQuery
1555                  * @param String expr An expression to filter the previous Elements with
1556                  */
1557                 prev: "jQuery.sibling(a).prev",
1558
1559                 /**
1560                  * Get a set of elements containing all of the unique siblings of each of the 
1561                  * matched set of elements.
1562                  * 
1563                  * @example $("div").siblings()
1564                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1565                  * @result [ <p>Hello</p>, <p>And Again</p> ]
1566                  *
1567                  * @name siblings
1568                  * @type jQuery
1569                  */
1570
1571                 /**
1572                  * Get a set of elements containing all of the unique siblings of each of the 
1573                  * matched set of elements, and filtered by an expression.
1574                  *
1575                  * @example $("div").siblings("selected")
1576                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1577                  * @result [ <p class="selected">Hello Again</p> ]
1578                  *
1579                  * @name siblings
1580                  * @type jQuery
1581                  * @param String expr An expression to filter the sibling Elements with
1582                  */
1583                 siblings: jQuery.sibling
1584         },
1585
1586         each: {
1587                 /**
1588                  * Displays each of the set of matched elements if they are hidden.
1589                  * 
1590                  * @example $("p").show()
1591                  * @before <p style="display: none">Hello</p>
1592                  * @result [ <p style="display: block">Hello</p> ]
1593                  *
1594                  * @name show
1595                  * @type jQuery
1596                  */
1597                 show: function(){
1598                         this.style.display = this.oldblock ? this.oldblock : "";
1599                         if ( jQuery.css(this,"display") == "none" )
1600                                 this.style.display = "block";
1601                 },
1602
1603                 /**
1604                  * Hides each of the set of matched elements if they are shown.
1605                  *
1606                  * @example $("p").hide()
1607                  * @before <p>Hello</p>
1608                  * @result [ <p style="display: none">Hello</p> ]
1609                  *
1610                  * @name hide
1611                  * @type jQuery
1612                  */
1613                 hide: function(){
1614                         this.oldblock = jQuery.css(this,"display");
1615                         if ( this.oldblock == "none" )
1616                                 this.oldblock = "block";
1617                         this.style.display = "none";
1618                 },
1619                 
1620                 /**
1621                  * Toggles each of the set of matched elements. If they are shown,
1622                  * toggle makes them hidden. If they are hidden, toggle
1623                  * makes them shown.
1624                  *
1625                  * @example $("p").toggle()
1626                  * @before <p>Hello</p><p style="display: none">Hello Again</p>
1627                  * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
1628                  *
1629                  * @name toggle
1630                  * @type jQuery
1631                  */
1632                 toggle: function(){
1633                         var d = jQuery.css(this,"display");
1634                         $(this)[ !d || d == "none" ? "show" : "hide" ]();
1635                 },
1636                 
1637                 /**
1638                  * Adds the specified class to each of the set of matched elements.
1639                  *
1640                  * @example ("p").addClass("selected")
1641                  * @before <p>Hello</p>
1642                  * @result [ <p class="selected">Hello</p> ]
1643                  * 
1644                  * @name addClass
1645                  * @type jQuery
1646                  * @param String class A CSS class to add to the elements
1647                  */
1648                 addClass: function(c){
1649                         jQuery.className.add(this,c);
1650                 },
1651                 
1652                 /**
1653                  * The opposite of addClass. Removes the specified class from the
1654                  * set of matched elements.
1655                  *
1656                  * @example ("p").removeClass("selected")
1657                  * @before <p class="selected">Hello</p>
1658                  * @result [ <p>Hello</p> ]
1659                  *
1660                  * @name removeClass
1661                  * @type jQuery
1662                  * @param String class A CSS class to remove from the elements
1663                  */
1664                 removeClass: function(c){
1665                         jQuery.className.remove(this,c);
1666                 },
1667         
1668                 /**
1669                  * Adds the specified class if it is present. Remove it if it is
1670                  * not present.
1671                  *
1672                  * @example ("p").toggleClass("selected")
1673                  * @before <p>Hello</p><p class="selected">Hello Again</p>
1674                  * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
1675                  *
1676                  * @name toggleClass
1677                  * @type jQuery
1678                  * @param String class A CSS class with which to toggle the elements
1679                  */
1680                 toggleClass: function( c ){
1681                         jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
1682                 },
1683                 
1684                 /**
1685                  * TODO: Document
1686                  */
1687                 remove: function(a){
1688                         if ( !a || jQuery.filter( [this], a ).r )
1689                                 this.parentNode.removeChild( this );
1690                 },
1691         
1692                 /**
1693                  * Removes all child nodes from the set of matched elements.
1694                  *
1695                  * @example ("p").empty()
1696                  * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
1697                  * @result [ <p></p> ]
1698                  *
1699                  * @name empty
1700                  * @type jQuery
1701                  */
1702                 empty: function(){
1703                         while ( this.firstChild )
1704                                 this.removeChild( this.firstChild );
1705                 },
1706                 
1707                 /**
1708                  * Binds a particular event (like click) to a each of a set of match elements.
1709                  *
1710                  * @example $("p").bind( "click", function() { alert("Hello"); } )
1711                  * @before <p>Hello</p>
1712                  * @result [ <p>Hello</p> ]
1713                  *
1714                  * Cancel a default action and prevent it from bubbling by returning false
1715                  * from your function.
1716                  *
1717                  * @example $("form").bind( "submit", function() { return false; } )
1718                  *
1719                  * Cancel a default action by using the preventDefault method.
1720                  *
1721                  * @example $("form").bind( "submit", function() { e.preventDefault(); } )
1722                  *
1723                  * Stop an event from bubbling by using the stopPropogation method.
1724                  *
1725                  * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
1726                  *
1727                  * @name bind
1728                  * @type jQuery
1729                  * @param String type An event type
1730                  * @param Function fn A function to bind to the event on each of the set of matched elements
1731                  */
1732                 bind: function( type, fn ) {
1733                         if ( fn.constructor == String )
1734                                 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
1735                         jQuery.event.add( this, type, fn );
1736                 },
1737                 
1738                 /**
1739                  * The opposite of bind. Removes a bound event from each of a set of matched
1740                  * elements. You must pass the identical function that was used in the original 
1741                  * bind method.
1742                  *
1743                  * @example $("p").unbind( "click", function() { alert("Hello"); } )
1744                  * @before <p>Hello</p>
1745                  * @result [ <p>Hello</p> ]
1746                  *
1747                  * @name unbind
1748                  * @type jQuery
1749                  * @param String type An event type
1750                  * @param Function fn A function to unbind from the event on each of the set of matched elements
1751                  */
1752                 unbind: function( type, fn ) {
1753                         jQuery.event.remove( this, type, fn );
1754                 },
1755                 
1756                 /**
1757                  * Trigger a particular event.
1758                  *
1759                  * @example $("p").trigger("click")
1760                  * @before <p>Hello</p>
1761                  * @result [ <p>Hello</p> ]
1762                  *
1763                  * @name trigger
1764                  * @type jQuery
1765                  * @param String type An event type
1766                  */
1767                 trigger: function( type, data ) {
1768                         jQuery.event.trigger( type, data, this );
1769                 }
1770         }
1771 };