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