Fix for #921
[jquery.git] / src / jquery / jquery.js
1 /*
2  * jQuery @VERSION - New Wave Javascript
3  *
4  * Copyright (c) 2007 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  * @param String|Function|Element|Array<Element>|jQuery a selector
22  * @param jQuery|Element|Array<Element> c context
23  * @cat Core
24  */
25 var jQuery = function(a,c) {
26         // If the context is global, return a new object
27         if ( window == this )
28                 return new jQuery(a,c);
29
30         // Make sure that a selection was provided
31         a = a || document;
32         
33         // HANDLE: $(function)
34         // Shortcut for document ready
35         if ( jQuery.isFunction(a) )
36                 return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
37         
38         // Handle HTML strings
39         if ( typeof a  == "string" ) {
40                 // HANDLE: $(html) -> $(array)
41                 var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
42                 if ( m )
43                         a = jQuery.clean( [ m[1] ] );
44                 
45                 // HANDLE: $(expr)
46                 else
47                         return new jQuery( c ).find( a );
48         }
49         
50         return this.setArray(
51                 // HANDLE: $(array)
52                 a.constructor == Array && a ||
53
54                 // HANDLE: $(arraylike)
55                 // Watch for when an array-like object is passed as the selector
56                 (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
57
58                 // HANDLE: $(*)
59                 [ a ] );
60 };
61
62 // Map over the $ in case of overwrite
63 if ( typeof $ != "undefined" )
64         jQuery._$ = $;
65         
66 // Map the jQuery namespace to the '$' one
67 var $ = jQuery;
68
69 /**
70  * This function accepts a string containing a CSS or
71  * basic XPath selector which is then used to match a set of elements.
72  *
73  * The core functionality of jQuery centers around this function.
74  * Everything in jQuery is based upon this, or uses this in some way.
75  * The most basic use of this function is to pass in an expression
76  * (usually consisting of CSS or XPath), which then finds all matching
77  * elements.
78  *
79  * By default, $() looks for DOM elements within the context of the
80  * current HTML document.
81  *
82  * @example $("div > p")
83  * @desc Finds all p elements that are children of a div element.
84  * @before <p>one</p> <div><p>two</p></div> <p>three</p>
85  * @result [ <p>two</p> ]
86  *
87  * @example $("input:radio", document.forms[0])
88  * @desc Searches for all inputs of type radio within the first form in the document
89  *
90  * @example $("div", xml.responseXML)
91  * @desc This finds all div elements within the specified XML document.
92  *
93  * @name $
94  * @param String expr An expression to search with
95  * @param Element|jQuery context (optional) A DOM Element, Document or jQuery to use as context
96  * @cat Core
97  * @type jQuery
98  * @see $(Element)
99  * @see $(Element<Array>)
100  */
101  
102 /**
103  * Create DOM elements on-the-fly from the provided String of raw HTML.
104  *
105  * @example $("<div><p>Hello</p></div>").appendTo("#body")
106  * @desc Creates a div element (and all of its contents) dynamically, 
107  * and appends it to the element with the ID of body. Internally, an
108  * element is created and it's innerHTML property set to the given markup.
109  * It is therefore both quite flexible and limited. 
110  *
111  * @name $
112  * @param String html A string of HTML to create on the fly.
113  * @cat Core
114  * @type jQuery
115  * @see appendTo(String)
116  */
117
118 /**
119  * Wrap jQuery functionality around a single or multiple DOM Element(s).
120  *
121  * This function also accepts XML Documents and Window objects
122  * as valid arguments (even though they are not DOM Elements).
123  *
124  * @example $(document.body).background( "black" );
125  * @desc Sets the background color of the page to black.
126  *
127  * @example $( myForm.elements ).hide()
128  * @desc Hides all the input elements within a form
129  *
130  * @name $
131  * @param Element|Array<Element> elems DOM element(s) to be encapsulated by a jQuery object.
132  * @cat Core
133  * @type jQuery
134  */
135
136 /**
137  * A shorthand for $(document).ready(), allowing you to bind a function
138  * to be executed when the DOM document has finished loading. This function
139  * behaves just like $(document).ready(), in that it should be used to wrap
140  * all of the other $() operations on your page. While this function is,
141  * technically, chainable - there really isn't much use for chaining against it.
142  * You can have as many $(document).ready events on your page as you like.
143  *
144  * See ready(Function) for details about the ready event. 
145  * 
146  * @example $(function(){
147  *   // Document is ready
148  * });
149  * @desc Executes the function when the DOM is ready to be used.
150  *
151  * @example jQuery(function($) {
152  *   // Your code using failsafe $ alias here...
153  * });
154  * @desc Uses both the shortcut for $(document).ready() and the argument
155  * to write failsafe jQuery code using the $ alias, without relying on the
156  * global alias.
157  *
158  * @name $
159  * @param Function fn The function to execute when the DOM is ready.
160  * @cat Core
161  * @type jQuery
162  * @see ready(Function)
163  */
164
165 jQuery.fn = jQuery.prototype = {
166         /**
167          * The current version of jQuery.
168          *
169          * @private
170          * @property
171          * @name jquery
172          * @type String
173          * @cat Core
174          */
175         jquery: "@VERSION",
176
177         /**
178          * The number of elements currently matched.
179          *
180          * @example $("img").length;
181          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
182          * @result 2
183          *
184          * @property
185          * @name length
186          * @type Number
187          * @cat Core
188          */
189
190         /**
191          * The number of elements currently matched.
192          *
193          * @example $("img").size();
194          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
195          * @result 2
196          *
197          * @name size
198          * @type Number
199          * @cat Core
200          */
201         size: function() {
202                 return this.length;
203         },
204         
205         length: 0,
206
207         /**
208          * Access all matched elements. This serves as a backwards-compatible
209          * way of accessing all matched elements (other than the jQuery object
210          * itself, which is, in fact, an array of elements).
211          *
212          * @example $("img").get();
213          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
214          * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
215          * @desc Selects all images in the document and returns the DOM Elements as an Array
216          *
217          * @name get
218          * @type Array<Element>
219          * @cat Core
220          */
221
222         /**
223          * Access a single matched element. num is used to access the
224          * Nth element matched.
225          *
226          * @example $("img").get(0);
227          * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
228          * @result [ <img src="test1.jpg"/> ]
229          * @desc Selects all images in the document and returns the first one
230          *
231          * @name get
232          * @type Element
233          * @param Number num Access the element in the Nth position.
234          * @cat Core
235          */
236         get: function( num ) {
237                 return num == undefined ?
238
239                         // Return a 'clean' array
240                         jQuery.makeArray( this ) :
241
242                         // Return just the object
243                         this[num];
244         },
245         
246         /**
247          * Set the jQuery object to an array of elements, while maintaining
248          * the stack.
249          *
250          * @example $("img").pushStack([ document.body ]);
251          * @result $("img").pushStack() == [ document.body ]
252          *
253          * @private
254          * @name pushStack
255          * @type jQuery
256          * @param Elements elems An array of elements
257          * @cat Core
258          */
259         pushStack: function( a ) {
260                 var ret = jQuery(a);
261                 ret.prevObject = this;
262                 return ret;
263         },
264         
265         /**
266          * Set the jQuery object to an array of elements. This operation is
267          * completely destructive - be sure to use .pushStack() if you wish to maintain
268          * the jQuery stack.
269          *
270          * @example $("img").setArray([ document.body ]);
271          * @result $("img").setArray() == [ document.body ]
272          *
273          * @private
274          * @name setArray
275          * @type jQuery
276          * @param Elements elems An array of elements
277          * @cat Core
278          */
279         setArray: function( a ) {
280                 this.length = 0;
281                 [].push.apply( this, a );
282                 return this;
283         },
284
285         /**
286          * Execute a function within the context of every matched element.
287          * This means that every time the passed-in function is executed
288          * (which is once for every element matched) the 'this' keyword
289          * points to the specific element.
290          *
291          * Additionally, the function, when executed, is passed a single
292          * argument representing the position of the element in the matched
293          * set.
294          *
295          * @example $("img").each(function(i){
296          *   this.src = "test" + i + ".jpg";
297          * });
298          * @before <img/><img/>
299          * @result <img src="test0.jpg"/><img src="test1.jpg"/>
300          * @desc Iterates over two images and sets their src property
301          *
302          * @name each
303          * @type jQuery
304          * @param Function fn A function to execute
305          * @cat Core
306          */
307         each: function( fn, args ) {
308                 return jQuery.each( this, fn, args );
309         },
310
311         /**
312          * Searches every matched element for the object and returns
313          * the index of the element, if found, starting with zero. 
314          * Returns -1 if the object wasn't found.
315          *
316          * @example $("*").index( $('#foobar')[0] ) 
317          * @before <div id="foobar"><b></b><span id="foo"></span></div>
318          * @result 0
319          * @desc Returns the index for the element with ID foobar
320          *
321          * @example $("*").index( $('#foo')[0] ) 
322          * @before <div id="foobar"><b></b><span id="foo"></span></div>
323          * @result 2
324          * @desc Returns the index for the element with ID foo within another element
325          *
326          * @example $("*").index( $('#bar')[0] ) 
327          * @before <div id="foobar"><b></b><span id="foo"></span></div>
328          * @result -1
329          * @desc Returns -1, as there is no element with ID bar
330          *
331          * @name index
332          * @type Number
333          * @param Element subject Object to search for
334          * @cat Core
335          */
336         index: function( obj ) {
337                 var pos = -1;
338                 this.each(function(i){
339                         if ( this == obj ) pos = i;
340                 });
341                 return pos;
342         },
343
344         /**
345          * Access a property on the first matched element.
346          * This method makes it easy to retrieve a property value
347          * from the first matched element.
348          *
349          * @example $("img").attr("src");
350          * @before <img src="test.jpg"/>
351          * @result test.jpg
352          * @desc Returns the src attribute from the first image in the document.
353          *
354          * @name attr
355          * @type Object
356          * @param String name The name of the property to access.
357          * @cat DOM/Attributes
358          */
359
360         /**
361          * Set a key/value object as properties to all matched elements.
362          *
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          * @desc Sets src and alt attributes to all images.
370          *
371          * @name attr
372          * @type jQuery
373          * @param Map properties Key/value pairs to set as object properties.
374          * @cat DOM/Attributes
375          */
376
377         /**
378          * Set a single property to a value, on all matched elements.
379          *
380          * Can compute values provided as ${formula}, see second example.
381          *
382          * Note that you can't set the name property of input elements in IE.
383          * Use $(html) or .append(html) or .html(html) to create elements
384          * on the fly including the name property.
385          *
386          * @example $("img").attr("src","test.jpg");
387          * @before <img/>
388          * @result <img src="test.jpg"/>
389          * @desc Sets src attribute to all images.
390          *
391          * @example $("img").attr("title", "${this.src}");
392          * @before <img src="test.jpg" />
393          * @result <img src="test.jpg" title="test.jpg" />
394          * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
395          *
396          * @name attr
397          * @type jQuery
398          * @param String key The name of the property to set.
399          * @param Object value The value to set the property to.
400          * @cat DOM/Attributes
401          */
402          
403         /**
404          * Set a single property to a computed value, on all matched elements.
405          *
406          * Instead of a value, a function is provided, that computes the value.
407          *
408          * @example $("img").attr("title", function() { return this.src });
409          * @before <img src="test.jpg" />
410          * @result <img src="test.jpg" title="test.jpg" />
411          * @desc Sets title attribute from src attribute.
412          *
413          * @example $("img").attr("title", function(index) { return this.title + (i + 1); });
414          * @before <img title="pic" /><img title="pic" /><img title="pic" />
415          * @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
416          * @desc Enumerate title attribute.
417          *
418          * @name attr
419          * @type jQuery
420          * @param String key The name of the property to set.
421          * @param Function value A function returning the value to set.
422          *                Scope: Current element, argument: Index of current element
423          * @cat DOM/Attributes
424          */
425         attr: function( key, value, type ) {
426                 var obj = key;
427                 
428                 // Look for the case where we're accessing a style value
429                 if ( key.constructor == String )
430                         if ( value == undefined )
431                                 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
432                         else {
433                                 obj = {};
434                                 obj[ key ] = value;
435                         }
436                 
437                 // Check to see if we're setting style values
438                 return this.each(function(index){
439                         // Set all the styles
440                         for ( var prop in obj )
441                                 jQuery.attr(
442                                         type ? this.style : this,
443                                         prop, jQuery.prop(this, obj[prop], type, index, prop)
444                                 );
445                 });
446         },
447
448         /**
449          * Access a style property on the first matched element.
450          * This method makes it easy to retrieve a style property value
451          * from the first matched element.
452          *
453          * @example $("p").css("color");
454          * @before <p style="color:red;">Test Paragraph.</p>
455          * @result "red"
456          * @desc Retrieves the color style of the first paragraph
457          *
458          * @example $("p").css("font-weight");
459          * @before <p style="font-weight: bold;">Test Paragraph.</p>
460          * @result "bold"
461          * @desc Retrieves the font-weight style of the first paragraph.
462          *
463          * @name css
464          * @type String
465          * @param String name The name of the property to access.
466          * @cat CSS
467          */
468
469         /**
470          * Set a key/value object as style properties to all matched elements.
471          *
472          * This serves as the best way to set a large number of style properties
473          * on all matched elements.
474          *
475          * @example $("p").css({ color: "red", background: "blue" });
476          * @before <p>Test Paragraph.</p>
477          * @result <p style="color:red; background:blue;">Test Paragraph.</p>
478          * @desc Sets color and background styles to all p elements.
479          *
480          * @name css
481          * @type jQuery
482          * @param Map properties Key/value pairs to set as style properties.
483          * @cat CSS
484          */
485
486         /**
487          * Set a single style property to a value, on all matched elements.
488          * If a number is provided, it is automatically converted into a pixel value.
489          *
490          * @example $("p").css("color","red");
491          * @before <p>Test Paragraph.</p>
492          * @result <p style="color:red;">Test Paragraph.</p>
493          * @desc Changes the color of all paragraphs to red
494          *
495          * @example $("p").css("left",30);
496          * @before <p>Test Paragraph.</p>
497          * @result <p style="left:30px;">Test Paragraph.</p>
498          * @desc Changes the left of all paragraphs to "30px"
499          *
500          * @name css
501          * @type jQuery
502          * @param String key The name of the property to set.
503          * @param String|Number value The value to set the property to.
504          * @cat CSS
505          */
506         css: function( key, value ) {
507                 return this.attr( key, value, "curCSS" );
508         },
509
510         /**
511          * Get the text contents of all matched elements. The result is
512          * a string that contains the combined text contents of all matched
513          * elements. This method works on both HTML and XML documents.
514          *
515          * @example $("p").text();
516          * @before <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>
517          * @result Test Paragraph.Paraparagraph
518          * @desc Gets the concatenated text of all paragraphs
519          *
520          * @name text
521          * @type String
522          * @cat DOM/Attributes
523          */
524
525         /**
526          * Set the text contents of all matched elements.
527          *
528          * Similar to html(), but escapes HTML (replace "<" and ">" with their
529          * HTML entities).
530          *
531          * @example $("p").text("<b>Some</b> new text.");
532          * @before <p>Test Paragraph.</p>
533          * @result <p>&lt;b&gt;Some&lt;/b&gt; new text.</p>
534          * @desc Sets the text of all paragraphs.
535          *
536          * @example $("p").text("<b>Some</b> new text.", true);
537          * @before <p>Test Paragraph.</p>
538          * @result <p>Some new text.</p>
539          * @desc Sets the text of all paragraphs.
540          *
541          * @name text
542          * @type String
543          * @param String val The text value to set the contents of the element to.
544          * @cat DOM/Attributes
545          */
546         text: function(e) {
547                 if ( typeof e == "string" )
548                         return this.empty().append( document.createTextNode( e ) );
549
550                 var t = "";
551                 jQuery.each( e || this, function(){
552                         jQuery.each( this.childNodes, function(){
553                                 if ( this.nodeType != 8 )
554                                         t += this.nodeType != 1 ?
555                                                 this.nodeValue : jQuery.fn.text([ this ]);
556                         });
557                 });
558                 return t;
559         },
560
561         /**
562          * Wrap all matched elements with a structure of other elements.
563          * This wrapping process is most useful for injecting additional
564          * stucture into a document, without ruining the original semantic
565          * qualities of a document.
566          *
567          * This works by going through the first element
568          * provided (which is generated, on the fly, from the provided HTML)
569          * and finds the deepest ancestor element within its
570          * structure - it is that element that will en-wrap everything else.
571          *
572          * This does not work with elements that contain text. Any necessary text
573          * must be added after the wrapping is done.
574          *
575          * @example $("p").wrap("<div class='wrap'></div>");
576          * @before <p>Test Paragraph.</p>
577          * @result <div class='wrap'><p>Test Paragraph.</p></div>
578          * 
579          * @name wrap
580          * @type jQuery
581          * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
582          * @cat DOM/Manipulation
583          */
584
585         /**
586          * Wrap all matched elements with a structure of other elements.
587          * This wrapping process is most useful for injecting additional
588          * stucture into a document, without ruining the original semantic
589          * qualities of a document.
590          *
591          * This works by going through the first element
592          * provided and finding the deepest ancestor element within its
593          * structure - it is that element that will en-wrap everything else.
594          *
595          * This does not work with elements that contain text. Any necessary text
596          * must be added after the wrapping is done.
597          *
598          * @example $("p").wrap( document.getElementById('content') );
599          * @before <p>Test Paragraph.</p><div id="content"></div>
600          * @result <div id="content"><p>Test Paragraph.</p></div>
601          *
602          * @name wrap
603          * @type jQuery
604          * @param Element elem A DOM element that will be wrapped around the target.
605          * @cat DOM/Manipulation
606          */
607         wrap: function() {
608                 // The elements to wrap the target around
609                 var a = jQuery.clean(arguments);
610
611                 // Wrap each of the matched elements individually
612                 return this.each(function(){
613                         // Clone the structure that we're using to wrap
614                         var b = a[0].cloneNode(true);
615
616                         // Insert it before the element to be wrapped
617                         this.parentNode.insertBefore( b, this );
618
619                         // Find the deepest point in the wrap structure
620                         while ( b.firstChild )
621                                 b = b.firstChild;
622
623                         // Move the matched element to within the wrap structure
624                         b.appendChild( this );
625                 });
626         },
627
628         /**
629          * Append content to the inside of every matched element.
630          *
631          * This operation is similar to doing an appendChild to all the
632          * specified elements, adding them into the document.
633          *
634          * @example $("p").append("<b>Hello</b>");
635          * @before <p>I would like to say: </p>
636          * @result <p>I would like to say: <b>Hello</b></p>
637          * @desc Appends some HTML to all paragraphs.
638          *
639          * @example $("p").append( $("#foo")[0] );
640          * @before <p>I would like to say: </p><b id="foo">Hello</b>
641          * @result <p>I would like to say: <b id="foo">Hello</b></p>
642          * @desc Appends an Element to all paragraphs.
643          *
644          * @example $("p").append( $("b") );
645          * @before <p>I would like to say: </p><b>Hello</b>
646          * @result <p>I would like to say: <b>Hello</b></p>
647          * @desc Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
648          *
649          * @name append
650          * @type jQuery
651          * @param <Content> content Content to append to the target
652          * @cat DOM/Manipulation
653          * @see prepend(<Content>)
654          * @see before(<Content>)
655          * @see after(<Content>)
656          */
657         append: function() {
658                 return this.domManip(arguments, true, 1, function(a){
659                         this.appendChild( a );
660                 });
661         },
662
663         /**
664          * Prepend content to the inside of every matched element.
665          *
666          * This operation is the best way to insert elements
667          * inside, at the beginning, of all matched elements.
668          *
669          * @example $("p").prepend("<b>Hello</b>");
670          * @before <p>I would like to say: </p>
671          * @result <p><b>Hello</b>I would like to say: </p>
672          * @desc Prepends some HTML to all paragraphs.
673          *
674          * @example $("p").prepend( $("#foo")[0] );
675          * @before <p>I would like to say: </p><b id="foo">Hello</b>
676          * @result <p><b id="foo">Hello</b>I would like to say: </p>
677          * @desc Prepends an Element to all paragraphs.
678          *      
679          * @example $("p").prepend( $("b") );
680          * @before <p>I would like to say: </p><b>Hello</b>
681          * @result <p><b>Hello</b>I would like to say: </p>
682          * @desc Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
683          *
684          * @name prepend
685          * @type jQuery
686          * @param <Content> content Content to prepend to the target.
687          * @cat DOM/Manipulation
688          * @see append(<Content>)
689          * @see before(<Content>)
690          * @see after(<Content>)
691          */
692         prepend: function() {
693                 return this.domManip(arguments, true, -1, function(a){
694                         this.insertBefore( a, this.firstChild );
695                 });
696         },
697         
698         /**
699          * Insert content before each of the matched elements.
700          *
701          * @example $("p").before("<b>Hello</b>");
702          * @before <p>I would like to say: </p>
703          * @result <b>Hello</b><p>I would like to say: </p>
704          * @desc Inserts some HTML before all paragraphs.
705          *
706          * @example $("p").before( $("#foo")[0] );
707          * @before <p>I would like to say: </p><b id="foo">Hello</b>
708          * @result <b id="foo">Hello</b><p>I would like to say: </p>
709          * @desc Inserts an Element before all paragraphs.
710          *
711          * @example $("p").before( $("b") );
712          * @before <p>I would like to say: </p><b>Hello</b>
713          * @result <b>Hello</b><p>I would like to say: </p>
714          * @desc Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
715          *
716          * @name before
717          * @type jQuery
718          * @param <Content> content Content to insert before each target.
719          * @cat DOM/Manipulation
720          * @see append(<Content>)
721          * @see prepend(<Content>)
722          * @see after(<Content>)
723          */
724         before: function() {
725                 return this.domManip(arguments, false, 1, function(a){
726                         this.parentNode.insertBefore( a, this );
727                 });
728         },
729
730         /**
731          * Insert content after each of the matched elements.
732          *
733          * @example $("p").after("<b>Hello</b>");
734          * @before <p>I would like to say: </p>
735          * @result <p>I would like to say: </p><b>Hello</b>
736          * @desc Inserts some HTML after all paragraphs.
737          *
738          * @example $("p").after( $("#foo")[0] );
739          * @before <b id="foo">Hello</b><p>I would like to say: </p>
740          * @result <p>I would like to say: </p><b id="foo">Hello</b>
741          * @desc Inserts an Element after all paragraphs.
742          *
743          * @example $("p").after( $("b") );
744          * @before <b>Hello</b><p>I would like to say: </p>
745          * @result <p>I would like to say: </p><b>Hello</b>
746          * @desc Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
747          *
748          * @name after
749          * @type jQuery
750          * @param <Content> content Content to insert after each target.
751          * @cat DOM/Manipulation
752          * @see append(<Content>)
753          * @see prepend(<Content>)
754          * @see before(<Content>)
755          */
756         after: function() {
757                 return this.domManip(arguments, false, -1, function(a){
758                         this.parentNode.insertBefore( a, this.nextSibling );
759                 });
760         },
761
762         /**
763          * End the most recent 'destructive' operation, reverting the list of matched elements
764          * back to its previous state. After an end operation, the list of matched elements will
765          * revert to the last state of matched elements.
766          *
767          * If there was no destructive operation before, an empty set is returned.
768          *
769          * @example $("p").find("span").end();
770          * @before <p><span>Hello</span>, how are you?</p>
771          * @result [ <p>...</p> ]
772          * @desc Selects all paragraphs, finds span elements inside these, and reverts the
773          * selection back to the paragraphs.
774          *
775          * @name end
776          * @type jQuery
777          * @cat DOM/Traversing
778          */
779         end: function() {
780                 return this.prevObject || jQuery([]);
781         },
782
783         /**
784          * Searches for all elements that match the specified expression.
785          
786          * This method is a good way to find additional descendant
787          * elements with which to process.
788          *
789          * All searching is done using a jQuery expression. The expression can be
790          * written using CSS 1-3 Selector syntax, or basic XPath.
791          *
792          * @example $("p").find("span");
793          * @before <p><span>Hello</span>, how are you?</p>
794          * @result [ <span>Hello</span> ]
795          * @desc Starts with all paragraphs and searches for descendant span
796          * elements, same as $("p span")
797          *
798          * @name find
799          * @type jQuery
800          * @param String expr An expression to search with.
801          * @cat DOM/Traversing
802          */
803         find: function(t) {
804                 return this.pushStack( jQuery.map( this, function(a){
805                         return jQuery.find(t,a);
806                 }), t );
807         },
808
809         /**
810          * Clone matched DOM Elements and select the clones. 
811          *
812          * This is useful for moving copies of the elements to another
813          * location in the DOM.
814          *
815          * @example $("b").clone().prependTo("p");
816          * @before <b>Hello</b><p>, how are you?</p>
817          * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
818          * @desc Clones all b elements (and selects the clones) and prepends them to all paragraphs.
819          *
820          * @name clone
821          * @type jQuery
822          * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
823          * @cat DOM/Manipulation
824          */
825         clone: function(deep) {
826                 return this.pushStack( jQuery.map( this, function(a){
827                         var a = a.cloneNode( deep != undefined ? deep : true );
828                         a.$events = null; // drop $events expando to avoid firing incorrect events
829                         return a;
830                 }) );
831         },
832
833         /**
834          * Removes all elements from the set of matched elements that do not
835          * match the specified expression(s). This method is used to narrow down
836          * the results of a search.
837          *
838          * Provide a comma-separated list of expressions to apply multiple filters at once.
839          *
840          * @example $("p").filter(".selected")
841          * @before <p class="selected">Hello</p><p>How are you?</p>
842          * @result [ <p class="selected">Hello</p> ]
843          * @desc Selects all paragraphs and removes those without a class "selected".
844          *
845          * @example $("p").filter(".selected, :first")
846          * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
847          * @result [ <p>Hello</p>, <p class="selected">And Again</p> ]
848          * @desc Selects all paragraphs and removes those without class "selected" and being the first one.
849          *
850          * @name filter
851          * @type jQuery
852          * @param String expression Expression(s) to search with.
853          * @cat DOM/Traversing
854          */
855          
856         /**
857          * Removes all elements from the set of matched elements that do not
858          * pass the specified filter. This method is used to narrow down
859          * the results of a search.
860          *
861          * @example $("p").filter(function(index) {
862          *   return $("ol", this).length == 0;
863          * })
864          * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p>
865          * @result [ <p>How are you?</p> ]
866          * @desc Remove all elements that have a child ol element
867          *
868          * @name filter
869          * @type jQuery
870          * @param Function filter A function to use for filtering
871          * @cat DOM/Traversing
872          */
873         filter: function(t) {
874                 return this.pushStack(
875                         jQuery.isFunction( t ) &&
876                         jQuery.grep(this, function(el, index){
877                                 return t.apply(el, [index])
878                         }) ||
879
880                         jQuery.multiFilter(t,this) );
881         },
882
883         /**
884          * Removes the specified Element from the set of matched elements. This
885          * method is used to remove a single Element from a jQuery object.
886          *
887          * @example $("p").not( $("#selected")[0] )
888          * @before <p>Hello</p><p id="selected">Hello Again</p>
889          * @result [ <p>Hello</p> ]
890          * @desc Removes the element with the ID "selected" from the set of all paragraphs.
891          *
892          * @name not
893          * @type jQuery
894          * @param Element el An element to remove from the set
895          * @cat DOM/Traversing
896          */
897
898         /**
899          * Removes elements matching the specified expression from the set
900          * of matched elements. This method is used to remove one or more
901          * elements from a jQuery object.
902          *
903          * @example $("p").not("#selected")
904          * @before <p>Hello</p><p id="selected">Hello Again</p>
905          * @result [ <p>Hello</p> ]
906          * @desc Removes the element with the ID "selected" from the set of all paragraphs.
907          *
908          * @name not
909          * @type jQuery
910          * @param String expr An expression with which to remove matching elements
911          * @cat DOM/Traversing
912          */
913
914         /**
915          * Removes any elements inside the array of elements 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( $("div p.selected") )
920          * @before <div><p>Hello</p><p class="selected">Hello Again</p></div>
921          * @result [ <p>Hello</p> ]
922          * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs.
923          *
924          * @name not
925          * @type jQuery
926          * @param jQuery elems A set of elements to remove from the jQuery set of matched elements.
927          * @cat DOM/Traversing
928          */
929         not: function(t) {
930                 return this.pushStack(
931                         t.constructor == String &&
932                         jQuery.multiFilter(t, this, true) ||
933
934                         jQuery.grep(this, function(a) {
935                                 return ( t.constructor == Array || t.jquery )
936                                         ? jQuery.inArray( a, t ) < 0
937                                         : a != t;
938                         })
939                 );
940         },
941
942         /**
943          * Adds more elements, matched by the given expression,
944          * to the set of matched elements.
945          *
946          * @example $("p").add("span")
947          * @before <p>Hello</p><span>Hello Again</span>
948          * @result [ <p>Hello</p>, <span>Hello Again</span> ]
949          *
950          * @name add
951          * @type jQuery
952          * @param String expr An expression whose matched elements are added
953          * @cat DOM/Traversing
954          */
955          
956         /**
957          * Adds more elements, created on the fly, to the set of
958          * matched elements.
959          *
960          * @example $("p").add("<span>Again</span>")
961          * @before <p>Hello</p>
962          * @result [ <p>Hello</p>, <span>Again</span> ]
963          *
964          * @name add
965          * @type jQuery
966          * @param String html A string of HTML to create on the fly.
967          * @cat DOM/Traversing
968          */
969
970         /**
971          * Adds one or more Elements to the set of matched elements.
972          *
973          * @example $("p").add( document.getElementById("a") )
974          * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
975          * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
976          *
977          * @example $("p").add( document.forms[0].elements )
978          * @before <p>Hello</p><p><form><input/><button/></form>
979          * @result [ <p>Hello</p>, <input/>, <button/> ]
980          *
981          * @name add
982          * @type jQuery
983          * @param Element|Array<Element> elements One or more Elements to add
984          * @cat DOM/Traversing
985          */
986         add: function(t) {
987                 return this.pushStack( jQuery.merge(
988                         this.get(),
989                         t.constructor == String ?
990                                 jQuery(t).get() :
991                                 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
992                                         t : [t] )
993                 );
994         },
995
996         /**
997          * Checks the current selection against an expression and returns true,
998          * if at least one element of the selection fits the given expression.
999          *
1000          * Does return false, if no element fits or the expression is not valid.
1001          *
1002          * filter(String) is used internally, therefore all rules that apply there
1003          * apply here, too.
1004          *
1005          * @example $("input[@type='checkbox']").parent().is("form")
1006          * @before <form><input type="checkbox" /></form>
1007          * @result true
1008          * @desc Returns true, because the parent of the input is a form element
1009          * 
1010          * @example $("input[@type='checkbox']").parent().is("form")
1011          * @before <form><p><input type="checkbox" /></p></form>
1012          * @result false
1013          * @desc Returns false, because the parent of the input is a p element
1014          *
1015          * @name is
1016          * @type Boolean
1017          * @param String expr The expression with which to filter
1018          * @cat DOM/Traversing
1019          */
1020         is: function(expr) {
1021                 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1022         },
1023         
1024         /**
1025          * Get the current value of the first matched element.
1026          *
1027          * @example $("input").val();
1028          * @before <input type="text" value="some text"/>
1029          * @result "some text"
1030          *
1031          * @name val
1032          * @type String
1033          * @cat DOM/Attributes
1034          */
1035         
1036         /**
1037          * Set the value of every matched element.
1038          *
1039          * @example $("input").val("test");
1040          * @before <input type="text" value="some text"/>
1041          * @result <input type="text" value="test"/>
1042          *
1043          * @name val
1044          * @type jQuery
1045          * @param String val Set the property to the specified value.
1046          * @cat DOM/Attributes
1047          */
1048         val: function( val ) {
1049                 return val == undefined ?
1050                         ( this.length ? this[0].value : null ) :
1051                         this.attr( "value", val );
1052         },
1053         
1054         /**
1055          * Get the html contents of the first matched element.
1056          * This property is not available on XML documents.
1057          *
1058          * @example $("div").html();
1059          * @before <div><input/></div>
1060          * @result <input/>
1061          *
1062          * @name html
1063          * @type String
1064          * @cat DOM/Attributes
1065          */
1066         
1067         /**
1068          * Set the html contents of every matched element.
1069          * This property is not available on XML documents.
1070          *
1071          * @example $("div").html("<b>new stuff</b>");
1072          * @before <div><input/></div>
1073          * @result <div><b>new stuff</b></div>
1074          *
1075          * @name html
1076          * @type jQuery
1077          * @param String val Set the html contents to the specified value.
1078          * @cat DOM/Attributes
1079          */
1080         html: function( val ) {
1081                 return val == undefined ?
1082                         ( this.length ? this[0].innerHTML : null ) :
1083                         this.empty().append( val );
1084         },
1085         
1086         /**
1087          * @private
1088          * @name domManip
1089          * @param Array args
1090          * @param Boolean table Insert TBODY in TABLEs if one is not found.
1091          * @param Number dir If dir<0, process args in reverse order.
1092          * @param Function fn The function doing the DOM manipulation.
1093          * @type jQuery
1094          * @cat Core
1095          */
1096         domManip: function(args, table, dir, fn){
1097                 var clone = this.length > 1; 
1098                 var a = jQuery.clean(args);
1099                 if ( dir < 0 )
1100                         a.reverse();
1101
1102                 return this.each(function(){
1103                         var obj = this;
1104
1105                         if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
1106                                 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1107
1108                         jQuery.each( a, function(){
1109                                 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
1110                         });
1111
1112                 });
1113         }
1114 };
1115
1116 /**
1117  * Extends the jQuery object itself. Can be used to add functions into
1118  * the jQuery namespace and to add plugin methods (plugins).
1119  * 
1120  * @example jQuery.fn.extend({
1121  *   check: function() {
1122  *     return this.each(function() { this.checked = true; });
1123  *   },
1124  *   uncheck: function() {
1125  *     return this.each(function() { this.checked = false; });
1126  *   }
1127  * });
1128  * $("input[@type=checkbox]").check();
1129  * $("input[@type=radio]").uncheck();
1130  * @desc Adds two plugin methods.
1131  *
1132  * @example jQuery.extend({
1133  *   min: function(a, b) { return a < b ? a : b; },
1134  *   max: function(a, b) { return a > b ? a : b; }
1135  * });
1136  * @desc Adds two functions into the jQuery namespace
1137  *
1138  * @name $.extend
1139  * @param Object prop The object that will be merged into the jQuery object
1140  * @type Object
1141  * @cat Core
1142  */
1143
1144 /**
1145  * Extend one object with one or more others, returning the original,
1146  * modified, object. This is a great utility for simple inheritance.
1147  * 
1148  * @example var settings = { validate: false, limit: 5, name: "foo" };
1149  * var options = { validate: true, name: "bar" };
1150  * jQuery.extend(settings, options);
1151  * @result settings == { validate: true, limit: 5, name: "bar" }
1152  * @desc Merge settings and options, modifying settings
1153  *
1154  * @example var defaults = { validate: false, limit: 5, name: "foo" };
1155  * var options = { validate: true, name: "bar" };
1156  * var settings = jQuery.extend({}, defaults, options);
1157  * @result settings == { validate: true, limit: 5, name: "bar" }
1158  * @desc Merge defaults and options, without modifying the defaults
1159  *
1160  * @name $.extend
1161  * @param Object target The object to extend
1162  * @param Object prop1 The object that will be merged into the first.
1163  * @param Object propN (optional) More objects to merge into the first
1164  * @type Object
1165  * @cat JavaScript
1166  */
1167 jQuery.extend = jQuery.fn.extend = function() {
1168         // copy reference to target object
1169         var target = arguments[0],
1170                 a = 1;
1171
1172         // extend jQuery itself if only one argument is passed
1173         if ( arguments.length == 1 ) {
1174                 target = this;
1175                 a = 0;
1176         }
1177         var prop;
1178         while (prop = arguments[a++])
1179                 // Extend the base object
1180                 for ( var i in prop ) target[i] = prop[i];
1181
1182         // Return the modified object
1183         return target;
1184 };
1185
1186 jQuery.extend({
1187         /**
1188          * Run this function to give control of the $ variable back
1189          * to whichever library first implemented it. This helps to make 
1190          * sure that jQuery doesn't conflict with the $ object
1191          * of other libraries.
1192          *
1193          * By using this function, you will only be able to access jQuery
1194          * using the 'jQuery' variable. For example, where you used to do
1195          * $("div p"), you now must do jQuery("div p").
1196          *
1197          * @example jQuery.noConflict();
1198          * // Do something with jQuery
1199          * jQuery("div p").hide();
1200          * // Do something with another library's $()
1201          * $("content").style.display = 'none';
1202          * @desc Maps the original object that was referenced by $ back to $
1203          *
1204          * @example jQuery.noConflict();
1205          * (function($) { 
1206          *   $(function() {
1207          *     // more code using $ as alias to jQuery
1208          *   });
1209          * })(jQuery);
1210          * // other code using $ as an alias to the other library
1211          * @desc Reverts the $ alias and then creates and executes a
1212          * function to provide the $ as a jQuery alias inside the functions
1213          * scope. Inside the function the original $ object is not available.
1214          * This works well for most plugins that don't rely on any other library.
1215          * 
1216          *
1217          * @name $.noConflict
1218          * @type undefined
1219          * @cat Core 
1220          */
1221         noConflict: function() {
1222                 if ( jQuery._$ )
1223                         $ = jQuery._$;
1224                 return jQuery;
1225         },
1226
1227         // This may seem like some crazy code, but trust me when I say that this
1228         // is the only cross-browser way to do this. --John
1229         isFunction: function( fn ) {
1230                 return !!fn && typeof fn != "string" &&
1231                         typeof fn[0] == "undefined" && /function/i.test( fn + "" );
1232         },
1233         
1234         // check if an element is in a XML document
1235         isXMLDoc: function(elem) {
1236                 return elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
1237         },
1238
1239         nodeName: function( elem, name ) {
1240                 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
1241         },
1242
1243         /**
1244          * A generic iterator function, which can be used to seemlessly
1245          * iterate over both objects and arrays. This function is not the same
1246          * as $().each() - which is used to iterate, exclusively, over a jQuery
1247          * object. This function can be used to iterate over anything.
1248          *
1249          * The callback has two arguments:the key (objects) or index (arrays) as first
1250          * the first, and the value as the second.
1251          *
1252          * @example $.each( [0,1,2], function(i, n){
1253          *   alert( "Item #" + i + ": " + n );
1254          * });
1255          * @desc This is an example of iterating over the items in an array,
1256          * accessing both the current item and its index.
1257          *
1258          * @example $.each( { name: "John", lang: "JS" }, function(i, n){
1259          *   alert( "Name: " + i + ", Value: " + n );
1260          * });
1261          *
1262          * @desc This is an example of iterating over the properties in an
1263          * Object, accessing both the current item and its key.
1264          *
1265          * @name $.each
1266          * @param Object obj The object, or array, to iterate over.
1267          * @param Function fn The function that will be executed on every object.
1268          * @type Object
1269          * @cat JavaScript
1270          */
1271         // args is for internal usage only
1272         each: function( obj, fn, args ) {
1273                 if ( obj.length == undefined )
1274                         for ( var i in obj )
1275                                 fn.apply( obj[i], args || [i, obj[i]] );
1276                 else
1277                         for ( var i = 0, ol = obj.length; i < ol; i++ )
1278                                 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1279                 return obj;
1280         },
1281         
1282         prop: function(elem, value, type, index, prop){
1283                         // Handle executable functions
1284                         if ( jQuery.isFunction( value ) )
1285                                 value = value.call( elem, [index] );
1286                                 
1287                         // exclude the following css properties to add px
1288                         var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
1289
1290                         // Handle passing in a number to a CSS property
1291                         return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
1292                                 value + "px" :
1293                                 value;
1294         },
1295
1296         className: {
1297                 // internal only, use addClass("class")
1298                 add: function( elem, c ){
1299                         jQuery.each( c.split(/\s+/), function(i, cur){
1300                                 if ( !jQuery.className.has( elem.className, cur ) )
1301                                         elem.className += ( elem.className ? " " : "" ) + cur;
1302                         });
1303                 },
1304
1305                 // internal only, use removeClass("class")
1306                 remove: function( elem, c ){
1307                         elem.className = c ?
1308                                 jQuery.grep( elem.className.split(/\s+/), function(cur){
1309                                         return !jQuery.className.has( c, cur ); 
1310                                 }).join(" ") : "";
1311                 },
1312
1313                 // internal only, use is(".class")
1314                 has: function( t, c ) {
1315                         t = t.className || t;
1316                         return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
1317                 }
1318         },
1319
1320         /**
1321          * Swap in/out style options.
1322          * @private
1323          */
1324         swap: function(e,o,f) {
1325                 for ( var i in o ) {
1326                         e.style["old"+i] = e.style[i];
1327                         e.style[i] = o[i];
1328                 }
1329                 f.apply( e, [] );
1330                 for ( var i in o )
1331                         e.style[i] = e.style["old"+i];
1332         },
1333
1334         css: function(e,p) {
1335                 if ( p == "height" || p == "width" ) {
1336                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1337
1338                         jQuery.each( d, function(){
1339                                 old["padding" + this] = 0;
1340                                 old["border" + this + "Width"] = 0;
1341                         });
1342
1343                         jQuery.swap( e, old, function() {
1344                                 if (jQuery.css(e,"display") != "none") {
1345                                         oHeight = e.offsetHeight;
1346                                         oWidth = e.offsetWidth;
1347                                 } else {
1348                                         e = jQuery(e.cloneNode(true))
1349                                                 .find(":radio").removeAttr("checked").end()
1350                                                 .css({
1351                                                         visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1352                                                 }).appendTo(e.parentNode)[0];
1353
1354                                         var parPos = jQuery.css(e.parentNode,"position");
1355                                         if ( parPos == "" || parPos == "static" )
1356                                                 e.parentNode.style.position = "relative";
1357
1358                                         oHeight = e.clientHeight;
1359                                         oWidth = e.clientWidth;
1360
1361                                         if ( parPos == "" || parPos == "static" )
1362                                                 e.parentNode.style.position = "static";
1363
1364                                         e.parentNode.removeChild(e);
1365                                 }
1366                         });
1367
1368                         return p == "height" ? oHeight : oWidth;
1369                 }
1370
1371                 return jQuery.curCSS( e, p );
1372         },
1373
1374         curCSS: function(elem, prop, force) {
1375                 var ret;
1376                 
1377                 if (prop == "opacity" && jQuery.browser.msie)
1378                         return jQuery.attr(elem.style, "opacity");
1379                         
1380                 if (prop == "float" || prop == "cssFloat")
1381                     prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1382
1383                 if (!force && elem.style[prop])
1384                         ret = elem.style[prop];
1385
1386                 else if (document.defaultView && document.defaultView.getComputedStyle) {
1387
1388                         if (prop == "cssFloat" || prop == "styleFloat")
1389                                 prop = "float";
1390
1391                         prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1392                         var cur = document.defaultView.getComputedStyle(elem, null);
1393
1394                         if ( cur )
1395                                 ret = cur.getPropertyValue(prop);
1396                         else if ( prop == "display" )
1397                                 ret = "none";
1398                         else
1399                                 jQuery.swap(elem, { display: "block" }, function() {
1400                                     var c = document.defaultView.getComputedStyle(this, "");
1401                                     ret = c && c.getPropertyValue(prop) || "";
1402                                 });
1403
1404                 } else if (elem.currentStyle) {
1405
1406                         var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1407                         ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1408                         
1409                 }
1410
1411                 return ret;
1412         },
1413         
1414         clean: function(a) {
1415                 var r = [];
1416
1417                 jQuery.each( a, function(i,arg){
1418                         if ( !arg ) return;
1419
1420                         if ( arg.constructor == Number )
1421                                 arg = arg.toString();
1422                         
1423                          // Convert html string into DOM nodes
1424                         if ( typeof arg == "string" ) {
1425                                 // Trim whitespace, otherwise indexOf won't work as expected
1426                                 var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
1427
1428                                 var wrap =
1429                                          // option or optgroup
1430                                         !s.indexOf("<opt") &&
1431                                         [1, "<select>", "</select>"] ||
1432                                         
1433                                         (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
1434                                         [1, "<table>", "</table>"] ||
1435                                         
1436                                         !s.indexOf("<tr") &&
1437                                         [2, "<table><tbody>", "</tbody></table>"] ||
1438                                         
1439                                         // <thead> matched above
1440                                         (!s.indexOf("<td") || !s.indexOf("<th")) &&
1441                                         [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
1442                                         
1443                                         [0,"",""];
1444
1445                                 // Go to html and back, then peel off extra wrappers
1446                                 div.innerHTML = wrap[1] + s + wrap[2];
1447                                 
1448                                 // Move to the right depth
1449                                 while ( wrap[0]-- )
1450                                         div = div.firstChild;
1451                                 
1452                                 // Remove IE's autoinserted <tbody> from table fragments
1453                                 if ( jQuery.browser.msie ) {
1454                                         
1455                                         // String was a <table>, *may* have spurious <tbody>
1456                                         if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 ) 
1457                                                 tb = div.firstChild && div.firstChild.childNodes;
1458                                                 
1459                                         // String was a bare <thead> or <tfoot>
1460                                         else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1461                                                 tb = div.childNodes;
1462
1463                                         for ( var n = tb.length-1; n >= 0 ; --n )
1464                                                 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
1465                                                         tb[n].parentNode.removeChild(tb[n]);
1466                                         
1467                                 }
1468                                 
1469                                 arg = div.childNodes;
1470                         }
1471
1472                         if ( arg.length === 0 )
1473                                 return;
1474                         
1475                         if ( arg[0] == undefined )
1476                                 r.push( arg );
1477                         else
1478                                 r = jQuery.merge( r, arg );
1479
1480                 });
1481
1482                 return r;
1483         },
1484         
1485         attr: function(elem, name, value){
1486                 var fix = jQuery.isXMLDoc(elem) ? {} : {
1487                         "for": "htmlFor",
1488                         "class": "className",
1489                         "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1490                         cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1491                         innerHTML: "innerHTML",
1492                         className: "className",
1493                         value: "value",
1494                         disabled: "disabled",
1495                         checked: "checked",
1496                         readonly: "readOnly",
1497                         selected: "selected"
1498                 };
1499                 
1500                 // IE actually uses filters for opacity ... elem is actually elem.style
1501                 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1502                         // IE has trouble with opacity if it does not have layout
1503                         // Force it by setting the zoom level
1504                         elem.zoom = 1; 
1505
1506                         // Set the alpha filter to set the opacity
1507                         return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1508                                 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1509
1510                 } else if ( name == "opacity" && jQuery.browser.msie )
1511                         return elem.filter ? 
1512                                 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1513                 
1514                 // Mozilla doesn't play well with opacity 1
1515                 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1516                         value = 0.9999;
1517                         
1518
1519                 // Certain attributes only work when accessed via the old DOM 0 way
1520                 if ( fix[name] ) {
1521                         if ( value != undefined ) elem[fix[name]] = value;
1522                         return elem[fix[name]];
1523
1524                 } else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
1525                         return elem.getAttributeNode(name).nodeValue;
1526
1527                 // IE elem.getAttribute passes even for style
1528                 else if ( elem.tagName ) {
1529                         if ( value != undefined ) elem.setAttribute( name, value );
1530                         if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) ) 
1531                                 return elem.getAttribute( name, 2 );
1532                         return elem.getAttribute( name );
1533
1534                 // elem is actually elem.style ... set the style
1535                 } else {
1536                         name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1537                         if ( value != undefined ) elem[name] = value;
1538                         return elem[name];
1539                 }
1540         },
1541         
1542         /**
1543          * Remove the whitespace from the beginning and end of a string.
1544          *
1545          * @example $.trim("  hello, how are you?  ");
1546          * @result "hello, how are you?"
1547          *
1548          * @name $.trim
1549          * @type String
1550          * @param String str The string to trim.
1551          * @cat JavaScript
1552          */
1553         trim: function(t){
1554                 return t.replace(/^\s+|\s+$/g, "");
1555         },
1556
1557         makeArray: function( a ) {
1558                 var r = [];
1559
1560                 if ( a.constructor != Array )
1561                         for ( var i = 0, al = a.length; i < al; i++ )
1562                                 r.push( a[i] );
1563                 else
1564                         r = a.slice( 0 );
1565
1566                 return r;
1567         },
1568
1569         inArray: function( b, a ) {
1570                 for ( var i = 0, al = a.length; i < al; i++ )
1571                         if ( a[i] == b )
1572                                 return i;
1573                 return -1;
1574         },
1575
1576         /**
1577          * Merge two arrays together, removing all duplicates.
1578          *
1579          * The result is the altered first argument with
1580          * the unique elements from the second array added.
1581          *
1582          * @example $.merge( [0,1,2], [2,3,4] )
1583          * @result [0,1,2,3,4]
1584          * @desc Merges two arrays, removing the duplicate 2
1585          *
1586          * @example var array = [3,2,1];
1587          * $.merge( array, [4,3,2] )
1588          * @result array == [3,2,1,4]
1589          * @desc Merges two arrays, removing the duplicates 3 and 2
1590          *
1591          * @name $.merge
1592          * @type Array
1593          * @param Array first The first array to merge, the unique elements of second added.
1594          * @param Array second The second array to merge into the first, unaltered.
1595          * @cat JavaScript
1596          */
1597         merge: function(first, second) {
1598                 var r = [].slice.call( first, 0 );
1599
1600                 // Now check for duplicates between the two arrays
1601                 // and only add the unique items
1602                 for ( var i = 0, sl = second.length; i < sl; i++ )
1603                         // Check for duplicates
1604                         if ( jQuery.inArray( second[i], r ) == -1 )
1605                                 // The item is unique, add it
1606                                 first.push( second[i] );
1607
1608                 return first;
1609         },
1610
1611         /**
1612          * Filter items out of an array, by using a filter function.
1613          *
1614          * The specified function will be passed two arguments: The
1615          * current array item and the index of the item in the array. The
1616          * function must return 'true' to keep the item in the array, 
1617          * false to remove it.
1618          *
1619          * @example $.grep( [0,1,2], function(i){
1620          *   return i > 0;
1621          * });
1622          * @result [1, 2]
1623          *
1624          * @name $.grep
1625          * @type Array
1626          * @param Array array The Array to find items in.
1627          * @param Function fn The function to process each item against.
1628          * @param Boolean inv Invert the selection - select the opposite of the function.
1629          * @cat JavaScript
1630          */
1631         grep: function(elems, fn, inv) {
1632                 // If a string is passed in for the function, make a function
1633                 // for it (a handy shortcut)
1634                 if ( typeof fn == "string" )
1635                         fn = new Function("a","i","return " + fn);
1636
1637                 var result = [];
1638
1639                 // Go through the array, only saving the items
1640                 // that pass the validator function
1641                 for ( var i = 0, el = elems.length; i < el; i++ )
1642                         if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1643                                 result.push( elems[i] );
1644
1645                 return result;
1646         },
1647
1648         /**
1649          * Translate all items in an array to another array of items.
1650          *
1651          * The translation function that is provided to this method is 
1652          * called for each item in the array and is passed one argument: 
1653          * The item to be translated.
1654          *
1655          * The function can then return the translated value, 'null'
1656          * (to remove the item), or  an array of values - which will
1657          * be flattened into the full array.
1658          *
1659          * @example $.map( [0,1,2], function(i){
1660          *   return i + 4;
1661          * });
1662          * @result [4, 5, 6]
1663          * @desc Maps the original array to a new one and adds 4 to each value.
1664          *
1665          * @example $.map( [0,1,2], function(i){
1666          *   return i > 0 ? i + 1 : null;
1667          * });
1668          * @result [2, 3]
1669          * @desc Maps the original array to a new one and adds 1 to each
1670          * value if it is bigger then zero, otherwise it's removed-
1671          * 
1672          * @example $.map( [0,1,2], function(i){
1673          *   return [ i, i + 1 ];
1674          * });
1675          * @result [0, 1, 1, 2, 2, 3]
1676          * @desc Maps the original array to a new one, each element is added
1677          * with it's original value and the value plus one.
1678          *
1679          * @name $.map
1680          * @type Array
1681          * @param Array array The Array to translate.
1682          * @param Function fn The function to process each item against.
1683          * @cat JavaScript
1684          */
1685         map: function(elems, fn) {
1686                 // If a string is passed in for the function, make a function
1687                 // for it (a handy shortcut)
1688                 if ( typeof fn == "string" )
1689                         fn = new Function("a","return " + fn);
1690
1691                 var result = [], r = [];
1692
1693                 // Go through the array, translating each of the items to their
1694                 // new value (or values).
1695                 for ( var i = 0, el = elems.length; i < el; i++ ) {
1696                         var val = fn(elems[i],i);
1697
1698                         if ( val !== null && val != undefined ) {
1699                                 if ( val.constructor != Array ) val = [val];
1700                                 result = result.concat( val );
1701                         }
1702                 }
1703
1704                 var r = result.length ? [ result[0] ] : [];
1705
1706                 check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
1707                         for ( var j = 0; j < i; j++ )
1708                                 if ( result[i] == r[j] )
1709                                         continue check;
1710
1711                         r.push( result[i] );
1712                 }
1713
1714                 return r;
1715         }
1716 });
1717
1718 /**
1719  * Contains flags for the useragent, read from navigator.userAgent.
1720  * Available flags are: safari, opera, msie, mozilla
1721  *
1722  * This property is available before the DOM is ready, therefore you can
1723  * use it to add ready events only for certain browsers.
1724  *
1725  * There are situations where object detections is not reliable enough, in that
1726  * cases it makes sense to use browser detection. Simply try to avoid both!
1727  *
1728  * A combination of browser and object detection yields quite reliable results.
1729  *
1730  * @example $.browser.msie
1731  * @desc Returns true if the current useragent is some version of microsoft's internet explorer
1732  *
1733  * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
1734  * @desc Alerts "this is safari!" only for safari browsers
1735  *
1736  * @property
1737  * @name $.browser
1738  * @type Boolean
1739  * @cat JavaScript
1740  */
1741  
1742 /*
1743  * Whether the W3C compliant box model is being used.
1744  *
1745  * @property
1746  * @name $.boxModel
1747  * @type Boolean
1748  * @cat JavaScript
1749  */
1750 new function() {
1751         var b = navigator.userAgent.toLowerCase();
1752
1753         // Figure out what browser is being used
1754         jQuery.browser = {
1755                 safari: /webkit/.test(b),
1756                 opera: /opera/.test(b),
1757                 msie: /msie/.test(b) && !/opera/.test(b),
1758                 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1759         };
1760
1761         // Check to see if the W3C box model is being used
1762         jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1763 };
1764
1765 /**
1766  * Get a set of elements containing the unique parents of the matched
1767  * set of elements.
1768  *
1769  * Can be filtered with an optional expressions.
1770  *
1771  * @example $("p").parent()
1772  * @before <div><p>Hello</p><p>Hello</p></div>
1773  * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1774  * @desc Find the parent element of each paragraph.
1775  *
1776  * @example $("p").parent(".selected")
1777  * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1778  * @result [ <div class="selected"><p>Hello Again</p></div> ]
1779  * @desc Find the parent element of each paragraph with a class "selected".
1780  *
1781  * @name parent
1782  * @type jQuery
1783  * @param String expr (optional) An expression to filter the parents with
1784  * @cat DOM/Traversing
1785  */
1786
1787 /**
1788  * Get a set of elements containing the unique ancestors of the matched
1789  * set of elements (except for the root element).
1790  *
1791  * Can be filtered with an optional expressions.
1792  *
1793  * @example $("span").parents()
1794  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1795  * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1796  * @desc Find all parent elements of each span.
1797  *
1798  * @example $("span").parents("p")
1799  * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1800  * @result [ <p><span>Hello</span></p> ]
1801  * @desc Find all parent elements of each span that is a paragraph.
1802  *
1803  * @name parents
1804  * @type jQuery
1805  * @param String expr (optional) An expression to filter the ancestors with
1806  * @cat DOM/Traversing
1807  */
1808
1809 /**
1810  * Get a set of elements containing the unique next siblings of each of the
1811  * matched set of elements.
1812  *
1813  * It only returns the very next sibling, not all next siblings.
1814  *
1815  * Can be filtered with an optional expressions.
1816  *
1817  * @example $("p").next()
1818  * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
1819  * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
1820  * @desc Find the very next sibling of each paragraph.
1821  *
1822  * @example $("p").next(".selected")
1823  * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
1824  * @result [ <p class="selected">Hello Again</p> ]
1825  * @desc Find the very next sibling of each paragraph that has a class "selected".
1826  *
1827  * @name next
1828  * @type jQuery
1829  * @param String expr (optional) An expression to filter the next Elements with
1830  * @cat DOM/Traversing
1831  */
1832
1833 /**
1834  * Get a set of elements containing the unique previous siblings of each of the
1835  * matched set of elements.
1836  *
1837  * Can be filtered with an optional expressions.
1838  *
1839  * It only returns the immediately previous sibling, not all previous siblings.
1840  *
1841  * @example $("p").prev()
1842  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1843  * @result [ <div><span>Hello Again</span></div> ]
1844  * @desc Find the very previous sibling of each paragraph.
1845  *
1846  * @example $("p").prev(".selected")
1847  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1848  * @result [ <div><span>Hello</span></div> ]
1849  * @desc Find the very previous sibling of each paragraph that has a class "selected".
1850  *
1851  * @name prev
1852  * @type jQuery
1853  * @param String expr (optional) An expression to filter the previous Elements with
1854  * @cat DOM/Traversing
1855  */
1856
1857 /**
1858  * Get a set of elements containing all of the unique siblings of each of the
1859  * matched set of elements.
1860  *
1861  * Can be filtered with an optional expressions.
1862  *
1863  * @example $("div").siblings()
1864  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1865  * @result [ <p>Hello</p>, <p>And Again</p> ]
1866  * @desc Find all siblings of each div.
1867  *
1868  * @example $("div").siblings(".selected")
1869  * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
1870  * @result [ <p class="selected">Hello Again</p> ]
1871  * @desc Find all siblings with a class "selected" of each div.
1872  *
1873  * @name siblings
1874  * @type jQuery
1875  * @param String expr (optional) An expression to filter the sibling Elements with
1876  * @cat DOM/Traversing
1877  */
1878
1879 /**
1880  * Get a set of elements containing all of the unique children of each of the
1881  * matched set of elements.
1882  *
1883  * Can be filtered with an optional expressions.
1884  *
1885  * @example $("div").children()
1886  * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
1887  * @result [ <span>Hello Again</span> ]
1888  * @desc Find all children of each div.
1889  *
1890  * @example $("div").children(".selected")
1891  * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
1892  * @result [ <p class="selected">Hello Again</p> ]
1893  * @desc Find all children with a class "selected" of each div.
1894  *
1895  * @name children
1896  * @type jQuery
1897  * @param String expr (optional) An expression to filter the child Elements with
1898  * @cat DOM/Traversing
1899  */
1900 jQuery.each({
1901         parent: "a.parentNode",
1902         parents: "jQuery.parents(a)",
1903         next: "jQuery.nth(a,2,'nextSibling')",
1904         prev: "jQuery.nth(a,2,'previousSibling')",
1905         siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
1906         children: "jQuery.sibling(a.firstChild)"
1907 }, function(i,n){
1908         jQuery.fn[ i ] = function(a) {
1909                 var ret = jQuery.map(this,n);
1910                 if ( a && typeof a == "string" )
1911                         ret = jQuery.multiFilter(a,ret);
1912                 return this.pushStack( ret );
1913         };
1914 });
1915
1916 /**
1917  * Append all of the matched elements to another, specified, set of elements.
1918  * This operation is, essentially, the reverse of doing a regular
1919  * $(A).append(B), in that instead of appending B to A, you're appending
1920  * A to B.
1921  *
1922  * @example $("p").appendTo("#foo");
1923  * @before <p>I would like to say: </p><div id="foo"></div>
1924  * @result <div id="foo"><p>I would like to say: </p></div>
1925  * @desc Appends all paragraphs to the element with the ID "foo"
1926  *
1927  * @name appendTo
1928  * @type jQuery
1929  * @param <Content> content Content to append to the selected element to.
1930  * @cat DOM/Manipulation
1931  * @see append(<Content>)
1932  */
1933
1934 /**
1935  * Prepend all of the matched elements to another, specified, set of elements.
1936  * This operation is, essentially, the reverse of doing a regular
1937  * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1938  * A to B.
1939  *
1940  * @example $("p").prependTo("#foo");
1941  * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1942  * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1943  * @desc Prepends all paragraphs to the element with the ID "foo"
1944  *
1945  * @name prependTo
1946  * @type jQuery
1947  * @param <Content> content Content to prepend to the selected element to.
1948  * @cat DOM/Manipulation
1949  * @see prepend(<Content>)
1950  */
1951
1952 /**
1953  * Insert all of the matched elements before another, specified, set of elements.
1954  * This operation is, essentially, the reverse of doing a regular
1955  * $(A).before(B), in that instead of inserting B before A, you're inserting
1956  * A before B.
1957  *
1958  * @example $("p").insertBefore("#foo");
1959  * @before <div id="foo">Hello</div><p>I would like to say: </p>
1960  * @result <p>I would like to say: </p><div id="foo">Hello</div>
1961  * @desc Same as $("#foo").before("p")
1962  *
1963  * @name insertBefore
1964  * @type jQuery
1965  * @param <Content> content Content to insert the selected element before.
1966  * @cat DOM/Manipulation
1967  * @see before(<Content>)
1968  */
1969
1970 /**
1971  * Insert all of the matched elements after another, specified, set of elements.
1972  * This operation is, essentially, the reverse of doing a regular
1973  * $(A).after(B), in that instead of inserting B after A, you're inserting
1974  * A after B.
1975  *
1976  * @example $("p").insertAfter("#foo");
1977  * @before <p>I would like to say: </p><div id="foo">Hello</div>
1978  * @result <div id="foo">Hello</div><p>I would like to say: </p>
1979  * @desc Same as $("#foo").after("p")
1980  *
1981  * @name insertAfter
1982  * @type jQuery
1983  * @param <Content> content Content to insert the selected element after.
1984  * @cat DOM/Manipulation
1985  * @see after(<Content>)
1986  */
1987
1988 jQuery.each({
1989         appendTo: "append",
1990         prependTo: "prepend",
1991         insertBefore: "before",
1992         insertAfter: "after"
1993 }, function(i,n){
1994         jQuery.fn[ i ] = function(){
1995                 var a = arguments;
1996                 return this.each(function(){
1997                         for ( var j = 0, al = a.length; j < al; j++ )
1998                                 jQuery(a[j])[n]( this );
1999                 });
2000         };
2001 });
2002
2003 /**
2004  * Remove an attribute from each of the matched elements.
2005  *
2006  * @example $("input").removeAttr("disabled")
2007  * @before <input disabled="disabled"/>
2008  * @result <input/>
2009  *
2010  * @name removeAttr
2011  * @type jQuery
2012  * @param String name The name of the attribute to remove.
2013  * @cat DOM/Attributes
2014  */
2015
2016 /**
2017  * Adds the specified class(es) to each of the set of matched elements.
2018  *
2019  * @example $("p").addClass("selected")
2020  * @before <p>Hello</p>
2021  * @result [ <p class="selected">Hello</p> ]
2022  *
2023  * @example $("p").addClass("selected highlight")
2024  * @before <p>Hello</p>
2025  * @result [ <p class="selected highlight">Hello</p> ]
2026  *
2027  * @name addClass
2028  * @type jQuery
2029  * @param String class One or more CSS classes to add to the elements
2030  * @cat DOM/Attributes
2031  * @see removeClass(String)
2032  */
2033
2034 /**
2035  * Removes all or the specified class(es) from the set of matched elements.
2036  *
2037  * @example $("p").removeClass()
2038  * @before <p class="selected">Hello</p>
2039  * @result [ <p>Hello</p> ]
2040  *
2041  * @example $("p").removeClass("selected")
2042  * @before <p class="selected first">Hello</p>
2043  * @result [ <p class="first">Hello</p> ]
2044  *
2045  * @example $("p").removeClass("selected highlight")
2046  * @before <p class="highlight selected first">Hello</p>
2047  * @result [ <p class="first">Hello</p> ]
2048  *
2049  * @name removeClass
2050  * @type jQuery
2051  * @param String class (optional) One or more CSS classes to remove from the elements
2052  * @cat DOM/Attributes
2053  * @see addClass(String)
2054  */
2055
2056 /**
2057  * Adds the specified class if it is not present, removes it if it is
2058  * present.
2059  *
2060  * @example $("p").toggleClass("selected")
2061  * @before <p>Hello</p><p class="selected">Hello Again</p>
2062  * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2063  *
2064  * @name toggleClass
2065  * @type jQuery
2066  * @param String class A CSS class with which to toggle the elements
2067  * @cat DOM/Attributes
2068  */
2069
2070 /**
2071  * Removes all matched elements from the DOM. This does NOT remove them from the
2072  * jQuery object, allowing you to use the matched elements further.
2073  *
2074  * Can be filtered with an optional expressions.
2075  *
2076  * @example $("p").remove();
2077  * @before <p>Hello</p> how are <p>you?</p>
2078  * @result how are
2079  *
2080  * @example $("p").remove(".hello");
2081  * @before <p class="hello">Hello</p> how are <p>you?</p>
2082  * @result how are <p>you?</p>
2083  *
2084  * @name remove
2085  * @type jQuery
2086  * @param String expr (optional) A jQuery expression to filter elements by.
2087  * @cat DOM/Manipulation
2088  */
2089
2090 /**
2091  * Removes all child nodes from the set of matched elements.
2092  *
2093  * @example $("p").empty()
2094  * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2095  * @result [ <p></p> ]
2096  *
2097  * @name empty
2098  * @type jQuery
2099  * @cat DOM/Manipulation
2100  */
2101
2102 jQuery.each( {
2103         removeAttr: function( key ) {
2104                 jQuery.attr( this, key, "" );
2105                 this.removeAttribute( key );
2106         },
2107         addClass: function(c){
2108                 jQuery.className.add(this,c);
2109         },
2110         removeClass: function(c){
2111                 jQuery.className.remove(this,c);
2112         },
2113         toggleClass: function( c ){
2114                 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
2115         },
2116         remove: function(a){
2117                 if ( !a || jQuery.filter( a, [this] ).r.length )
2118                         this.parentNode.removeChild( this );
2119         },
2120         empty: function() {
2121                 while ( this.firstChild )
2122                         this.removeChild( this.firstChild );
2123         }
2124 }, function(i,n){
2125         jQuery.fn[ i ] = function() {
2126                 return this.each( n, arguments );
2127         };
2128 });
2129
2130 /**
2131  * Reduce the set of matched elements to a single element.
2132  * The position of the element in the set of matched elements
2133  * starts at 0 and goes to length - 1.
2134  *
2135  * @example $("p").eq(1)
2136  * @before <p>This is just a test.</p><p>So is this</p>
2137  * @result [ <p>So is this</p> ]
2138  *
2139  * @name eq
2140  * @type jQuery
2141  * @param Number pos The index of the element that you wish to limit to.
2142  * @cat Core
2143  */
2144
2145 /**
2146  * Reduce the set of matched elements to all elements before a given position.
2147  * The position of the element in the set of matched elements
2148  * starts at 0 and goes to length - 1.
2149  *
2150  * @example $("p").lt(1)
2151  * @before <p>This is just a test.</p><p>So is this</p>
2152  * @result [ <p>This is just a test.</p> ]
2153  *
2154  * @name lt
2155  * @type jQuery
2156  * @param Number pos Reduce the set to all elements below this position.
2157  * @cat Core
2158  */
2159
2160 /**
2161  * Reduce the set of matched elements to all elements after a given position.
2162  * The position of the element in the set of matched elements
2163  * starts at 0 and goes to length - 1.
2164  *
2165  * @example $("p").gt(0)
2166  * @before <p>This is just a test.</p><p>So is this</p>
2167  * @result [ <p>So is this</p> ]
2168  *
2169  * @name gt
2170  * @type jQuery
2171  * @param Number pos Reduce the set to all elements after this position.
2172  * @cat Core
2173  */
2174
2175 /**
2176  * Filter the set of elements to those that contain the specified text.
2177  *
2178  * @example $("p").contains("test")
2179  * @before <p>This is just a test.</p><p>So is this</p>
2180  * @result [ <p>This is just a test.</p> ]
2181  *
2182  * @name contains
2183  * @type jQuery
2184  * @param String str The string that will be contained within the text of an element.
2185  * @cat DOM/Traversing
2186  */
2187 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
2188         jQuery.fn[ n ] = function(num,fn) {
2189                 return this.filter( ":" + n + "(" + num + ")", fn );
2190         };
2191 });
2192
2193 /**
2194  * Get the current computed, pixel, width of the first matched element.
2195  *
2196  * @example $("p").width();
2197  * @before <p>This is just a test.</p>
2198  * @result 300
2199  *
2200  * @name width
2201  * @type String
2202  * @cat CSS
2203  */
2204
2205 /**
2206  * Set the CSS width of every matched element. If no explicit unit
2207  * was specified (like 'em' or '%') then "px" is added to the width.
2208  *
2209  * @example $("p").width(20);
2210  * @before <p>This is just a test.</p>
2211  * @result <p style="width:20px;">This is just a test.</p>
2212  *
2213  * @example $("p").width("20em");
2214  * @before <p>This is just a test.</p>
2215  * @result <p style="width:20em;">This is just a test.</p>
2216  *
2217  * @name width
2218  * @type jQuery
2219  * @param String|Number val Set the CSS property to the specified value.
2220  * @cat CSS
2221  */
2222  
2223 /**
2224  * Get the current computed, pixel, height of the first matched element.
2225  *
2226  * @example $("p").height();
2227  * @before <p>This is just a test.</p>
2228  * @result 300
2229  *
2230  * @name height
2231  * @type String
2232  * @cat CSS
2233  */
2234
2235 /**
2236  * Set the CSS width of every matched element. If no explicit unit
2237  * was specified (like 'em' or '%') then "px" is added to the width.
2238  *
2239  * @example $("p").height(20);
2240  * @before <p>This is just a test.</p>
2241  * @result <p style="height:20px;">This is just a test.</p>
2242  *
2243  * @example $("p").height("20em");
2244  * @before <p>This is just a test.</p>
2245  * @result <p style="height:20em;">This is just a test.</p>
2246  *
2247  * @name height
2248  * @type jQuery
2249  * @param String|Number val Set the CSS property to the specified value.
2250  * @cat CSS
2251  */
2252
2253 jQuery.each( [ "height", "width" ], function(i,n){
2254         jQuery.fn[ n ] = function(h) {
2255                 return h == undefined ?
2256                         ( this.length ? jQuery.css( this[0], n ) : null ) :
2257                         this.css( n, h.constructor == String ? h : h + "px" );
2258         };
2259 });