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