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