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