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