Added in #690, the ability to remove an event handler from inside itself.
[jquery.git] / src / jquery / jquery.js
1 /*
2  * jQuery @VERSION - New Wave Javascript
3  *
4  * Copyright (c) 2006 John Resig (jquery.com)
5  * Dual licensed under the MIT (MIT-LICENSE.txt)
6  * and GPL (GPL-LICENSE.txt) licenses.
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  *
18  * @constructor
19  * @private
20  * @name jQuery
21  * @cat Core
22  */
23 var jQuery = function(a,c) {
24
25         // Shortcut for document ready
26         if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function
27                 return jQuery(document).ready(a);
28
29         // Make sure that a selection was provided
30         a = a || document;
31
32         // Watch for when a jQuery object is passed as the selector
33         if ( a.jquery )
34                 return jQuery( jQuery.makeArray( a ) );
35
36         // Watch for when a jQuery object is passed at the context
37         if ( c && c.jquery )
38                 return jQuery( c ).find(a);
39
40         // If the context is global, return a new object
41         if ( window == this )
42                 return new jQuery(a,c);
43
44         // Handle HTML strings
45         if ( typeof a  == "string" ) {
46                 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
47                 if ( m ) a = jQuery.clean( [ m[1] ] );
48         }
49
50         // Watch for when an array is passed in
51         this.set( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
52                 // Assume that it is an array of DOM Elements
53                 jQuery.makeArray( a ) :
54
55                 // Find the matching elements and save them for later
56                 jQuery.find( a, c ) );
57
58         // See if an extra function was provided
59         var fn = arguments[ arguments.length - 1 ];
60
61         // If so, execute it in context
62         if ( fn && typeof fn == "function" )
63                 this.each(fn);
64
65         return this;
66 };
67
68 // Map over the $ in case of overwrite
69 if ( typeof $ != "undefined" )
70         jQuery._$ = $;
71         
72 // Map the jQuery namespace to the '$' one
73 var $ = jQuery;
74
75 /**
76  * This function accepts a string containing a CSS or
77  * basic XPath selector which is then used to match a set of elements.
78  *
79  * The core functionality of jQuery centers around this function.
80  * Everything in jQuery is based upon this, or uses this in some way.
81  * The most basic use of this function is to pass in an expression
82  * (usually consisting of CSS or XPath), which then finds all matching
83  * elements.
84  *
85  * By default, $() looks for DOM elements within the context of the
86  * current HTML document.
87  *
88  * @example $("div > p")
89  * @desc This finds all p elements that are children of a div element.
90  * @before <p>one</p> <div><p>two</p></div> <p>three</p>
91  * @result [ <p>two</p> ]
92  *
93  * @example $("input:radio", document.forms[0])
94  * @desc Searches for all inputs of type radio within the first form in the document
95  *
96  * @example $("div", xml.responseXML)
97  * @desc This finds all div elements within the specified XML document.
98  *
99  * @name $
100  * @param String expr An expression to search with
101  * @param Element context (optional) A DOM Element, or Document, representing the base context.
102  * @cat Core
103  * @type jQuery
104  * @see $(Element)
105  * @see $(Element<Array>)
106  */
107  
108 /**
109  * This function accepts a string of raw HTML.
110  *
111  * The HTML string is different from the traditional selectors in that
112  * it creates the DOM elements representing that HTML string, on the fly,
113  * to be (assumedly) inserted into the document later.
114  *
115  * @example $("<div><p>Hello</p></div>").appendTo("#body")
116  * @desc Creates a div element (and all of its contents) dynamically, 
117  * and appends it to the element with the ID of body. Internally, an
118  * element is created and it's innerHTML property set to the given markup.
119  * It is therefore both quite flexible and limited. 
120  *
121  * @name $
122  * @param String html A string of HTML to create on the fly.
123  * @cat Core
124  * @type jQuery
125  */
126
127 /**
128  * Wrap jQuery functionality around a specific DOM Element.
129  * This function also accepts XML Documents and Window objects
130  * as valid arguments (even though they are not DOM Elements).
131  *
132  * @example $(document).find("div > p")
133  * @before <p>one</p> <div><p>two</p></div> <p>three</p>
134  * @result [ <p>two</p> ]
135  *
136  * @example $(document.body).background( "black" );
137  * @desc Sets the background color of the page to black.
138  *
139  * @name $
140  * @param Element elem A DOM element to be encapsulated by a jQuery object.
141  * @cat Core
142  * @type jQuery
143  */
144
145 /**
146  * Wrap jQuery functionality around a set of DOM Elements.
147  *
148  * @example $( myForm.elements ).hide()
149  * @desc Hides all the input elements within a form
150  *
151  * @name $
152  * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
153  * @cat Core
154  * @type jQuery
155  */
156
157 /**
158  * A shorthand for $(document).ready(), allowing you to bind a function
159  * to be executed when the DOM document has finished loading. This function
160  * behaves just like $(document).ready(), in that it should be used to wrap
161  * all of the other $() operations on your page. While this function is,
162  * technically, chainable - there really isn't much use for chaining against it.
163  * You can have as many $(document).ready events on your page as you like.
164  *
165  * See ready(Function) for details about the ready event. 
166  * 
167  * @example $(function(){
168  *   // Document is ready
169  * });
170  * @desc Executes the function when the DOM is ready to be used.
171  *
172  * @name $
173  * @param Function fn The function to execute when the DOM is ready.
174  * @cat Core
175  * @type jQuery
176  */
177
178 /**
179  * A means of creating a cloned copy of a jQuery object. This function
180  * copies the set of matched elements from one jQuery object and creates
181  * another, new, jQuery object containing the same elements.
182  *
183  * @example var div = $("div");
184  * $( div ).find("p");
185  * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done).
186  *
187  * @name $
188  * @param jQuery obj The jQuery object to be cloned.
189  * @cat Core
190  * @type jQuery
191  */
192
193 jQuery.fn = jQuery.prototype = {
194         /**
195          * The current version of jQuery.
196          *
197          * @private
198          * @property
199          * @name jquery
200          * @type String
201          * @cat Core
202          */
203         jquery: "@VERSION",
204
205         /**
206          * The number of elements currently matched.
207          *
208          * @example $("img").length;
209          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
210          * @result 2
211          *
212          * @property
213          * @name length
214          * @type Number
215          * @cat Core
216          */
217
218         /**
219          * The number of elements currently matched.
220          *
221          * @example $("img").size();
222          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
223          * @result 2
224          *
225          * @name size
226          * @type Number
227          * @cat Core
228          */
229         size: function() {
230                 return this.length;
231         },
232
233         /**
234          * Access all matched elements. This serves as a backwards-compatible
235          * way of accessing all matched elements (other than the jQuery object
236          * itself, which is, in fact, an array of elements).
237          *
238          * @example $("img").get();
239          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
240          * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
241          *
242          * @name get
243          * @type Array<Element>
244          * @cat Core
245          */
246
247         /**
248          * Access a single matched element. num is used to access the
249          * Nth element matched.
250          *
251          * @example $("img").get(1);
252          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
253          * @result [ <img src="test1.jpg"/> ]
254          *
255          * @name get
256          * @type Element
257          * @param Number num Access the element in the Nth position.
258          * @cat Core
259          */
260         get: function( num ) {
261                 return num == undefined ?
262
263                         // Return a 'clean' array
264                         jQuery.makeArray( this ) :
265
266                         // Return just the object
267                         this[num];
268         },
269         
270         /**
271          * Set the jQuery object to an array of elements.
272          *
273          * @example $("img").set([ document.body ]);
274          * @result $("img").set() == [ document.body ]
275          *
276          * @private
277          * @name set
278          * @type jQuery
279          * @param Elements elems An array of elements
280          * @cat Core
281          */
282         set: function( array ) {
283                 // Use a tricky hack to make the jQuery object
284                 // look and feel like an array
285                 this.length = 0;
286                 [].push.apply( this, array );
287                 return this;
288         },
289
290         /**
291          * Execute a function within the context of every matched element.
292          * This means that every time the passed-in function is executed
293          * (which is once for every element matched) the 'this' keyword
294          * points to the specific element.
295          *
296          * Additionally, the function, when executed, is passed a single
297          * argument representing the position of the element in the matched
298          * set.
299          *
300          * @example $("img").each(function(i){
301          *   this.src = "test" + i + ".jpg";
302          * });
303          * @before <img/> <img/>
304          * @result <img src="test0.jpg"/> <img src="test1.jpg"/>
305          * @desc Iterates over two images and sets their src property
306          *
307          * @name each
308          * @type jQuery
309          * @param Function fn A function to execute
310          * @cat Core
311          */
312         each: function( fn, args ) {
313                 return jQuery.each( this, fn, args );
314         },
315
316         /**
317          * Searches every matched element for the object and returns
318          * the index of the element, if found, starting with zero. 
319          * Returns -1 if the object wasn't found.
320          *
321          * @example $("*").index(document.getElementById('foobar')) 
322          * @before <div id="foobar"></div><b></b><span id="foo"></span>
323          * @result 0
324          *
325          * @example $("*").index(document.getElementById('foo')) 
326          * @before <div id="foobar"></div><b></b><span id="foo"></span>
327          * @result 2
328          *
329          * @example $("*").index(document.getElementById('bar')) 
330          * @before <div id="foobar"></div><b></b><span id="foo"></span>
331          * @result -1
332          *
333          * @name index
334          * @type Number
335          * @param Object obj Object to search for
336          * @cat Core
337          */
338         index: function( obj ) {
339                 var pos = -1;
340                 this.each(function(i){
341                         if ( this == obj ) pos = i;
342                 });
343                 return pos;
344         },
345
346         /**
347          * Access a property on the first matched element.
348          * This method makes it easy to retrieve a property value
349          * from the first matched element.
350          *
351          * @example $("img").attr("src");
352          * @before <img src="test.jpg"/>
353          * @result test.jpg
354          *
355          * @name attr
356          * @type Object
357          * @param String name The name of the property to access.
358          * @cat DOM
359          */
360
361         /**
362          * Set a hash of key/value object properties to all matched elements.
363          * This serves as the best way to set a large number of properties
364          * on all matched elements.
365          *
366          * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
367          * @before <img/>
368          * @result <img src="test.jpg" alt="Test Image"/>
369          *
370          * @name attr
371          * @type jQuery
372          * @param Hash prop A set of key/value pairs to set as object properties.
373          * @cat DOM
374          */
375
376         /**
377          * Set a single property to a value, on all matched elements.
378          *
379          * Note that you can't set the name property of input elements in IE.
380          * Use $(html) or $().append(html) or $().html(html) to create elements
381          * on the fly including the name property.
382          *
383          * @example $("img").attr("src","test.jpg");
384          * @before <img/>
385          * @result <img src="test.jpg"/>
386          *
387          * @name attr
388          * @type jQuery
389          * @param String key The name of the property to set.
390          * @param Object value The value to set the property to.
391          * @cat DOM
392          */
393         attr: function( key, value, type ) {
394                 // Check to see if we're setting style values
395                 return typeof key != "string" || value != undefined ?
396                         this.each(function(){
397                                 // See if we're setting a hash of styles
398                                 if ( value == undefined )
399                                         // Set all the styles
400                                         for ( var prop in key )
401                                                 jQuery.attr(
402                                                         type ? this.style : this,
403                                                         prop, key[prop]
404                                                 );
405
406                                 // See if we're setting a single key/value style
407                                 else
408                                         jQuery.attr(
409                                                 type ? this.style : this,
410                                                 key, value
411                                         );
412                         }) :
413
414                         // Look for the case where we're accessing a style value
415                         jQuery[ type || "attr" ]( this[0], key );
416         },
417
418         /**
419          * Access a style property on the first matched element.
420          * This method makes it easy to retrieve a style property value
421          * from the first matched element.
422          *
423          * @example $("p").css("color");
424          * @before <p style="color:red;">Test Paragraph.</p>
425          * @result red
426          * @desc Retrieves the color style of the first paragraph
427          *
428          * @example $("p").css("fontWeight");
429          * @before <p style="font-weight: bold;">Test Paragraph.</p>
430          * @result bold
431          * @desc Retrieves the font-weight style of the first paragraph.
432          * Note that for all style properties with a dash (like 'font-weight'), you have to
433          * write it in camelCase. In other words: Every time you have a '-' in a 
434          * property, remove it and replace the next character with an uppercase 
435          * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
436          * borderStyle, borderBottomWidth etc.
437          *
438          * @name css
439          * @type Object
440          * @param String name The name of the property to access.
441          * @cat CSS
442          */
443
444         /**
445          * Set a hash of key/value style properties to all matched elements.
446          * This serves as the best way to set a large number of style properties
447          * on all matched elements.
448          *
449          * @example $("p").css({ color: "red", background: "blue" });
450          * @before <p>Test Paragraph.</p>
451          * @result <p style="color:red; background:blue;">Test Paragraph.</p>
452          *
453          * @name css
454          * @type jQuery
455          * @param Hash prop A set of key/value pairs to set as style properties.
456          * @cat CSS
457          */
458
459         /**
460          * Set a single style property to a value, on all matched elements.
461          *
462          * @example $("p").css("color","red");
463          * @before <p>Test Paragraph.</p>
464          * @result <p style="color:red;">Test Paragraph.</p>
465          * @desc Changes the color of all paragraphs to red
466          *
467          * @name css
468          * @type jQuery
469          * @param String key The name of the property to set.
470          * @param Object value The value to set the property to.
471          * @cat CSS
472          */
473         css: function( key, value ) {
474                 return this.attr( key, value, "curCSS" );
475         },
476
477         /**
478          * Retrieve the text contents of all matched elements. The result is
479          * a string that contains the combined text contents of all matched
480          * elements. This method works on both HTML and XML documents.
481          *
482          * @example $("p").text();
483          * @before <p>Test Paragraph.</p>
484          * @result Test Paragraph.
485          *
486          * @name text
487          * @type String
488          * @cat DOM
489          */
490
491         /**
492          * Set the text contents of all matched elements. This has the same
493          * effect as calling .html() with your specified string.
494          *
495          * @example $("p").text("Some new text.");
496          * @before <p>Test Paragraph.</p>
497          * @result <p>Some new text.</p>
498          *
499          * @param String val The text value to set the contents of the element to.
500          *
501          * @name text
502          * @type String
503          * @cat DOM
504          */
505         text: function(e) {
506                 // A surprisingly high number of people expect the
507                 // .text() method to do this, so lets do it!
508                 if ( typeof e == "string" )
509                         return this.html( e );
510
511                 e = e || this;
512                 var t = "";
513                 for ( var j = 0; j < e.length; j++ ) {
514                         var r = e[j].childNodes;
515                         for ( var i = 0; i < r.length; i++ )
516                                 if ( r[i].nodeType != 8 )
517                                         t += r[i].nodeType != 1 ?
518                                                 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
519                 }
520                 return t;
521         },
522
523         /**
524          * Wrap all matched elements with a structure of other elements.
525          * This wrapping process is most useful for injecting additional
526          * stucture into a document, without ruining the original semantic
527          * qualities of a document.
528          *
529          * This works by going through the first element
530          * provided (which is generated, on the fly, from the provided HTML)
531          * and finds the deepest ancestor element within its
532          * structure - it is that element that will en-wrap everything else.
533          *
534          * This does not work with elements that contain text. Any necessary text
535          * must be added after the wrapping is done.
536          *
537          * @example $("p").wrap("<div class='wrap'></div>");
538          * @before <p>Test Paragraph.</p>
539          * @result <div class='wrap'><p>Test Paragraph.</p></div>
540          * 
541          * @name wrap
542          * @type jQuery
543          * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
544          * @cat DOM/Manipulation
545          */
546
547         /**
548          * Wrap all matched elements with a structure of other elements.
549          * This wrapping process is most useful for injecting additional
550          * stucture into a document, without ruining the original semantic
551          * qualities of a document.
552          *
553          * This works by going through the first element
554          * provided and finding the deepest ancestor element within its
555          * structure - it is that element that will en-wrap everything else.
556          *
557          * This does not work with elements that contain text. Any necessary text
558          * must be added after the wrapping is done.
559          *
560          * @example $("p").wrap( document.getElementById('content') );
561          * @before <p>Test Paragraph.</p><div id="content"></div>
562          * @result <div id="content"><p>Test Paragraph.</p></div>
563          *
564          * @name wrap
565          * @type jQuery
566          * @param Element elem A DOM element that will be wrapped.
567          * @cat DOM/Manipulation
568          */
569         wrap: function() {
570                 // The elements to wrap the target around
571                 var a = jQuery.clean(arguments);
572
573                 // Wrap each of the matched elements individually
574                 return this.each(function(){
575                         // Clone the structure that we're using to wrap
576                         var b = a[0].cloneNode(true);
577
578                         // Insert it before the element to be wrapped
579                         this.parentNode.insertBefore( b, this );
580
581                         // Find the deepest point in the wrap structure
582                         while ( b.firstChild )
583                                 b = b.firstChild;
584
585                         // Move the matched element to within the wrap structure
586                         b.appendChild( this );
587                 });
588         },
589
590         /**
591          * Append any number of elements to the inside of every matched elements,
592          * generated from the provided HTML.
593          * This operation is similar to doing an appendChild to all the
594          * specified elements, adding them into the document.
595          *
596          * @example $("p").append("<b>Hello</b>");
597          * @before <p>I would like to say: </p>
598          * @result <p>I would like to say: <b>Hello</b></p>
599          *
600          * @name append
601          * @type jQuery
602          * @param String html A string of HTML, that will be created on the fly and appended to the target.
603          * @cat DOM/Manipulation
604          */
605
606         /**
607          * Append an element to the inside of all matched elements.
608          * This operation is similar to doing an appendChild to all the
609          * specified elements, adding them into the document.
610          *
611          * @example $("p").append( $("#foo")[0] );
612          * @before <p>I would like to say: </p><b id="foo">Hello</b>
613          * @result <p>I would like to say: <b id="foo">Hello</b></p>
614          *
615          * @name append
616          * @type jQuery
617          * @param Element elem A DOM element that will be appended.
618          * @cat DOM/Manipulation
619          */
620
621         /**
622          * Append any number of elements to the inside of all matched elements.
623          * This operation is similar to doing an appendChild to all the
624          * specified elements, adding them into the document.
625          *
626          * @example $("p").append( $("b") );
627          * @before <p>I would like to say: </p><b>Hello</b>
628          * @result <p>I would like to say: <b>Hello</b></p>
629          *
630          * @name append
631          * @type jQuery
632          * @param Array<Element> elems An array of elements, all of which will be appended.
633          * @cat DOM/Manipulation
634          */
635         append: function() {
636                 return this.domManip(arguments, true, 1, function(a){
637                         this.appendChild( a );
638                 });
639         },
640
641         /**
642          * Prepend any number of elements to the inside of every matched elements,
643          * generated from the provided HTML.
644          * This operation is the best way to insert dynamically created elements
645          * inside, at the beginning, of all the matched element.
646          *
647          * @example $("p").prepend("<b>Hello</b>");
648          * @before <p>I would like to say: </p>
649          * @result <p><b>Hello</b>I would like to say: </p>
650          *
651          * @name prepend
652          * @type jQuery
653          * @param String html A string of HTML, that will be created on the fly and appended to the target.
654          * @cat DOM/Manipulation
655          */
656
657         /**
658          * Prepend an element to the inside of all matched elements.
659          * This operation is the best way to insert an element inside, at the
660          * beginning, of all the matched element.
661          *
662          * @example $("p").prepend( $("#foo")[0] );
663          * @before <p>I would like to say: </p><b id="foo">Hello</b>
664          * @result <p><b id="foo">Hello</b>I would like to say: </p>
665          *       
666          * @name prepend
667          * @type jQuery
668          * @param Element elem A DOM element that will be appended.
669          * @cat DOM/Manipulation
670          */
671
672         /**
673          * Prepend any number of elements to the inside of all matched elements.
674          * This operation is the best way to insert a set of elements inside, at the
675          * beginning, of all the matched element.
676          *
677          * @example $("p").prepend( $("b") );
678          * @before <p>I would like to say: </p><b>Hello</b>
679          * @result <p><b>Hello</b>I would like to say: </p>
680          *
681          * @name prepend
682          * @type jQuery
683          * @param Array<Element> elems An array of elements, all of which will be appended.
684          * @cat DOM/Manipulation
685          */
686         prepend: function() {
687                 return this.domManip(arguments, true, -1, function(a){
688                         this.insertBefore( a, this.firstChild );
689                 });
690         },
691
692         /**
693          * Insert any number of dynamically generated elements before each of the
694          * matched elements.
695          *
696          * @example $("p").before("<b>Hello</b>");
697          * @before <p>I would like to say: </p>
698          * @result <b>Hello</b><p>I would like to say: </p>
699          *
700          * @name before
701          * @type jQuery
702          * @param String html A string of HTML, that will be created on the fly and appended to the target.
703          * @cat DOM/Manipulation
704          */
705
706         /**
707          * Insert an element before each of the matched elements.
708          *
709          * @example $("p").before( $("#foo")[0] );
710          * @before <p>I would like to say: </p><b id="foo">Hello</b>
711          * @result <b id="foo">Hello</b><p>I would like to say: </p>
712          *
713          * @name before
714          * @type jQuery
715          * @param Element elem A DOM element that will be appended.
716          * @cat DOM/Manipulation
717          */
718
719         /**
720          * Insert any number of elements before each of the matched elements.
721          *
722          * @example $("p").before( $("b") );
723          * @before <p>I would like to say: </p><b>Hello</b>
724          * @result <b>Hello</b><p>I would like to say: </p>
725          *
726          * @name before
727          * @type jQuery
728          * @param Array<Element> elems An array of elements, all of which will be appended.
729          * @cat DOM/Manipulation
730          */
731         before: function() {
732                 return this.domManip(arguments, false, 1, function(a){
733                         this.parentNode.insertBefore( a, this );
734                 });
735         },
736
737         /**
738          * Insert any number of dynamically generated elements after each of the
739          * matched elements.
740          *
741          * @example $("p").after("<b>Hello</b>");
742          * @before <p>I would like to say: </p>
743          * @result <p>I would like to say: </p><b>Hello</b>
744          *
745          * @name after
746          * @type jQuery
747          * @param String html A string of HTML, that will be created on the fly and appended to the target.
748          * @cat DOM/Manipulation
749          */
750
751         /**
752          * Insert an element after each of the matched elements.
753          *
754          * @example $("p").after( $("#foo")[0] );
755          * @before <b id="foo">Hello</b><p>I would like to say: </p>
756          * @result <p>I would like to say: </p><b id="foo">Hello</b>
757          *
758          * @name after
759          * @type jQuery
760          * @param Element elem A DOM element that will be appended.
761          * @cat DOM/Manipulation
762          */
763
764         /**
765          * Insert any number of elements after each of the matched elements.
766          *
767          * @example $("p").after( $("b") );
768          * @before <b>Hello</b><p>I would like to say: </p>
769          * @result <p>I would like to say: </p><b>Hello</b>
770          *
771          * @name after
772          * @type jQuery
773          * @param Array<Element> elems An array of elements, all of which will be appended.
774          * @cat DOM/Manipulation
775          */
776         after: function() {
777                 return this.domManip(arguments, false, -1, function(a){
778                         this.parentNode.insertBefore( a, this.nextSibling );
779                 });
780         },
781
782         /**
783          * End the most recent 'destructive' operation, reverting the list of matched elements
784          * back to its previous state. After an end operation, the list of matched elements will
785          * revert to the last state of matched elements.
786          *
787          * @example $("p").find("span").end();
788          * @before <p><span>Hello</span>, how are you?</p>
789          * @result $("p").find("span").end() == [ <p>...</p> ]
790          *
791          * @name end
792          * @type jQuery
793          * @cat DOM/Traversing
794          */
795         end: function() {
796                 if( !(this.stack && this.stack.length) )
797                         return this;
798                 return this.set( this.stack.pop() );
799         },
800
801         /**
802          * Searches for all elements that match the specified expression.
803          * This method is the optimal way of finding additional descendant
804          * elements with which to process.
805          *
806          * All searching is done using a jQuery expression. The expression can be
807          * written using CSS 1-3 Selector syntax, or basic XPath.
808          *
809          * @example $("p").find("span");
810          * @before <p><span>Hello</span>, how are you?</p>
811          * @result $("p").find("span") == [ <span>Hello</span> ]
812          *
813          * @name find
814          * @type jQuery
815          * @param String expr An expression to search with.
816          * @cat DOM/Traversing
817          */
818         find: function(t) {
819                 return this.pushStack( jQuery.map( this, function(a){
820                         return jQuery.find(t,a);
821                 }), arguments );
822         },
823
824         /**
825          * Create cloned copies of all matched DOM Elements. This does
826          * not create a cloned copy of this particular jQuery object,
827          * instead it creates duplicate copies of all DOM Elements.
828          * This is useful for moving copies of the elements to another
829          * location in the DOM.
830          *
831          * @example $("b").clone().prependTo("p");
832          * @before <b>Hello</b><p>, how are you?</p>
833          * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
834          *
835          * @name clone
836          * @type jQuery
837          * @cat DOM/Manipulation
838          */
839         clone: function(deep) {
840                 return this.pushStack( jQuery.map( this, function(a){
841                         return a.cloneNode( deep != undefined ? deep : true );
842                 }), arguments );
843         },
844
845         /**
846          * Removes all elements from the set of matched elements that do not
847          * match the specified expression. This method is used to narrow down
848          * the results of a search.
849          *
850          * All searching is done using a jQuery expression. The expression
851          * can be written using CSS 1-3 Selector syntax, or basic XPath.
852          *
853          * @example $("p").filter(".selected")
854          * @before <p class="selected">Hello</p><p>How are you?</p>
855          * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
856          *
857          * @name filter
858          * @type jQuery
859          * @param String expr An expression to search with.
860          * @cat DOM/Traversing
861          */
862
863         /**
864          * Removes all elements from the set of matched elements that do not
865          * match at least one of the expressions passed to the function. This
866          * method is used when you want to filter the set of matched elements
867          * through more than one expression.
868          *
869          * Elements will be retained in the jQuery object if they match at
870          * least one of the expressions passed.
871          *
872          * @example $("p").filter([".selected", ":first"])
873          * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
874          * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
875          *
876          * @name filter
877          * @type jQuery
878          * @param Array<String> exprs A set of expressions to evaluate against
879          * @cat DOM/Traversing
880          */
881         filter: function(t) {
882                 return this.pushStack(
883                         t.constructor == Array &&
884                         jQuery.map(this,function(a){
885                                 for ( var i = 0; i < t.length; i++ )
886                                         if ( jQuery.filter(t[i],[a]).r.length )
887                                                 return a;
888                                 return null;
889                         }) ||
890
891                         t.constructor == Boolean &&
892                         ( t ? this.get() : [] ) ||
893
894                         typeof t == "function" &&
895                         jQuery.grep( this, t ) ||
896
897                         jQuery.filter(t,this).r, arguments );
898         },
899
900         /**
901          * Removes the specified Element from the set of matched elements. This
902          * method is used to remove a single Element from a jQuery object.
903          *
904          * @example $("p").not( document.getElementById("selected") )
905          * @before <p>Hello</p><p id="selected">Hello Again</p>
906          * @result [ <p>Hello</p> ]
907          *
908          * @name not
909          * @type jQuery
910          * @param Element el An element to remove from the set
911          * @cat DOM/Traversing
912          */
913
914         /**
915          * Removes elements matching the specified expression from the set
916          * of matched elements. This method is used to remove one or more
917          * elements from a jQuery object.
918          *
919          * @example $("p").not("#selected")
920          * @before <p>Hello</p><p id="selected">Hello Again</p>
921          * @result [ <p>Hello</p> ]
922          *
923          * @name not
924          * @type jQuery
925          * @param String expr An expression with which to remove matching elements
926          * @cat DOM/Traversing
927          */
928         not: function(t) {
929                 return this.pushStack( typeof t == "string" ?
930                         jQuery.filter(t,this,true).r :
931                         jQuery.grep(this,function(a){ return a != t; }), arguments );
932         },
933
934         /**
935          * Adds the elements matched by the expression to the jQuery object. This
936          * can be used to concatenate the result sets of two expressions.
937          *
938          * @example $("p").add("span")
939          * @before <p>Hello</p><p><span>Hello Again</span></p>
940          * @result [ <p>Hello</p>, <span>Hello Again</span> ]
941          *
942          * @name add
943          * @type jQuery
944          * @param String expr An expression whose matched elements are added
945          * @cat DOM/Traversing
946          */
947
948         /**
949          * Adds each of the Elements in the array to the set of matched elements.
950          * This is used to add a set of Elements to a jQuery object.
951          *
952          * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
953          * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
954          * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
955          *
956          * @name add
957          * @type jQuery
958          * @param Array<Element> els An array of Elements to add
959          * @cat DOM/Traversing
960          */
961
962         /**
963          * Adds a single Element to the set of matched elements. This is used to
964          * add a single Element to a jQuery object.
965          *
966          * @example $("p").add( document.getElementById("a") )
967          * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
968          * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
969          *
970          * @name add
971          * @type jQuery
972          * @param Element el An Element to add
973          * @cat DOM/Traversing
974          */
975         add: function(t) {
976                 return this.pushStack( jQuery.merge(
977                         this.get(), typeof t == "string" ?
978                                 jQuery.find(t) :
979                                 t.constructor == Array ? t : [t] ), arguments );
980         },
981
982         /**
983          * Checks the current selection against an expression and returns true,
984          * if at least one element of the selection fits the given expression.
985          * Does return false, if no element fits or the expression is not valid.
986          *
987          * @example $("input[@type='checkbox']").parent().is("form")
988          * @before <form><input type="checkbox" /></form>
989          * @result true
990          * @desc Returns true, because the parent of the input is a form element
991          * 
992          * @example $("input[@type='checkbox']").parent().is("form")
993          * @before <form><p><input type="checkbox" /></p></form>
994          * @result false
995          * @desc Returns false, because the parent of the input is a p element
996          *
997          * @example $("form").is(null)
998          * @before <form></form>
999          * @result false
1000          * @desc An invalid expression always returns false.
1001          *
1002          * @name is
1003          * @type Boolean
1004          * @param String expr The expression with which to filter
1005          * @cat DOM/Traversing
1006          */
1007         is: function(expr) {
1008                 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1009         },
1010         
1011         /**
1012          * @private
1013          * @name domManip
1014          * @param Array args
1015          * @param Boolean table Insert TBODY in TABLEs if one is not found.
1016          * @param Number dir If dir<0, process args in reverse order.
1017          * @param Function fn The function doing the DOM manipulation.
1018          * @type jQuery
1019          * @cat Core
1020          */
1021         domManip: function(args, table, dir, fn){
1022                 var clone = this.length > 1; 
1023                 var a = jQuery.clean(args);
1024                 if ( dir < 0 )
1025                         a.reverse();
1026
1027                 return this.each(function(){
1028                         var obj = this;
1029
1030                         if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1031                                 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1032
1033                         for ( var i=0; i < a.length; i++ )
1034                                 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1035
1036                 });
1037         },
1038
1039         /**
1040          *
1041          *
1042          * @private
1043          * @name pushStack
1044          * @param Array a
1045          * @param Array args
1046          * @type jQuery
1047          * @cat Core
1048          */
1049         pushStack: function(a,args) {
1050                 var fn = args && args.length > 1 && args[args.length-1];
1051                 var fn2 = args && args.length > 2 && args[args.length-2];
1052                 
1053                 if ( fn && fn.constructor != Function ) fn = null;
1054                 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1055
1056                 if ( !fn ) {
1057                         if ( !this.stack ) this.stack = [];
1058                         this.stack.push( this.get() );
1059                         this.set( a );
1060                 } else {
1061                         var old = this.get();
1062                         this.set( a );
1063
1064                         if ( fn2 && a.length || !fn2 )
1065                                 this.each( fn2 || fn ).set( old );
1066                         else
1067                                 this.set( old ).each( fn );
1068                 }
1069
1070                 return this;
1071         }
1072 };
1073
1074 /**
1075  * Extends the jQuery object itself. Can be used to add functions into
1076  * the jQuery namespace and to add plugin methods (plugins).
1077  * 
1078  * @example jQuery.fn.extend({
1079  *   check: function() {
1080  *     return this.each(function() { this.checked = true; });
1081  *   ),
1082  *   uncheck: function() {
1083  *     return this.each(function() { this.checked = false; });
1084  *   }
1085  * });
1086  * $("input[@type=checkbox]").check();
1087  * $("input[@type=radio]").uncheck();
1088  * @desc Adds two plugin methods.
1089  *
1090  * @example jQuery.extend({
1091  *   min: function(a, b) { return a < b ? a : b; },
1092  *   max: function(a, b) { return a > b ? a : b; }
1093  * });
1094  * @desc Adds two functions into the jQuery namespace
1095  *
1096  * @name $.extend
1097  * @param Object prop The object that will be merged into the jQuery object
1098  * @type Object
1099  * @cat Core
1100  */
1101
1102 /**
1103  * Extend one object with one or more others, returning the original,
1104  * modified, object. This is a great utility for simple inheritance.
1105  * 
1106  * @example var settings = { validate: false, limit: 5, name: "foo" };
1107  * var options = { validate: true, name: "bar" };
1108  * jQuery.extend(settings, options);
1109  * @result settings == { validate: true, limit: 5, name: "bar" }
1110  * @desc Merge settings and options, modifying settings
1111  *
1112  * @example var defaults = { validate: false, limit: 5, name: "foo" };
1113  * var options = { validate: true, name: "bar" };
1114  * var settings = jQuery.extend({}, defaults, options);
1115  * @result settings == { validate: true, limit: 5, name: "bar" }
1116  * @desc Merge defaults and options, without modifying the defaults
1117  *
1118  * @name $.extend
1119  * @param Object target The object to extend
1120  * @param Object prop1 The object that will be merged into the first.
1121  * @param Object propN (optional) More objects to merge into the first
1122  * @type Object
1123  * @cat Javascript
1124  */
1125 jQuery.extend = jQuery.fn.extend = function() {
1126         // copy reference to target object
1127         var target = arguments[0],
1128                 a = 1;
1129
1130         // extend jQuery itself if only one argument is passed
1131         if ( arguments.length == 1 ) {
1132                 target = this;
1133                 a = 0;
1134         }
1135         var prop;
1136         while (prop = arguments[a++])
1137                 // Extend the base object
1138                 for ( var i in prop ) target[i] = prop[i];
1139
1140         // Return the modified object
1141         return target;
1142 };
1143
1144 jQuery.extend({
1145         /**
1146          * @private
1147          * @name init
1148          * @type undefined
1149          * @cat Core
1150          */
1151         init: function(){
1152                 jQuery.initDone = true;
1153
1154                 jQuery.each( jQuery.macros.axis, function(i,n){
1155                         jQuery.fn[ i ] = function(a) {
1156                                 var ret = jQuery.map(this,n);
1157                                 if ( a && typeof a == "string" )
1158                                         ret = jQuery.filter(a,ret).r;
1159                                 return this.pushStack( ret, arguments );
1160                         };
1161                 });
1162
1163                 jQuery.each( jQuery.macros.to, function(i,n){
1164                         jQuery.fn[ i ] = function(){
1165                                 var a = arguments;
1166                                 return this.each(function(){
1167                                         for ( var j = 0; j < a.length; j++ )
1168                                                 jQuery(a[j])[n]( this );
1169                                 });
1170                         };
1171                 });
1172
1173                 jQuery.each( jQuery.macros.each, function(i,n){
1174                         jQuery.fn[ i ] = function() {
1175                                 return this.each( n, arguments );
1176                         };
1177                 });
1178
1179                 jQuery.each( jQuery.macros.filter, function(i,n){
1180                         jQuery.fn[ n ] = function(num,fn) {
1181                                 return this.filter( ":" + n + "(" + num + ")", fn );
1182                         };
1183                 });
1184
1185                 jQuery.each( jQuery.macros.attr, function(i,n){
1186                         n = n || i;
1187                         jQuery.fn[ i ] = function(h) {
1188                                 return h == undefined ?
1189                                         this.length ? this[0][n] : null :
1190                                         this.attr( n, h );
1191                         };
1192                 });
1193
1194                 jQuery.each( jQuery.macros.css, function(i,n){
1195                         jQuery.fn[ n ] = function(h) {
1196                                 return h == undefined ?
1197                                         ( this.length ? jQuery.css( this[0], n ) : null ) :
1198                                         this.css( n, h );
1199                         };
1200                 });
1201
1202         },
1203
1204         /**
1205          * A generic iterator function, which can be used to seemlessly
1206          * iterate over both objects and arrays. This function is not the same
1207          * as $().each() - which is used to iterate, exclusively, over a jQuery
1208          * object. This function can be used to iterate over anything.
1209          *
1210          * @example $.each( [0,1,2], function(i){
1211          *   alert( "Item #" + i + ": " + this );
1212          * });
1213          * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1214          *
1215          * @example $.each( { name: "John", lang: "JS" }, function(i){
1216          *   alert( "Name: " + i + ", Value: " + this );
1217          * });
1218          * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1219          *
1220          * @name $.each
1221          * @param Object obj The object, or array, to iterate over.
1222          * @param Function fn The function that will be executed on every object.
1223          * @type Object
1224          * @cat Javascript
1225          */
1226         // args is for internal usage only
1227         each: function( obj, fn, args ) {
1228                 if ( obj.length == undefined )
1229                         for ( var i in obj )
1230                                 fn.apply( obj[i], args || [i, obj[i]] );
1231                 else
1232                         for ( var i = 0; i < obj.length; i++ )
1233                                 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1234                 return obj;
1235         },
1236
1237         className: {
1238                 add: function(o,c){
1239                         if (jQuery.className.has(o,c)) return;
1240                         o.className += ( o.className ? " " : "" ) + c;
1241                 },
1242                 remove: function(o,c){
1243                         if( !c ) {
1244                                 o.className = "";
1245                         } else {
1246                                 var classes = o.className.split(" ");
1247                                 for(var i=0; i<classes.length; i++) {
1248                                         if(classes[i] == c) {
1249                                                 classes.splice(i, 1);
1250                                                 break;
1251                                         }
1252                                 }
1253                                 o.className = classes.join(' ');
1254                         }
1255                 },
1256                 has: function(e,a) {
1257                         if ( e.className != undefined )
1258                                 e = e.className;
1259                         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1260                 }
1261         },
1262
1263         /**
1264          * Swap in/out style options.
1265          * @private
1266          */
1267         swap: function(e,o,f) {
1268                 for ( var i in o ) {
1269                         e.style["old"+i] = e.style[i];
1270                         e.style[i] = o[i];
1271                 }
1272                 f.apply( e, [] );
1273                 for ( var i in o )
1274                         e.style[i] = e.style["old"+i];
1275         },
1276
1277         css: function(e,p) {
1278                 if ( p == "height" || p == "width" ) {
1279                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1280
1281                         for ( var i=0; i<d.length; i++ ) {
1282                                 old["padding" + d[i]] = 0;
1283                                 old["border" + d[i] + "Width"] = 0;
1284                         }
1285
1286                         jQuery.swap( e, old, function() {
1287                                 if (jQuery.css(e,"display") != "none") {
1288                                         oHeight = e.offsetHeight;
1289                                         oWidth = e.offsetWidth;
1290                                 } else {
1291                                         e = jQuery(e.cloneNode(true))
1292                                                 .find(":radio").removeAttr("checked").end()
1293                                                 .css({
1294                                                         visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1295                                                 }).appendTo(e.parentNode)[0];
1296
1297                                         var parPos = jQuery.css(e.parentNode,"position");
1298                                         if ( parPos == "" || parPos == "static" )
1299                                                 e.parentNode.style.position = "relative";
1300
1301                                         oHeight = e.clientHeight;
1302                                         oWidth = e.clientWidth;
1303
1304                                         if ( parPos == "" || parPos == "static" )
1305                                                 e.parentNode.style.position = "static";
1306
1307                                         e.parentNode.removeChild(e);
1308                                 }
1309                         });
1310
1311                         return p == "height" ? oHeight : oWidth;
1312                 }
1313
1314                 return jQuery.curCSS( e, p );
1315         },
1316
1317         curCSS: function(elem, prop, force) {
1318                 var ret;
1319                 
1320                 if (prop == 'opacity' && jQuery.browser.msie)
1321                         return jQuery.attr(elem.style, 'opacity');
1322                         
1323                 if (prop == "float" || prop == "cssFloat")
1324                     prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1325
1326                 if (!force && elem.style[prop]) {
1327
1328                         ret = elem.style[prop];
1329
1330                 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1331
1332                         if (prop == "cssFloat" || prop == "styleFloat")
1333                                 prop = "float";
1334
1335                         prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1336                         var cur = document.defaultView.getComputedStyle(elem, null);
1337
1338                         if ( cur )
1339                                 ret = cur.getPropertyValue(prop);
1340                         else if ( prop == 'display' )
1341                                 ret = 'none';
1342                         else
1343                                 jQuery.swap(elem, { display: 'block' }, function() {
1344                                     var c = document.defaultView.getComputedStyle(this, '');
1345                                     ret = c && c.getPropertyValue(prop) || '';
1346                                 });
1347
1348                 } else if (elem.currentStyle) {
1349
1350                         var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1351                         ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1352                         
1353                 }
1354
1355                 return ret;
1356         },
1357         
1358         clean: function(a) {
1359                 var r = [];
1360                 for ( var i = 0; i < a.length; i++ ) {
1361                         var arg = a[i];
1362                         if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1363                                 // Trim whitespace, otherwise indexOf won't work as expected
1364                                 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1365                                         div = document.createElement("div"), wrap = [0,"",""];
1366
1367                                 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1368                                         wrap = [1, "<select>", "</select>"];
1369                                 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1370                                         wrap = [1, "<table>", "</table>"];
1371                                 else if ( s3 == "<tr" )
1372                                         wrap = [2, "<table><tbody>", "</tbody></table>"];
1373                                 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1374                                         wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1375
1376                                 // Go to html and back, then peel off extra wrappers
1377                                 div.innerHTML = wrap[1] + s + wrap[2];
1378                                 while ( wrap[0]-- ) div = div.firstChild;
1379                                 
1380                                 // Remove IE's autoinserted <tbody> from table fragments
1381                                 if ( jQuery.browser.msie ) {
1382                                         var tb = null;
1383                                         // String was a <table>, *may* have spurious <tbody>
1384                                         if ( s6 == "<table" && s.indexOf("<tbody") < 0 ) 
1385                                                 tb = div.firstChild && div.firstChild.childNodes;
1386                                         // String was a bare <thead> or <tfoot>
1387                                         else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1388                                                 tb = div.childNodes;
1389                                         if ( tb ) {
1390                                                 for ( var n = tb.length-1; n >= 0 ; --n )
1391                                                         if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1392                                                                 tb[n].parentNode.removeChild(tb[n]);
1393                                         }
1394                                 }
1395                                 
1396                                 arg = div.childNodes;
1397                         } 
1398                         
1399                         
1400                         if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1401                                 for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections
1402                                         r.push(arg[n]);
1403                         else
1404                                 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1405                 }
1406
1407                 return r;
1408         },
1409
1410         nth: function(cur,result,dir){
1411                 result = result || 1;
1412                 var num = 0;
1413                 for ( ; cur; cur = cur[dir] ) {
1414                         if ( cur.nodeType == 1 ) num++;
1415                         if ( num == result || result == "even" && num % 2 == 0 && num > 1 ||
1416                                 result == "odd" && num % 2 == 1 ) return cur;
1417                 }
1418         },
1419
1420         expr: {
1421                 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1422                 "#": "a.getAttribute('id')==m[2]",
1423                 ":": {
1424                         // Position Checks
1425                         lt: "i<m[3]-0",
1426                         gt: "i>m[3]-0",
1427                         nth: "m[3]-0==i",
1428                         eq: "m[3]-0==i",
1429                         first: "i==0",
1430                         last: "i==r.length-1",
1431                         even: "i%2==0",
1432                         odd: "i%2",
1433
1434                         // Child Checks
1435                         "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling')==a",
1436                         "first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a",
1437                         "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
1438                         "only-child": "jQuery.sibling(a.parentNode.firstChild).length==1",
1439
1440                         // Parent Checks
1441                         parent: "a.childNodes.length",
1442                         empty: "!a.childNodes.length",
1443
1444                         // Text Check
1445                         contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
1446
1447                         // Visibility
1448                         visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1449                         hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1450
1451                         // Form attributes
1452                         enabled: "!a.disabled",
1453                         disabled: "a.disabled",
1454                         checked: "a.checked",
1455                         selected: "a.selected || jQuery.attr(a, 'selected')",
1456
1457                         // Form elements
1458                         text: "a.type=='text'",
1459                         radio: "a.type=='radio'",
1460                         checkbox: "a.type=='checkbox'",
1461                         file: "a.type=='file'",
1462                         password: "a.type=='password'",
1463                         submit: "a.type=='submit'",
1464                         image: "a.type=='image'",
1465                         reset: "a.type=='reset'",
1466                         button: "a.type=='button'",
1467                         input: "/input|select|textarea|button/i.test(a.nodeName)"
1468                 },
1469                 ".": "jQuery.className.has(a,m[2])",
1470                 "@": {
1471                         "=": "z==m[4]",
1472                         "!=": "z!=m[4]",
1473                         "^=": "z && !z.indexOf(m[4])",
1474                         "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1475                         "*=": "z && z.indexOf(m[4])>=0",
1476                         "": "z",
1477                         _resort: function(m){
1478                                 return ["", m[1], m[3], m[2], m[5]];
1479                         },
1480                         _prefix: "z=jQuery.attr(a,m[3]);"
1481                 },
1482                 "[": "jQuery.find(m[2],a).length"
1483         },
1484
1485         /**
1486          * All elements on a specified axis.
1487          *
1488          * @private
1489          * @name $.sibling
1490          * @type Array
1491          * @param Element elem The element to find all the siblings of (including itself).
1492          * @cat DOM/Traversing
1493          */
1494         sibling: function( n, elem ) {
1495                 var r = [];
1496
1497                 for ( ; n; n = n.nextSibling ) {
1498                         if ( n.nodeType == 1 && (!elem || n != elem) )
1499                                 r.push( n );
1500                 }
1501
1502                 return r;
1503         },
1504
1505         token: [
1506                 "\\.\\.|/\\.\\.", "a.parentNode",
1507                 ">|/", "jQuery.sibling(a.firstChild)",
1508                 "\\+", "jQuery.nth(a,2,'nextSibling')",
1509                 "~", function(a){
1510                         var s = jQuery.sibling(a.parentNode.firstChild)
1511                         return s.slice(0, jQuery.inArray(a,s));
1512                 }
1513         ],
1514
1515         /**
1516          * @name $.find
1517          * @type Array<Element>
1518          * @private
1519          * @cat Core
1520          */
1521         find: function( t, context ) {
1522                 // Quickly handle non-string expressions
1523                 if ( typeof t != "string" )
1524                         return [ t ];
1525
1526                 // Make sure that the context is a DOM Element
1527                 if ( context && context.nodeType == undefined )
1528                         context = null;
1529
1530                 // Set the correct context (if none is provided)
1531                 context = context || document;
1532
1533                 // Handle the common XPath // expression
1534                 if ( !t.indexOf("//") ) {
1535                         context = context.documentElement;
1536                         t = t.substr(2,t.length);
1537
1538                 // And the / root expression
1539                 } else if ( !t.indexOf("/") ) {
1540                         context = context.documentElement;
1541                         t = t.substr(1,t.length);
1542                         if ( t.indexOf("/") >= 1 )
1543                                 t = t.substr(t.indexOf("/"),t.length);
1544                 }
1545
1546                 // Initialize the search
1547                 var ret = [context], done = [], last = null;
1548
1549                 // Continue while a selector expression exists, and while
1550                 // we're no longer looping upon ourselves
1551                 while ( t && last != t ) {
1552                         var r = [];
1553                         last = t;
1554
1555                         t = jQuery.trim(t).replace( /^\/\//i, "" );
1556
1557                         var foundToken = false;
1558
1559                         // An attempt at speeding up child selectors that
1560                         // point to a specific element tag
1561                         var re = /^[\/>]\s*([a-z0-9*-]+)/i;
1562                         var m = re.exec(t);
1563
1564                         if ( m ) {
1565                                 // Perform our own iteration and filter
1566                                 for ( var i = 0; i < ret.length; i++ )
1567                                         for ( var c = ret[i].firstChild; c; c = c.nextSibling )
1568                                                 if ( c.nodeType == 1 && ( c.nodeName == m[1].toUpperCase() || m[1] == "*" ) )
1569                                                         r.push( c );
1570
1571                                 ret = r;
1572                                 t = jQuery.trim( t.replace( re, "" ) );
1573                                 foundToken = true;
1574                         } else {
1575                                 // Look for pre-defined expression tokens
1576                                 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1577                                         // Attempt to match each, individual, token in
1578                                         // the specified order
1579                                         var re = new RegExp("^(" + jQuery.token[i] + ")");
1580                                         var m = re.exec(t);
1581
1582                                         // If the token match was found
1583                                         if ( m ) {
1584                                                 // Map it against the token's handler
1585                                                 r = ret = jQuery.map( ret, jQuery.token[i+1].constructor == Function ?
1586                                                         jQuery.token[i+1] :
1587                                                         function(a){ return eval(jQuery.token[i+1]); });
1588
1589                                                 // And remove the token
1590                                                 t = jQuery.trim( t.replace( re, "" ) );
1591                                                 foundToken = true;
1592                                                 break;
1593                                         }
1594                                 }
1595                         }
1596
1597                         // See if there's still an expression, and that we haven't already
1598                         // matched a token
1599                         if ( t && !foundToken ) {
1600                                 // Handle multiple expressions
1601                                 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1602                                         // Clean teh result set
1603                                         if ( ret[0] == context ) ret.shift();
1604
1605                                         // Merge the result sets
1606                                         jQuery.merge( done, ret );
1607
1608                                         // Reset the context
1609                                         r = ret = [context];
1610
1611                                         // Touch up the selector string
1612                                         t = " " + t.substr(1,t.length);
1613
1614                                 } else {
1615                                         // Optomize for the case nodeName#idName
1616                                         var re2 = /^([a-z0-9_-]+)(#)([a-z0-9\\*_-]*)/i;
1617                                         var m = re2.exec(t);
1618                                         
1619                                         // Re-organize the results, so that they're consistent
1620                                         if ( m ) {
1621                                            m = [ 0, m[2], m[3], m[1] ];
1622
1623                                         } else {
1624                                                 // Otherwise, do a traditional filter check for
1625                                                 // ID, class, and element selectors
1626                                                 re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1627                                                 m = re2.exec(t);
1628                                         }
1629
1630                                         // Try to do a global search by ID, where we can
1631                                         if ( m[1] == "#" && ret[ret.length-1].getElementById ) {
1632                                                 // Optimization for HTML document case
1633                                                 var oid = ret[ret.length-1].getElementById(m[2]);
1634
1635                                                 // Do a quick check for node name (where applicable) so
1636                                                 // that div#foo searches will be really fast
1637                                                 ret = r = oid && 
1638                                                   (!m[3] || oid.nodeName == m[3].toUpperCase()) ? [oid] : [];
1639
1640                                         // Use the DOM 0 shortcut for the body element
1641                                         } else if ( m[1] == "" && m[2] == "body" ) {
1642                                                 ret = r = [ document.body ];
1643
1644                                         } else {
1645                                                 // Pre-compile a regular expression to handle class searches
1646                                                 if ( m[1] == "." )
1647                                                         var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
1648
1649                                                 // We need to find all descendant elements, it is more
1650                                                 // efficient to use getAll() when we are already further down
1651                                                 // the tree - we try to recognize that here
1652                                                 for ( var i = 0; i < ret.length; i++ )
1653                                                         jQuery.merge( r,
1654                                                                 m[1] != "" && ret.length != 1 ?
1655                                                                         jQuery.getAll( ret[i], [], m[1], m[2], rec ) :
1656                                                                         ret[i].getElementsByTagName( m[1] != "" || m[0] == "" ? "*" : m[2] )
1657                                                         );
1658
1659                                                 // It's faster to filter by class and be done with it
1660                                                 if ( m[1] == "." && ret.length == 1 )
1661                                                         r = jQuery.grep( r, function(e) {
1662                                                                 return rec.test(e.className);
1663                                                         });
1664
1665                                                 // Same with ID filtering
1666                                                 if ( m[1] == "#" && ret.length == 1 ) {
1667                                                         // Remember, then wipe out, the result set
1668                                                         var tmp = r;
1669                                                         r = [];
1670
1671                                                         // Then try to find the element with the ID
1672                                                         for ( var i = 0; i < tmp.length; i++ )
1673                                                                 if ( tmp[i].getAttribute("id") == m[2] ) {
1674                                                                         r = [ tmp[i] ];
1675                                                                         break;
1676                                                                 }
1677                                                 }
1678
1679                                                 ret = r;
1680                                         }
1681
1682                                         t = t.replace( re2, "" );
1683                                 }
1684
1685                         }
1686
1687                         // If a selector string still exists
1688                         if ( t ) {
1689                                 // Attempt to filter it
1690                                 var val = jQuery.filter(t,r);
1691                                 ret = r = val.r;
1692                                 t = jQuery.trim(val.t);
1693                         }
1694                 }
1695
1696                 // Remove the root context
1697                 if ( ret && ret[0] == context ) ret.shift();
1698
1699                 // And combine the results
1700                 jQuery.merge( done, ret );
1701
1702                 return done;
1703         },
1704
1705         getAll: function( o, r, token, name, re ) {
1706                 for ( var s = o.firstChild; s; s = s.nextSibling )
1707                         if ( s.nodeType == 1 ) {
1708                                 var add = true;
1709
1710                                 if ( token == "." )
1711                                         add = s.className && re.test(s.className);
1712                                 else if ( token == "#" )
1713                                         add = s.getAttribute('id') == name;
1714         
1715                                 if ( add )
1716                                         r.push( s );
1717
1718                                 if ( token == "#" && r.length ) break;
1719
1720                                 if ( s.firstChild )
1721                                         jQuery.getAll( s, r, token, name, re );
1722                         }
1723
1724                 return r;
1725         },
1726
1727         attr: function(elem, name, value){
1728                 var fix = {
1729                         "for": "htmlFor",
1730                         "class": "className",
1731                         "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1732                         cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1733                         innerHTML: "innerHTML",
1734                         className: "className",
1735                         value: "value",
1736                         disabled: "disabled",
1737                         checked: "checked",
1738                         readonly: "readOnly",
1739                         selected: "selected"
1740                 };
1741                 
1742                 // IE actually uses filters for opacity ... elem is actually elem.style
1743                 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1744                         // IE has trouble with opacity if it does not have layout
1745                         // Force it by setting the zoom level
1746                         elem.zoom = 1; 
1747
1748                         // Set the alpha filter to set the opacity
1749                         return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1750                                 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1751
1752                 } else if ( name == "opacity" && jQuery.browser.msie ) {
1753                         return elem.filter ? 
1754                                 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1755                 }
1756                 
1757                 // Mozilla doesn't play well with opacity 1
1758                 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1759                         value = 0.9999;
1760
1761                 // Certain attributes only work when accessed via the old DOM 0 way
1762                 if ( fix[name] ) {
1763                         if ( value != undefined ) elem[fix[name]] = value;
1764                         return elem[fix[name]];
1765
1766                 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1767                         return elem.getAttributeNode(name).nodeValue;
1768
1769                 // IE elem.getAttribute passes even for style
1770                 } else if ( elem.tagName ) {
1771                         if ( value != undefined ) elem.setAttribute( name, value );
1772                         return elem.getAttribute( name );
1773
1774                 } else {
1775                         name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1776                         if ( value != undefined ) elem[name] = value;
1777                         return elem[name];
1778                 }
1779         },
1780
1781         // The regular expressions that power the parsing engine
1782         parse: [
1783                 // Match: [@value='test'], [@foo]
1784                 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1785
1786                 // Match: [div], [div p]
1787                 "(\\[)\s*(.*?)\s*\\]",
1788
1789                 // Match: :contains('foo')
1790                 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1791
1792                 // Match: :even, :last-chlid
1793                 "([:.#]*)S"
1794         ],
1795
1796         filter: function(t,r,not) {
1797                 // Look for common filter expressions
1798                 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1799
1800                         var p = jQuery.parse;
1801
1802                         for ( var i = 0; i < p.length; i++ ) {
1803                 
1804                                 // Look for, and replace, string-like sequences
1805                                 // and finally build a regexp out of it
1806                                 var re = new RegExp(
1807                                         "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1808
1809                                 var m = re.exec( t );
1810
1811                                 if ( m ) {
1812                                         // Re-organize the first match
1813                                         if ( jQuery.expr[ m[1] ]._resort )
1814                                                 m = jQuery.expr[ m[1] ]._resort( m );
1815
1816                                         // Remove what we just matched
1817                                         t = t.replace( re, "" );
1818
1819                                         break;
1820                                 }
1821                         }
1822
1823                         // :not() is a special case that can be optimized by
1824                         // keeping it out of the expression list
1825                         if ( m[1] == ":" && m[2] == "not" )
1826                                 r = jQuery.filter(m[3], r, true).r;
1827
1828                         // Handle classes as a special case (this will help to
1829                         // improve the speed, as the regexp will only be compiled once)
1830                         else if ( m[1] == "." ) {
1831
1832                                 var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
1833                                 r = jQuery.grep( r, function(e){
1834                                         return re.test(e.className || '');
1835                                 }, not);
1836
1837                         // Otherwise, find the expression to execute
1838                         } else {
1839                                 var f = jQuery.expr[m[1]];
1840                                 if ( typeof f != "string" )
1841                                         f = jQuery.expr[m[1]][m[2]];
1842
1843                                 // Build a custom macro to enclose it
1844                                 eval("f = function(a,i){" +
1845                                         ( jQuery.expr[ m[1] ]._prefix || "" ) +
1846                                         "return " + f + "}");
1847
1848                                 // Execute it against the current filter
1849                                 r = jQuery.grep( r, f, not );
1850                         }
1851                 }
1852
1853                 // Return an array of filtered elements (r)
1854                 // and the modified expression string (t)
1855                 return { r: r, t: t };
1856         },
1857
1858         /**
1859          * Remove the whitespace from the beginning and end of a string.
1860          *
1861          * @example $.trim("  hello, how are you?  ");
1862          * @result "hello, how are you?"
1863          *
1864          * @name $.trim
1865          * @type String
1866          * @param String str The string to trim.
1867          * @cat Javascript
1868          */
1869         trim: function(t){
1870                 return t.replace(/^\s+|\s+$/g, "");
1871         },
1872
1873         /**
1874          * All ancestors of a given element.
1875          *
1876          * @private
1877          * @name $.parents
1878          * @type Array<Element>
1879          * @param Element elem The element to find the ancestors of.
1880          * @cat DOM/Traversing
1881          */
1882         parents: function( elem ){
1883                 var matched = [];
1884                 var cur = elem.parentNode;
1885                 while ( cur && cur != document ) {
1886                         matched.push( cur );
1887                         cur = cur.parentNode;
1888                 }
1889                 return matched;
1890         },
1891
1892         makeArray: function( a ) {
1893                 var r = [];
1894
1895                 if ( a.constructor != Array ) {
1896                         for ( var i = 0; i < a.length; i++ )
1897                                 r.push( a[i] );
1898                 } else
1899                         r = a.slice( 0 );
1900
1901                 return r;
1902         },
1903
1904         inArray: function( b, a ) {
1905                 for ( var i = 0; i < a.length; i++ )
1906                         if ( a[i] == b )
1907                                 return i;
1908                 return -1;
1909         },
1910
1911         /**
1912          * Merge two arrays together, removing all duplicates. The final order
1913          * or the new array is: All the results from the first array, followed
1914          * by the unique results from the second array.
1915          *
1916          * @example $.merge( [0,1,2], [2,3,4] )
1917          * @result [0,1,2,3,4]
1918          *
1919          * @example $.merge( [3,2,1], [4,3,2] )
1920          * @result [3,2,1,4]
1921          *
1922          * @name $.merge
1923          * @type Array
1924          * @param Array first The first array to merge.
1925          * @param Array second The second array to merge.
1926          * @cat Javascript
1927          */
1928         merge: function(first, second) {
1929                 var r = [].slice.call( first, 0 );
1930
1931                 // Now check for duplicates between the two arrays
1932                 // and only add the unique items
1933                 for ( var i = 0; i < second.length; i++ ) {
1934                         // Check for duplicates
1935                         if ( jQuery.inArray( second[i], r ) == -1 )
1936                                 // The item is unique, add it
1937                                 first.push( second[i] );
1938                 }
1939
1940                 return first;
1941         },
1942
1943         /**
1944          * Filter items out of an array, by using a filter function.
1945          * The specified function will be passed two arguments: The
1946          * current array item and the index of the item in the array. The
1947          * function should return 'true' if you wish to keep the item in
1948          * the array, false if it should be removed.
1949          *
1950          * @example $.grep( [0,1,2], function(i){
1951          *   return i > 0;
1952          * });
1953          * @result [1, 2]
1954          *
1955          * @name $.grep
1956          * @type Array
1957          * @param Array array The Array to find items in.
1958          * @param Function fn The function to process each item against.
1959          * @param Boolean inv Invert the selection - select the opposite of the function.
1960          * @cat Javascript
1961          */
1962         grep: function(elems, fn, inv) {
1963                 // If a string is passed in for the function, make a function
1964                 // for it (a handy shortcut)
1965                 if ( typeof fn == "string" )
1966                         fn = new Function("a","i","return " + fn);
1967
1968                 var result = [];
1969
1970                 // Go through the array, only saving the items
1971                 // that pass the validator function
1972                 for ( var i = 0; i < elems.length; i++ )
1973                         if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1974                                 result.push( elems[i] );
1975
1976                 return result;
1977         },
1978
1979         /**
1980          * Translate all items in an array to another array of items. 
1981          * The translation function that is provided to this method is 
1982          * called for each item in the array and is passed one argument: 
1983          * The item to be translated. The function can then return:
1984          * The translated value, 'null' (to remove the item), or 
1985          * an array of values - which will be flattened into the full array.
1986          *
1987          * @example $.map( [0,1,2], function(i){
1988          *   return i + 4;
1989          * });
1990          * @result [4, 5, 6]
1991          *
1992          * @example $.map( [0,1,2], function(i){
1993          *   return i > 0 ? i + 1 : null;
1994          * });
1995          * @result [2, 3]
1996          * 
1997          * @example $.map( [0,1,2], function(i){
1998          *   return [ i, i + 1 ];
1999          * });
2000          * @result [0, 1, 1, 2, 2, 3]
2001          *
2002          * @name $.map
2003          * @type Array
2004          * @param Array array The Array to translate.
2005          * @param Function fn The function to process each item against.
2006          * @cat Javascript
2007          */
2008         map: function(elems, fn) {
2009                 // If a string is passed in for the function, make a function
2010                 // for it (a handy shortcut)
2011                 if ( typeof fn == "string" )
2012                         fn = new Function("a","return " + fn);
2013
2014                 var result = [], r = [];
2015
2016                 // Go through the array, translating each of the items to their
2017                 // new value (or values).
2018                 for ( var i = 0; i < elems.length; i++ ) {
2019                         var val = fn(elems[i],i);
2020
2021                         if ( val !== null && val != undefined ) {
2022                                 if ( val.constructor != Array ) val = [val];
2023                                 result = result.concat( val );
2024                         }
2025                 }
2026
2027                 var r = [ result[0] ];
2028
2029                 check: for ( var i = 1; i < result.length; i++ ) {
2030                         for ( var j = 0; j < i; j++ )
2031                                 if ( result[i] == r[j] )
2032                                         continue check;
2033
2034                         r.push( result[i] );
2035                 }
2036
2037                 return r;
2038         },
2039
2040         /*
2041          * A number of helper functions used for managing events.
2042          * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2043          */
2044         event: {
2045
2046                 // Bind an event to an element
2047                 // Original by Dean Edwards
2048                 add: function(element, type, handler) {
2049                         // For whatever reason, IE has trouble passing the window object
2050                         // around, causing it to be cloned in the process
2051                         if ( jQuery.browser.msie && element.setInterval != undefined )
2052                                 element = window;
2053
2054                         // Make sure that the function being executed has a unique ID
2055                         if ( !handler.guid )
2056                                 handler.guid = this.guid++;
2057
2058                         // Init the element's event structure
2059                         if (!element.events)
2060                                 element.events = {};
2061
2062                         // Get the current list of functions bound to this event
2063                         var handlers = element.events[type];
2064
2065                         // If it hasn't been initialized yet
2066                         if (!handlers) {
2067                                 // Init the event handler queue
2068                                 handlers = element.events[type] = {};
2069
2070                                 // Remember an existing handler, if it's already there
2071                                 if (element["on" + type])
2072                                         handlers[0] = element["on" + type];
2073                         }
2074
2075                         // Add the function to the element's handler list
2076                         handlers[handler.guid] = handler;
2077
2078                         // And bind the global event handler to the element
2079                         element["on" + type] = this.handle;
2080
2081                         // Remember the function in a global list (for triggering)
2082                         if (!this.global[type])
2083                                 this.global[type] = [];
2084                         this.global[type].push( element );
2085                 },
2086
2087                 guid: 1,
2088                 global: {},
2089
2090                 // Detach an event or set of events from an element
2091                 remove: function(element, type, handler) {
2092                         if (element.events)
2093                                 if ( type && type.type )
2094                                         delete element.events[ type.type ][ type.handler.guid ];
2095                                 else if (type && element.events[type])
2096                                         if ( handler )
2097                                                 delete element.events[type][handler.guid];
2098                                         else
2099                                                 for ( var i in element.events[type] )
2100                                                         delete element.events[type][i];
2101                                 else
2102                                         for ( var j in element.events )
2103                                                 this.remove( element, j );
2104                 },
2105
2106                 trigger: function(type,data,element) {
2107                         // Clone the incoming data, if any
2108                         data = jQuery.makeArray(data || []);
2109
2110                         // Handle a global trigger
2111                         if ( !element ) {
2112                                 var g = this.global[type];
2113                                 if ( g )
2114                                         for ( var i = 0; i < g.length; i++ )
2115                                                 this.trigger( type, data, g[i] );
2116
2117                         // Handle triggering a single element
2118                         } else if ( element["on" + type] ) {
2119                                 // Pass along a fake event
2120                                 data.unshift( this.fix({ type: type, target: element }) );
2121
2122                                 // Trigger the event
2123                                 element["on" + type].apply( element, data );
2124                         }
2125                 },
2126
2127                 handle: function(event) {
2128                         if ( typeof jQuery == "undefined" ) return false;
2129
2130                         event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data
2131
2132                         var returnValue = true;
2133
2134                         var c = this.events[event.type];
2135
2136                         var args = [].slice.call( arguments, 1 );
2137                         args.unshift( event );
2138
2139                         for ( var j in c ) {
2140                                 // Pass in a reference to the handler function itself
2141                                 // So that we can later remove it
2142                                 args[0].handler = c[j];
2143
2144                                 if ( c[j].apply( this, args ) === false ) {
2145                                         event.preventDefault();
2146                                         event.stopPropagation();
2147                                         returnValue = false;
2148                                 }
2149                         }
2150
2151                         // Clean up added properties in IE to prevent memory leak
2152                         if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null;
2153
2154                         return returnValue;
2155                 },
2156
2157                 fix: function(event) {
2158                         // Fix target property, if necessary
2159                         if ( !event.target && event.srcElement )
2160                                 event.target = event.srcElement;
2161
2162                         // Calculate pageX/Y if missing and clientX/Y available
2163                         if ( typeof event.pageX == "undefined" && typeof event.clientX != "undefined" ) {
2164                                 var e = document.documentElement, b = document.body;
2165                                 event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
2166                                 event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
2167                         }
2168                                         
2169                         // Check safari and if target is a textnode
2170                         if ( jQuery.browser.safari && event.target.nodeType == 3 ) {
2171                                 // target is readonly, clone the event object
2172                                 event = jQuery.extend({}, event);
2173                                 // get parentnode from textnode
2174                                 event.target = event.target.parentNode;
2175                         }
2176                         
2177                         // fix preventDefault and stopPropagation
2178                         if (!event.preventDefault) {
2179                                 event.preventDefault = function() {
2180                                         this.returnValue = false;
2181                                 };
2182                         }
2183                                 
2184                         if (!event.stopPropagation) {
2185                                 event.stopPropagation = function() {
2186                                         this.cancelBubble = true;
2187                                 };
2188                         }
2189                                 
2190                         return event;
2191                 }
2192         }
2193 });
2194
2195 /**
2196  * Contains flags for the useragent, read from navigator.userAgent.
2197  * Available flags are: safari, opera, msie, mozilla
2198  * This property is available before the DOM is ready, therefore you can
2199  * use it to add ready events only for certain browsers.
2200  *
2201  * There are situations where object detections is not reliable enough, in that
2202  * cases it makes sense to use browser detection. Simply try to avoid both!
2203  *
2204  * A combination of browser and object detection yields quite reliable results.
2205  *
2206  * @example $.browser.msie
2207  * @desc Returns true if the current useragent is some version of microsoft's internet explorer
2208  *
2209  * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2210  * @desc Alerts "this is safari!" only for safari browsers
2211  *
2212  * @property
2213  * @name $.browser
2214  * @type Boolean
2215  * @cat Javascript
2216  */
2217  
2218 /*
2219  * Wheather the W3C compliant box model is being used.
2220  *
2221  * @property
2222  * @name $.boxModel
2223  * @type Boolean
2224  * @cat Javascript
2225  */
2226 new function() {
2227         var b = navigator.userAgent.toLowerCase();
2228
2229         // Figure out what browser is being used
2230         jQuery.browser = {
2231                 safari: /webkit/.test(b),
2232                 opera: /opera/.test(b),
2233                 msie: /msie/.test(b) && !/opera/.test(b),
2234                 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2235         };
2236
2237         // Check to see if the W3C box model is being used
2238         jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2239 };
2240
2241 jQuery.macros = {
2242         to: {
2243                 /**
2244                  * Append all of the matched elements to another, specified, set of elements.
2245                  * This operation is, essentially, the reverse of doing a regular
2246                  * $(A).append(B), in that instead of appending B to A, you're appending
2247                  * A to B.
2248                  *
2249                  * @example $("p").appendTo("#foo");
2250                  * @before <p>I would like to say: </p><div id="foo"></div>
2251                  * @result <div id="foo"><p>I would like to say: </p></div>
2252                  *
2253                  * @name appendTo
2254                  * @type jQuery
2255                  * @param String expr A jQuery expression of elements to match.
2256                  * @cat DOM/Manipulation
2257                  */
2258                 appendTo: "append",
2259
2260                 /**
2261                  * Prepend all of the matched elements to another, specified, set of elements.
2262                  * This operation is, essentially, the reverse of doing a regular
2263                  * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2264                  * A to B.
2265                  *
2266                  * @example $("p").prependTo("#foo");
2267                  * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2268                  * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2269                  *
2270                  * @name prependTo
2271                  * @type jQuery
2272                  * @param String expr A jQuery expression of elements to match.
2273                  * @cat DOM/Manipulation
2274                  */
2275                 prependTo: "prepend",
2276
2277                 /**
2278                  * Insert all of the matched elements before another, specified, set of elements.
2279                  * This operation is, essentially, the reverse of doing a regular
2280                  * $(A).before(B), in that instead of inserting B before A, you're inserting
2281                  * A before B.
2282                  *
2283                  * @example $("p").insertBefore("#foo");
2284                  * @before <div id="foo">Hello</div><p>I would like to say: </p>
2285                  * @result <p>I would like to say: </p><div id="foo">Hello</div>
2286                  *
2287                  * @name insertBefore
2288                  * @type jQuery
2289                  * @param String expr A jQuery expression of elements to match.
2290                  * @cat DOM/Manipulation
2291                  */
2292                 insertBefore: "before",
2293
2294                 /**
2295                  * Insert all of the matched elements after another, specified, set of elements.
2296                  * This operation is, essentially, the reverse of doing a regular
2297                  * $(A).after(B), in that instead of inserting B after A, you're inserting
2298                  * A after B.
2299                  *
2300                  * @example $("p").insertAfter("#foo");
2301                  * @before <p>I would like to say: </p><div id="foo">Hello</div>
2302                  * @result <div id="foo">Hello</div><p>I would like to say: </p>
2303                  *
2304                  * @name insertAfter
2305                  * @type jQuery
2306                  * @param String expr A jQuery expression of elements to match.
2307                  * @cat DOM/Manipulation
2308                  */
2309                 insertAfter: "after"
2310         },
2311
2312         /**
2313          * Get the current CSS width of the first matched element.
2314          *
2315          * @example $("p").width();
2316          * @before <p>This is just a test.</p>
2317          * @result "300px"
2318          *
2319          * @name width
2320          * @type String
2321          * @cat CSS
2322          */
2323
2324         /**
2325          * Set the CSS width of every matched element. Be sure to include
2326          * the "px" (or other unit of measurement) after the number that you
2327          * specify, otherwise you might get strange results.
2328          *
2329          * @example $("p").width("20px");
2330          * @before <p>This is just a test.</p>
2331          * @result <p style="width:20px;">This is just a test.</p>
2332          *
2333          * @name width
2334          * @type jQuery
2335          * @param String val Set the CSS property to the specified value.
2336          * @cat CSS
2337          */
2338
2339         /**
2340          * Get the current CSS height of the first matched element.
2341          *
2342          * @example $("p").height();
2343          * @before <p>This is just a test.</p>
2344          * @result "14px"
2345          *
2346          * @name height
2347          * @type String
2348          * @cat CSS
2349          */
2350
2351         /**
2352          * Set the CSS height of every matched element. Be sure to include
2353          * the "px" (or other unit of measurement) after the number that you
2354          * specify, otherwise you might get strange results.
2355          *
2356          * @example $("p").height("20px");
2357          * @before <p>This is just a test.</p>
2358          * @result <p style="height:20px;">This is just a test.</p>
2359          *
2360          * @name height
2361          * @type jQuery
2362          * @param String val Set the CSS property to the specified value.
2363          * @cat CSS
2364          */
2365
2366         /**
2367          * Get the current CSS top of the first matched element.
2368          *
2369          * @example $("p").top();
2370          * @before <p>This is just a test.</p>
2371          * @result "0px"
2372          *
2373          * @name top
2374          * @type String
2375          * @cat CSS
2376          */
2377
2378         /**
2379          * Set the CSS top of every matched element. Be sure to include
2380          * the "px" (or other unit of measurement) after the number that you
2381          * specify, otherwise you might get strange results.
2382          *
2383          * @example $("p").top("20px");
2384          * @before <p>This is just a test.</p>
2385          * @result <p style="top:20px;">This is just a test.</p>
2386          *
2387          * @name top
2388          * @type jQuery
2389          * @param String val Set the CSS property to the specified value.
2390          * @cat CSS
2391          */
2392
2393         /**
2394          * Get the current CSS left of the first matched element.
2395          *
2396          * @example $("p").left();
2397          * @before <p>This is just a test.</p>
2398          * @result "0px"
2399          *
2400          * @name left
2401          * @type String
2402          * @cat CSS
2403          */
2404
2405         /**
2406          * Set the CSS left of every matched element. Be sure to include
2407          * the "px" (or other unit of measurement) after the number that you
2408          * specify, otherwise you might get strange results.
2409          *
2410          * @example $("p").left("20px");
2411          * @before <p>This is just a test.</p>
2412          * @result <p style="left:20px;">This is just a test.</p>
2413          *
2414          * @name left
2415          * @type jQuery
2416          * @param String val Set the CSS property to the specified value.
2417          * @cat CSS
2418          */
2419
2420         /**
2421          * Get the current CSS position of the first matched element.
2422          *
2423          * @example $("p").position();
2424          * @before <p>This is just a test.</p>
2425          * @result "static"
2426          *
2427          * @name position
2428          * @type String
2429          * @cat CSS
2430          */
2431
2432         /**
2433          * Set the CSS position of every matched element.
2434          *
2435          * @example $("p").position("relative");
2436          * @before <p>This is just a test.</p>
2437          * @result <p style="position:relative;">This is just a test.</p>
2438          *
2439          * @name position
2440          * @type jQuery
2441          * @param String val Set the CSS property to the specified value.
2442          * @cat CSS
2443          */
2444
2445         /**
2446          * Get the current CSS float of the first matched element.
2447          *
2448          * @example $("p").float();
2449          * @before <p>This is just a test.</p>
2450          * @result "none"
2451          *
2452          * @name float
2453          * @type String
2454          * @cat CSS
2455          */
2456
2457         /**
2458          * Set the CSS float of every matched element.
2459          *
2460          * @example $("p").float("left");
2461          * @before <p>This is just a test.</p>
2462          * @result <p style="float:left;">This is just a test.</p>
2463          *
2464          * @name float
2465          * @type jQuery
2466          * @param String val Set the CSS property to the specified value.
2467          * @cat CSS
2468          */
2469
2470         /**
2471          * Get the current CSS overflow of the first matched element.
2472          *
2473          * @example $("p").overflow();
2474          * @before <p>This is just a test.</p>
2475          * @result "none"
2476          *
2477          * @name overflow
2478          * @type String
2479          * @cat CSS
2480          */
2481
2482         /**
2483          * Set the CSS overflow of every matched element.
2484          *
2485          * @example $("p").overflow("auto");
2486          * @before <p>This is just a test.</p>
2487          * @result <p style="overflow:auto;">This is just a test.</p>
2488          *
2489          * @name overflow
2490          * @type jQuery
2491          * @param String val Set the CSS property to the specified value.
2492          * @cat CSS
2493          */
2494
2495         /**
2496          * Get the current CSS color of the first matched element.
2497          *
2498          * @example $("p").color();
2499          * @before <p>This is just a test.</p>
2500          * @result "black"
2501          *
2502          * @name color
2503          * @type String
2504          * @cat CSS
2505          */
2506
2507         /**
2508          * Set the CSS color of every matched element.
2509          *
2510          * @example $("p").color("blue");
2511          * @before <p>This is just a test.</p>
2512          * @result <p style="color:blue;">This is just a test.</p>
2513          *
2514          * @name color
2515          * @type jQuery
2516          * @param String val Set the CSS property to the specified value.
2517          * @cat CSS
2518          */
2519
2520         /**
2521          * Get the current CSS background of the first matched element.
2522          *
2523          * @example $("p").background();
2524          * @before <p style="background:blue;">This is just a test.</p>
2525          * @result "blue"
2526          *
2527          * @name background
2528          * @type String
2529          * @cat CSS
2530          */
2531
2532         /**
2533          * Set the CSS background of every matched element.
2534          *
2535          * @example $("p").background("blue");
2536          * @before <p>This is just a test.</p>
2537          * @result <p style="background:blue;">This is just a test.</p>
2538          *
2539          * @name background
2540          * @type jQuery
2541          * @param String val Set the CSS property to the specified value.
2542          * @cat CSS
2543          */
2544
2545         css: "width,height,top,left,position,float,overflow,color,background".split(","),
2546
2547         /**
2548          * Reduce the set of matched elements to a single element.
2549          * The position of the element in the set of matched elements
2550          * starts at 0 and goes to length - 1.
2551          *
2552          * @example $("p").eq(1)
2553          * @before <p>This is just a test.</p><p>So is this</p>
2554          * @result [ <p>So is this</p> ]
2555          *
2556          * @name eq
2557          * @type jQuery
2558          * @param Number pos The index of the element that you wish to limit to.
2559          * @cat Core
2560          */
2561
2562         /**
2563          * Reduce the set of matched elements to all elements before a given position.
2564          * The position of the element in the set of matched elements
2565          * starts at 0 and goes to length - 1.
2566          *
2567          * @example $("p").lt(1)
2568          * @before <p>This is just a test.</p><p>So is this</p>
2569          * @result [ <p>This is just a test.</p> ]
2570          *
2571          * @name lt
2572          * @type jQuery
2573          * @param Number pos Reduce the set to all elements below this position.
2574          * @cat Core
2575          */
2576
2577         /**
2578          * Reduce the set of matched elements to all elements after a given position.
2579          * The position of the element in the set of matched elements
2580          * starts at 0 and goes to length - 1.
2581          *
2582          * @example $("p").gt(0)
2583          * @before <p>This is just a test.</p><p>So is this</p>
2584          * @result [ <p>So is this</p> ]
2585          *
2586          * @name gt
2587          * @type jQuery
2588          * @param Number pos Reduce the set to all elements after this position.
2589          * @cat Core
2590          */
2591
2592         /**
2593          * Filter the set of elements to those that contain the specified text.
2594          *
2595          * @example $("p").contains("test")
2596          * @before <p>This is just a test.</p><p>So is this</p>
2597          * @result [ <p>This is just a test.</p> ]
2598          *
2599          * @name contains
2600          * @type jQuery
2601          * @param String str The string that will be contained within the text of an element.
2602          * @cat DOM/Traversing
2603          */
2604
2605         filter: [ "eq", "lt", "gt", "contains" ],
2606
2607         attr: {
2608                 /**
2609                  * Get the current value of the first matched element.
2610                  *
2611                  * @example $("input").val();
2612                  * @before <input type="text" value="some text"/>
2613                  * @result "some text"
2614                  *
2615                  * @name val
2616                  * @type String
2617                  * @cat DOM/Attributes
2618                  */
2619
2620                 /**
2621                  * Set the value of every matched element.
2622                  *
2623                  * @example $("input").val("test");
2624                  * @before <input type="text" value="some text"/>
2625                  * @result <input type="text" value="test"/>
2626                  *
2627                  * @name val
2628                  * @type jQuery
2629                  * @param String val Set the property to the specified value.
2630                  * @cat DOM/Attributes
2631                  */
2632                 val: "value",
2633
2634                 /**
2635                  * Get the html contents of the first matched element.
2636                  * This property is not available on XML documents.
2637                  *
2638                  * @example $("div").html();
2639                  * @before <div><input/></div>
2640                  * @result <input/>
2641                  *
2642                  * @name html
2643                  * @type String
2644                  * @cat DOM/Attributes
2645                  */
2646
2647                 /**
2648                  * Set the html contents of every matched element.
2649                  * This property is not available on XML documents.
2650                  *
2651                  * @example $("div").html("<b>new stuff</b>");
2652                  * @before <div><input/></div>
2653                  * @result <div><b>new stuff</b></div>
2654                  *
2655                  * @name html
2656                  * @type jQuery
2657                  * @param String val Set the html contents to the specified value.
2658                  * @cat DOM/Attributes
2659                  */
2660                 html: "innerHTML",
2661
2662                 /**
2663                  * Get the current id of the first matched element.
2664                  *
2665                  * @example $("input").id();
2666                  * @before <input type="text" id="test" value="some text"/>
2667                  * @result "test"
2668                  *
2669                  * @name id
2670                  * @type String
2671                  * @cat DOM/Attributes
2672                  */
2673
2674                 /**
2675                  * Set the id of every matched element.
2676                  *
2677                  * @example $("input").id("newid");
2678                  * @before <input type="text" id="test" value="some text"/>
2679                  * @result <input type="text" id="newid" value="some text"/>
2680                  *
2681                  * @name id
2682                  * @type jQuery
2683                  * @param String val Set the property to the specified value.
2684                  * @cat DOM/Attributes
2685                  */
2686                 id: null,
2687
2688                 /**
2689                  * Get the current title of the first matched element.
2690                  *
2691                  * @example $("img").title();
2692                  * @before <img src="test.jpg" title="my image"/>
2693                  * @result "my image"
2694                  *
2695                  * @name title
2696                  * @type String
2697                  * @cat DOM/Attributes
2698                  */
2699
2700                 /**
2701                  * Set the title of every matched element.
2702                  *
2703                  * @example $("img").title("new title");
2704                  * @before <img src="test.jpg" title="my image"/>
2705                  * @result <img src="test.jpg" title="new image"/>
2706                  *
2707                  * @name title
2708                  * @type jQuery
2709                  * @param String val Set the property to the specified value.
2710                  * @cat DOM/Attributes
2711                  */
2712                 title: null,
2713
2714                 /**
2715                  * Get the current name of the first matched element.
2716                  *
2717                  * @example $("input").name();
2718                  * @before <input type="text" name="username"/>
2719                  * @result "username"
2720                  *
2721                  * @name name
2722                  * @type String
2723                  * @cat DOM/Attributes
2724                  */
2725
2726                 /**
2727                  * Set the name of every matched element.
2728                  *
2729                  * @example $("input").name("user");
2730                  * @before <input type="text" name="username"/>
2731                  * @result <input type="text" name="user"/>
2732                  *
2733                  * @name name
2734                  * @type jQuery
2735                  * @param String val Set the property to the specified value.
2736                  * @cat DOM/Attributes
2737                  */
2738                 name: null,
2739
2740                 /**
2741                  * Get the current href of the first matched element.
2742                  *
2743                  * @example $("a").href();
2744                  * @before <a href="test.html">my link</a>
2745                  * @result "test.html"
2746                  *
2747                  * @name href
2748                  * @type String
2749                  * @cat DOM/Attributes
2750                  */
2751
2752                 /**
2753                  * Set the href of every matched element.
2754                  *
2755                  * @example $("a").href("test2.html");
2756                  * @before <a href="test.html">my link</a>
2757                  * @result <a href="test2.html">my link</a>
2758                  *
2759                  * @name href
2760                  * @type jQuery
2761                  * @param String val Set the property to the specified value.
2762                  * @cat DOM/Attributes
2763                  */
2764                 href: null,
2765
2766                 /**
2767                  * Get the current src of the first matched element.
2768                  *
2769                  * @example $("img").src();
2770                  * @before <img src="test.jpg" title="my image"/>
2771                  * @result "test.jpg"
2772                  *
2773                  * @name src
2774                  * @type String
2775                  * @cat DOM/Attributes
2776                  */
2777
2778                 /**
2779                  * Set the src of every matched element.
2780                  *
2781                  * @example $("img").src("test2.jpg");
2782                  * @before <img src="test.jpg" title="my image"/>
2783                  * @result <img src="test2.jpg" title="my image"/>
2784                  *
2785                  * @name src
2786                  * @type jQuery
2787                  * @param String val Set the property to the specified value.
2788                  * @cat DOM/Attributes
2789                  */
2790                 src: null,
2791
2792                 /**
2793                  * Get the current rel of the first matched element.
2794                  *
2795                  * @example $("a").rel();
2796                  * @before <a href="test.html" rel="nofollow">my link</a>
2797                  * @result "nofollow"
2798                  *
2799                  * @name rel
2800                  * @type String
2801                  * @cat DOM/Attributes
2802                  */
2803
2804                 /**
2805                  * Set the rel of every matched element.
2806                  *
2807                  * @example $("a").rel("nofollow");
2808                  * @before <a href="test.html">my link</a>
2809                  * @result <a href="test.html" rel="nofollow">my link</a>
2810                  *
2811                  * @name rel
2812                  * @type jQuery
2813                  * @param String val Set the property to the specified value.
2814                  * @cat DOM/Attributes
2815                  */
2816                 rel: null
2817         },
2818
2819         axis: {
2820                 /**
2821                  * Get a set of elements containing the unique parents of the matched
2822                  * set of elements.
2823                  *
2824                  * @example $("p").parent()
2825                  * @before <div><p>Hello</p><p>Hello</p></div>
2826                  * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2827                  *
2828                  * @name parent
2829                  * @type jQuery
2830                  * @cat DOM/Traversing
2831                  */
2832
2833                 /**
2834                  * Get a set of elements containing the unique parents of the matched
2835                  * set of elements, and filtered by an expression.
2836                  *
2837                  * @example $("p").parent(".selected")
2838                  * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2839                  * @result [ <div class="selected"><p>Hello Again</p></div> ]
2840                  *
2841                  * @name parent
2842                  * @type jQuery
2843                  * @param String expr An expression to filter the parents with
2844                  * @cat DOM/Traversing
2845                  */
2846                 parent: "a.parentNode",
2847
2848                 /**
2849                  * Get a set of elements containing the unique ancestors of the matched
2850                  * set of elements (except for the root element).
2851                  *
2852                  * @example $("span").ancestors()
2853                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2854                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2855                  *
2856                  * @name ancestors
2857                  * @type jQuery
2858                  * @cat DOM/Traversing
2859                  */
2860
2861                 /**
2862                  * Get a set of elements containing the unique ancestors of the matched
2863                  * set of elements, and filtered by an expression.
2864                  *
2865                  * @example $("span").ancestors("p")
2866                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2867                  * @result [ <p><span>Hello</span></p> ]
2868                  *
2869                  * @name ancestors
2870                  * @type jQuery
2871                  * @param String expr An expression to filter the ancestors with
2872                  * @cat DOM/Traversing
2873                  */
2874                 ancestors: jQuery.parents,
2875
2876                 /**
2877                  * Get a set of elements containing the unique ancestors of the matched
2878                  * set of elements (except for the root element).
2879                  *
2880                  * @example $("span").ancestors()
2881                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2882                  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2883                  *
2884                  * @name parents
2885                  * @type jQuery
2886                  * @cat DOM/Traversing
2887                  */
2888
2889                 /**
2890                  * Get a set of elements containing the unique ancestors of the matched
2891                  * set of elements, and filtered by an expression.
2892                  *
2893                  * @example $("span").ancestors("p")
2894                  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2895                  * @result [ <p><span>Hello</span></p> ]
2896                  *
2897                  * @name parents
2898                  * @type jQuery
2899                  * @param String expr An expression to filter the ancestors with
2900                  * @cat DOM/Traversing
2901                  */
2902                 parents: jQuery.parents,
2903
2904                 /**
2905                  * Get a set of elements containing the unique next siblings of each of the
2906                  * matched set of elements.
2907                  *
2908                  * It only returns the very next sibling, not all next siblings.
2909                  *
2910                  * @example $("p").next()
2911                  * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2912                  * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2913                  *
2914                  * @name next
2915                  * @type jQuery
2916                  * @cat DOM/Traversing
2917                  */
2918
2919                 /**
2920                  * Get a set of elements containing the unique next siblings of each of the
2921                  * matched set of elements, and filtered by an expression.
2922                  *
2923                  * It only returns the very next sibling, not all next siblings.
2924                  *
2925                  * @example $("p").next(".selected")
2926                  * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2927                  * @result [ <p class="selected">Hello Again</p> ]
2928                  *
2929                  * @name next
2930                  * @type jQuery
2931                  * @param String expr An expression to filter the next Elements with
2932                  * @cat DOM/Traversing
2933                  */
2934                 next: "jQuery.nth(a,1,'nextSibling')",
2935
2936                 /**
2937                  * Get a set of elements containing the unique previous siblings of each of the
2938                  * matched set of elements.
2939                  *
2940                  * It only returns the immediately previous sibling, not all previous siblings.
2941                  *
2942                  * @example $("p").prev()
2943                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2944                  * @result [ <div><span>Hello Again</span></div> ]
2945                  *
2946                  * @name prev
2947                  * @type jQuery
2948                  * @cat DOM/Traversing
2949                  */
2950
2951                 /**
2952                  * Get a set of elements containing the unique previous siblings of each of the
2953                  * matched set of elements, and filtered by an expression.
2954                  *
2955                  * It only returns the immediately previous sibling, not all previous siblings.
2956                  *
2957                  * @example $("p").prev(".selected")
2958                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2959                  * @result [ <div><span>Hello</span></div> ]
2960                  *
2961                  * @name prev
2962                  * @type jQuery
2963                  * @param String expr An expression to filter the previous Elements with
2964                  * @cat DOM/Traversing
2965                  */
2966                 prev: "jQuery.nth(a,1,'previousSibling')",
2967
2968                 /**
2969                  * Get a set of elements containing all of the unique siblings of each of the
2970                  * matched set of elements.
2971                  *
2972                  * @example $("div").siblings()
2973                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2974                  * @result [ <p>Hello</p>, <p>And Again</p> ]
2975                  *
2976                  * @name siblings
2977                  * @type jQuery
2978                  * @cat DOM/Traversing
2979                  */
2980
2981                 /**
2982                  * Get a set of elements containing all of the unique siblings of each of the
2983                  * matched set of elements, and filtered by an expression.
2984                  *
2985                  * @example $("div").siblings(".selected")
2986                  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2987                  * @result [ <p class="selected">Hello Again</p> ]
2988                  *
2989                  * @name siblings
2990                  * @type jQuery
2991                  * @param String expr An expression to filter the sibling Elements with
2992                  * @cat DOM/Traversing
2993                  */
2994                 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
2995
2996                 /**
2997                  * Get a set of elements containing all of the unique children of each of the
2998                  * matched set of elements.
2999                  *
3000                  * @example $("div").children()
3001                  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3002                  * @result [ <span>Hello Again</span> ]
3003                  *
3004                  * @name children
3005                  * @type jQuery
3006                  * @cat DOM/Traversing
3007                  */
3008
3009                 /**
3010                  * Get a set of elements containing all of the unique children of each of the
3011                  * matched set of elements, and filtered by an expression.
3012                  *
3013                  * @example $("div").children(".selected")
3014                  * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3015                  * @result [ <p class="selected">Hello Again</p> ]
3016                  *
3017                  * @name children
3018                  * @type jQuery
3019                  * @param String expr An expression to filter the child Elements with
3020                  * @cat DOM/Traversing
3021                  */
3022                 children: "jQuery.sibling(a.firstChild)"
3023         },
3024
3025         each: {
3026
3027                 /**
3028                  * Remove an attribute from each of the matched elements.
3029                  *
3030                  * @example $("input").removeAttr("disabled")
3031                  * @before <input disabled="disabled"/>
3032                  * @result <input/>
3033                  *
3034                  * @name removeAttr
3035                  * @type jQuery
3036                  * @param String name The name of the attribute to remove.
3037                  * @cat DOM
3038                  */
3039                 removeAttr: function( key ) {
3040                         jQuery.attr( this, key, "" );
3041                         this.removeAttribute( key );
3042                 },
3043
3044                 /**
3045                  * Displays each of the set of matched elements if they are hidden.
3046                  *
3047                  * @example $("p").show()
3048                  * @before <p style="display: none">Hello</p>
3049                  * @result [ <p style="display: block">Hello</p> ]
3050                  *
3051                  * @name show
3052                  * @type jQuery
3053                  * @cat Effects
3054                  */
3055                 show: function(){
3056                         this.style.display = this.oldblock ? this.oldblock : "";
3057                         if ( jQuery.css(this,"display") == "none" )
3058                                 this.style.display = "block";
3059                 },
3060
3061                 /**
3062                  * Hides each of the set of matched elements if they are shown.
3063                  *
3064                  * @example $("p").hide()
3065                  * @before <p>Hello</p>
3066                  * @result [ <p style="display: none">Hello</p> ]
3067                  *
3068                  * var pass = true, div = $("div");
3069                  * div.hide().each(function(){
3070                  *   if ( this.style.display != "none" ) pass = false;
3071                  * });
3072                  * ok( pass, "Hide" );
3073                  *
3074                  * @name hide
3075                  * @type jQuery
3076                  * @cat Effects
3077                  */
3078                 hide: function(){
3079                         this.oldblock = this.oldblock || jQuery.css(this,"display");
3080                         if ( this.oldblock == "none" )
3081                                 this.oldblock = "block";
3082                         this.style.display = "none";
3083                 },
3084
3085                 /**
3086                  * Toggles each of the set of matched elements. If they are shown,
3087                  * toggle makes them hidden. If they are hidden, toggle
3088                  * makes them shown.
3089                  *
3090                  * @example $("p").toggle()
3091                  * @before <p>Hello</p><p style="display: none">Hello Again</p>
3092                  * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3093                  *
3094                  * @name toggle
3095                  * @type jQuery
3096                  * @cat Effects
3097                  */
3098                 toggle: function(){
3099                         jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3100                 },
3101
3102                 /**
3103                  * Adds the specified class to each of the set of matched elements.
3104                  *
3105                  * @example $("p").addClass("selected")
3106                  * @before <p>Hello</p>
3107                  * @result [ <p class="selected">Hello</p> ]
3108                  *
3109                  * @name addClass
3110                  * @type jQuery
3111                  * @param String class A CSS class to add to the elements
3112                  * @cat DOM
3113                  */
3114                 addClass: function(c){
3115                         jQuery.className.add(this,c);
3116                 },
3117
3118                 /**
3119                  * Removes the specified class from the set of matched elements.
3120                  *
3121                  * @example $("p").removeClass("selected")
3122                  * @before <p class="selected">Hello</p>
3123                  * @result [ <p>Hello</p> ]
3124                  *
3125                  * @name removeClass
3126                  * @type jQuery
3127                  * @param String class A CSS class to remove from the elements
3128                  * @cat DOM
3129                  */
3130                 removeClass: function(c){
3131                         jQuery.className.remove(this,c);
3132                 },
3133
3134                 /**
3135                  * Adds the specified class if it is not present, removes it if it is
3136                  * present.
3137                  *
3138                  * @example $("p").toggleClass("selected")
3139                  * @before <p>Hello</p><p class="selected">Hello Again</p>
3140                  * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3141                  *
3142                  * @name toggleClass
3143                  * @type jQuery
3144                  * @param String class A CSS class with which to toggle the elements
3145                  * @cat DOM
3146                  */
3147                 toggleClass: function( c ){
3148                         jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
3149                 },
3150
3151                 /**
3152                  * Removes all matched elements from the DOM. This does NOT remove them from the
3153                  * jQuery object, allowing you to use the matched elements further.
3154                  *
3155                  * @example $("p").remove();
3156                  * @before <p>Hello</p> how are <p>you?</p>
3157                  * @result how are
3158                  *
3159                  * @name remove
3160                  * @type jQuery
3161                  * @cat DOM/Manipulation
3162                  */
3163
3164                 /**
3165                  * Removes only elements (out of the list of matched elements) that match
3166                  * the specified jQuery expression. This does NOT remove them from the
3167                  * jQuery object, allowing you to use the matched elements further.
3168                  *
3169                  * @example $("p").remove(".hello");
3170                  * @before <p class="hello">Hello</p> how are <p>you?</p>
3171                  * @result how are <p>you?</p>
3172                  *
3173                  * @name remove
3174                  * @type jQuery
3175                  * @param String expr A jQuery expression to filter elements by.
3176                  * @cat DOM/Manipulation
3177                  */
3178                 remove: function(a){
3179                         if ( !a || jQuery.filter( a, [this] ).r )
3180                                 this.parentNode.removeChild( this );
3181                 },
3182
3183                 /**
3184                  * Removes all child nodes from the set of matched elements.
3185                  *
3186                  * @example $("p").empty()
3187                  * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3188                  * @result [ <p></p> ]
3189                  *
3190                  * @name empty
3191                  * @type jQuery
3192                  * @cat DOM/Manipulation
3193                  */
3194                 empty: function(){
3195                         while ( this.firstChild )
3196                                 this.removeChild( this.firstChild );
3197                 },
3198
3199                 /**
3200                  * Binds a handler to a particular event (like click) for each matched element.
3201                  * The event handler is passed an event object that you can use to prevent
3202                  * default behaviour. To stop both default action and event bubbling, your handler
3203                  * has to return false.
3204                  *
3205                  * @example $("p").bind( "click", function() {
3206                  *   alert( $(this).text() );
3207                  * } )
3208                  * @before <p>Hello</p>
3209                  * @result alert("Hello")
3210                  *
3211                  * @example $("form").bind( "submit", function() { return false; } )
3212                  * @desc Cancel a default action and prevent it from bubbling by returning false
3213                  * from your function.
3214                  *
3215                  * @example $("form").bind( "submit", function(event) {
3216                  *   event.preventDefault();
3217                  * } );
3218                  * @desc Cancel only the default action by using the preventDefault method.
3219                  *
3220                  *
3221                  * @example $("form").bind( "submit", function(event) {
3222                  *   event.stopPropagation();
3223                  * } )
3224                  * @desc Stop only an event from bubbling by using the stopPropagation method.
3225                  *
3226                  * @name bind
3227                  * @type jQuery
3228                  * @param String type An event type
3229                  * @param Function fn A function to bind to the event on each of the set of matched elements
3230                  * @cat Events
3231                  */
3232                 bind: function( type, fn ) {
3233                         jQuery.event.add( this, type, fn );
3234                 },
3235
3236                 /**
3237                  * The opposite of bind, removes a bound event from each of the matched
3238                  * elements. You must pass the identical function that was used in the original
3239                  * bind method.
3240                  *
3241                  * @example $("p").unbind( "click", function() { alert("Hello"); } )
3242                  * @before <p onclick="alert('Hello');">Hello</p>
3243                  * @result [ <p>Hello</p> ]
3244                  *
3245                  * @name unbind
3246                  * @type jQuery
3247                  * @param String type An event type
3248                  * @param Function fn A function to unbind from the event on each of the set of matched elements
3249                  * @cat Events
3250                  */
3251
3252                 /**
3253                  * Removes all bound events of a particular type from each of the matched
3254                  * elements.
3255                  *
3256                  * @example $("p").unbind( "click" )
3257                  * @before <p onclick="alert('Hello');">Hello</p>
3258                  * @result [ <p>Hello</p> ]
3259                  *
3260                  * @name unbind
3261                  * @type jQuery
3262                  * @param String type An event type
3263                  * @cat Events
3264                  */
3265
3266                 /**
3267                  * Removes all bound events from each of the matched elements.
3268                  *
3269                  * @example $("p").unbind()
3270                  * @before <p onclick="alert('Hello');">Hello</p>
3271                  * @result [ <p>Hello</p> ]
3272                  *
3273                  * @name unbind
3274                  * @type jQuery
3275                  * @cat Events
3276                  */
3277                 unbind: function( type, fn ) {
3278                         jQuery.event.remove( this, type, fn );
3279                 },
3280
3281                 /**
3282                  * Trigger a type of event on every matched element.
3283                  *
3284                  * @example $("p").trigger("click")
3285                  * @before <p click="alert('hello')">Hello</p>
3286                  * @result alert('hello')
3287                  *
3288                  * @name trigger
3289                  * @type jQuery
3290                  * @param String type An event type to trigger.
3291                  * @cat Events
3292                  */
3293                 trigger: function( type, data ) {
3294                         jQuery.event.trigger( type, data, this );
3295                 }
3296         }
3297 };
3298
3299 jQuery.init();