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