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