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