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