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