Added the new jQuery.support object and removed all uses of jQuery.browser from withi...
[jquery.git] / src / core.js
1 /*
2  * jQuery @VERSION - New Wave Javascript
3  *
4  * Copyright (c) 2008 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 // Map over jQuery in case of overwrite
13 var _jQuery = window.jQuery,
14 // Map over the $ in case of overwrite
15         _$ = window.$;
16
17 var jQuery = window.jQuery = window.$ = function( selector, context ) {
18         // The jQuery object is actually just the init constructor 'enhanced'
19         return new jQuery.fn.init( selector, context );
20 };
21
22 // A simple way to check for HTML strings or ID strings
23 // (both of which we optimize for)
24 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
25
26 // Is it a simple selector
27         isSimple = /^.[^:#\[\.]*$/,
28
29 // Will speed up references to undefined, and allows munging its name.
30         undefined;
31
32 jQuery.fn = jQuery.prototype = {
33         init: function( selector, context ) {
34                 // Make sure that a selection was provided
35                 selector = selector || document;
36
37                 // Handle $(DOMElement)
38                 if ( selector.nodeType ) {
39                         this[0] = selector;
40                         this.length = 1;
41                         this.context = selector;
42                         return this;
43                 }
44                 // Handle HTML strings
45                 if ( typeof selector === "string" ) {
46                         // Are we dealing with HTML string or an ID?
47                         var match = quickExpr.exec( selector );
48
49                         // Verify a match, and that no context was specified for #id
50                         if ( match && (match[1] || !context) ) {
51
52                                 // HANDLE: $(html) -> $(array)
53                                 if ( match[1] )
54                                         selector = jQuery.clean( [ match[1] ], context );
55
56                                 // HANDLE: $("#id")
57                                 else {
58                                         var elem = document.getElementById( match[3] );
59
60                                         // Make sure an element was located
61                                         if ( elem ){
62                                                 // Handle the case where IE and Opera return items
63                                                 // by name instead of ID
64                                                 if ( elem.id != match[3] )
65                                                         return jQuery().find( selector );
66
67                                                 // Otherwise, we inject the element directly into the jQuery object
68                                                 var ret = jQuery( elem );
69                                                 ret.context = document;
70                                                 ret.selector = selector;
71                                                 return ret;
72                                         }
73                                         selector = [];
74                                 }
75
76                         // HANDLE: $(expr, [context])
77                         // (which is just equivalent to: $(content).find(expr)
78                         } else
79                                 return jQuery( context ).find( selector );
80
81                 // HANDLE: $(function)
82                 // Shortcut for document ready
83                 } else if ( jQuery.isFunction( selector ) )
84                         return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
85
86                 return this.setArray(jQuery.makeArray(selector));
87         },
88
89         // Start with an empty selector
90         selector: "",
91
92         // The current version of jQuery being used
93         jquery: "@VERSION",
94
95         // The number of elements contained in the matched element set
96         size: function() {
97                 return this.length;
98         },
99
100         // Get the Nth element in the matched element set OR
101         // Get the whole matched element set as a clean array
102         get: function( num ) {
103                 return num === undefined ?
104
105                         // Return a 'clean' array
106                         jQuery.makeArray( this ) :
107
108                         // Return just the object
109                         this[ num ];
110         },
111
112         // Take an array of elements and push it onto the stack
113         // (returning the new matched element set)
114         pushStack: function( elems, name, selector ) {
115                 // Build a new jQuery matched element set
116                 var ret = jQuery( elems );
117
118                 // Add the old object onto the stack (as a reference)
119                 ret.prevObject = this;
120
121                 ret.context = this.context;
122
123                 if ( name === "find" )
124                         ret.selector = this.selector + (this.selector ? " " : "") + selector;
125                 else if ( name )
126                         ret.selector = this.selector + "." + name + "(" + selector + ")";
127
128                 // Return the newly-formed element set
129                 return ret;
130         },
131
132         // Force the current matched set of elements to become
133         // the specified array of elements (destroying the stack in the process)
134         // You should use pushStack() in order to do this, but maintain the stack
135         setArray: function( elems ) {
136                 // Resetting the length to 0, then using the native Array push
137                 // is a super-fast way to populate an object with array-like properties
138                 this.length = 0;
139                 Array.prototype.push.apply( this, elems );
140
141                 return this;
142         },
143
144         // Execute a callback for every element in the matched set.
145         // (You can seed the arguments with an array of args, but this is
146         // only used internally.)
147         each: function( callback, args ) {
148                 return jQuery.each( this, callback, args );
149         },
150
151         // Determine the position of an element within
152         // the matched set of elements
153         index: function( elem ) {
154                 var ret = -1;
155
156                 // Locate the position of the desired element
157                 return jQuery.inArray(
158                         // If it receives a jQuery object, the first element is used
159                         elem && elem.jquery ? elem[0] : elem
160                 , this );
161         },
162
163         attr: function( name, value, type ) {
164                 var options = name;
165
166                 // Look for the case where we're accessing a style value
167                 if ( typeof name === "string" )
168                         if ( value === undefined )
169                                 return this[0] && jQuery[ type || "attr" ]( this[0], name );
170
171                         else {
172                                 options = {};
173                                 options[ name ] = value;
174                         }
175
176                 // Check to see if we're setting style values
177                 return this.each(function(i){
178                         // Set all the styles
179                         for ( name in options )
180                                 jQuery.attr(
181                                         type ?
182                                                 this.style :
183                                                 this,
184                                         name, jQuery.prop( this, options[ name ], type, i, name )
185                                 );
186                 });
187         },
188
189         css: function( key, value ) {
190                 // ignore negative width and height values
191                 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
192                         value = undefined;
193                 return this.attr( key, value, "curCSS" );
194         },
195
196         text: function( text ) {
197                 if ( typeof text !== "object" && text != null )
198                         return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
199
200                 var ret = "";
201
202                 jQuery.each( text || this, function(){
203                         jQuery.each( this.childNodes, function(){
204                                 if ( this.nodeType != 8 )
205                                         ret += this.nodeType != 1 ?
206                                                 this.nodeValue :
207                                                 jQuery.fn.text( [ this ] );
208                         });
209                 });
210
211                 return ret;
212         },
213
214         wrapAll: function( html ) {
215                 if ( this[0] )
216                         // The elements to wrap the target around
217                         jQuery( html, this[0].ownerDocument )
218                                 .clone()
219                                 .insertBefore( this[0] )
220                                 .map(function(){
221                                         var elem = this;
222
223                                         while ( elem.firstChild )
224                                                 elem = elem.firstChild;
225
226                                         return elem;
227                                 })
228                                 .append(this);
229
230                 return this;
231         },
232
233         wrapInner: function( html ) {
234                 return this.each(function(){
235                         jQuery( this ).contents().wrapAll( html );
236                 });
237         },
238
239         wrap: function( html ) {
240                 return this.each(function(){
241                         jQuery( this ).wrapAll( html );
242                 });
243         },
244
245         append: function() {
246                 return this.domManip(arguments, true, function(elem){
247                         if (this.nodeType == 1)
248                                 this.appendChild( elem );
249                 });
250         },
251
252         prepend: function() {
253                 return this.domManip(arguments, true, function(elem){
254                         if (this.nodeType == 1)
255                                 this.insertBefore( elem, this.firstChild );
256                 });
257         },
258
259         before: function() {
260                 return this.domManip(arguments, false, function(elem){
261                         this.parentNode.insertBefore( elem, this );
262                 });
263         },
264
265         after: function() {
266                 return this.domManip(arguments, false, function(elem){
267                         this.parentNode.insertBefore( elem, this.nextSibling );
268                 });
269         },
270
271         end: function() {
272                 return this.prevObject || jQuery( [] );
273         },
274
275         find: function( selector ) {
276                 var elems = jQuery.map(this, function(elem){
277                         return jQuery.find( selector, elem );
278                 });
279
280                 return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
281                         jQuery.unique( elems ) :
282                         elems, "find", selector );
283         },
284
285         clone: function( events ) {
286                 // Do the clone
287                 var ret = this.map(function(){
288                         if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
289                                 // IE copies events bound via attachEvent when
290                                 // using cloneNode. Calling detachEvent on the
291                                 // clone will also remove the events from the orignal
292                                 // In order to get around this, we use innerHTML.
293                                 // Unfortunately, this means some modifications to
294                                 // attributes in IE that are actually only stored
295                                 // as properties will not be copied (such as the
296                                 // the name attribute on an input).
297                                 var clone = this.cloneNode(true),
298                                         container = document.createElement("div");
299                                 container.appendChild(clone);
300                                 return jQuery.clean([container.innerHTML])[0];
301                         } else
302                                 return this.cloneNode(true);
303                 });
304
305                 // Need to set the expando to null on the cloned set if it exists
306                 // removeData doesn't work here, IE removes it from the original as well
307                 // this is primarily for IE but the data expando shouldn't be copied over in any browser
308                 var clone = ret.find("*").andSelf().each(function(){
309                         if ( this[ expando ] !== undefined )
310                                 this[ expando ] = null;
311                 });
312
313                 // Copy the events from the original to the clone
314                 if ( events === true )
315                         this.find("*").andSelf().each(function(i){
316                                 if (this.nodeType == 3)
317                                         return;
318                                 var events = jQuery.data( this, "events" );
319
320                                 for ( var type in events )
321                                         for ( var handler in events[ type ] )
322                                                 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
323                         });
324
325                 // Return the cloned set
326                 return ret;
327         },
328
329         filter: function( selector ) {
330                 return this.pushStack(
331                         jQuery.isFunction( selector ) &&
332                         jQuery.grep(this, function(elem, i){
333                                 return selector.call( elem, i );
334                         }) ||
335
336                         jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
337                                 return elem.nodeType === 1;
338                         }) ), "filter", selector );
339         },
340
341         not: function( selector ) {
342                 if ( typeof selector === "string" )
343                         // test special case where just one selector is passed in
344                         if ( isSimple.test( selector ) )
345                                 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
346                         else
347                                 selector = jQuery.multiFilter( selector, this );
348
349                 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
350                 return this.filter(function() {
351                         return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
352                 });
353         },
354
355         add: function( selector ) {
356                 return this.pushStack( jQuery.unique( jQuery.merge(
357                         this.get(),
358                         typeof selector === "string" ?
359                                 jQuery( selector ) :
360                                 jQuery.makeArray( selector )
361                 )));
362         },
363
364         is: function( selector ) {
365                 return !!selector && jQuery.multiFilter( selector, this ).length > 0;
366         },
367
368         hasClass: function( selector ) {
369                 return !!selector && this.is( "." + selector );
370         },
371
372         val: function( value ) {
373                 if ( value === undefined ) {                    
374                         var elem = this[0];
375
376                         if ( elem ) {
377                                 if( jQuery.nodeName( elem, 'option' ) )
378                                         return (elem.attributes.value || {}).specified ? elem.value : elem.text;
379                                 
380                                 // We need to handle select boxes special
381                                 if ( jQuery.nodeName( elem, "select" ) ) {
382                                         var index = elem.selectedIndex,
383                                                 values = [],
384                                                 options = elem.options,
385                                                 one = elem.type == "select-one";
386
387                                         // Nothing was selected
388                                         if ( index < 0 )
389                                                 return null;
390
391                                         // Loop through all the selected options
392                                         for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
393                                                 var option = options[ i ];
394
395                                                 if ( option.selected ) {
396                                                         // Get the specifc value for the option
397                                                         value = jQuery(option).val();
398
399                                                         // We don't need an array for one selects
400                                                         if ( one )
401                                                                 return value;
402
403                                                         // Multi-Selects return an array
404                                                         values.push( value );
405                                                 }
406                                         }
407
408                                         return values;                          
409                                 }
410
411                                 // Everything else, we just grab the value
412                                 return (elem.value || "").replace(/\r/g, "");
413
414                         }
415
416                         return undefined;
417                 }
418
419                 if ( typeof value === "number" )
420                         value += '';
421
422                 return this.each(function(){
423                         if ( this.nodeType != 1 )
424                                 return;
425
426                         if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
427                                 this.checked = (jQuery.inArray(this.value, value) >= 0 ||
428                                         jQuery.inArray(this.name, value) >= 0);
429
430                         else if ( jQuery.nodeName( this, "select" ) ) {
431                                 var values = jQuery.makeArray(value);
432
433                                 jQuery( "option", this ).each(function(){
434                                         this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
435                                                 jQuery.inArray( this.text, values ) >= 0);
436                                 });
437
438                                 if ( !values.length )
439                                         this.selectedIndex = -1;
440
441                         } else
442                                 this.value = value;
443                 });
444         },
445
446         html: function( value ) {
447                 return value === undefined ?
448                         (this[0] ?
449                                 this[0].innerHTML :
450                                 null) :
451                         this.empty().append( value );
452         },
453
454         replaceWith: function( value ) {
455                 return this.after( value ).remove();
456         },
457
458         eq: function( i ) {
459                 return this.slice( i, +i + 1 );
460         },
461
462         slice: function() {
463                 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
464                         "slice", Array.prototype.slice.call(arguments).join(",") );
465         },
466
467         map: function( callback ) {
468                 return this.pushStack( jQuery.map(this, function(elem, i){
469                         return callback.call( elem, i, elem );
470                 }));
471         },
472
473         andSelf: function() {
474                 return this.add( this.prevObject );
475         },
476
477         data: function( key, value ){
478                 var parts = key.split(".");
479                 parts[1] = parts[1] ? "." + parts[1] : "";
480
481                 if ( value === undefined ) {
482                         var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
483
484                         if ( data === undefined && this.length )
485                                 data = jQuery.data( this[0], key );
486
487                         return data == null && parts[1] ?
488                                 this.data( parts[0] ) :
489                                 data;
490                 } else
491                         return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
492                                 jQuery.data( this, key, value );
493                         });
494         },
495
496         removeData: function( key ){
497                 return this.each(function(){
498                         jQuery.removeData( this, key );
499                 });
500         },
501
502         domManip: function( args, table, callback ) {
503                 if ( this[0] ) {
504                         var fragment = this[0].ownerDocument.createDocumentFragment(),
505                                 scripts = jQuery.clean( args, this[0].ownerDocument, fragment ),
506                                 first = fragment.firstChild,
507                                 extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
508                         
509                         if ( first )
510                                 for ( var i = 0, l = this.length; i < l; i++ )
511                                         callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
512                         
513                         if ( scripts )
514                                 jQuery.each( scripts, evalScript );
515                 }
516
517                 return this;
518                 
519                 function root( elem, cur ) {
520                         return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
521                                 (elem.getElementsByTagName("tbody")[0] ||
522                                 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
523                                 elem;
524                 }
525         }
526 };
527
528 // Give the init function the jQuery prototype for later instantiation
529 jQuery.fn.init.prototype = jQuery.fn;
530
531 function evalScript( i, elem ) {
532         if ( elem.src )
533                 jQuery.ajax({
534                         url: elem.src,
535                         async: false,
536                         dataType: "script"
537                 });
538
539         else
540                 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
541
542         if ( elem.parentNode )
543                 elem.parentNode.removeChild( elem );
544 }
545
546 function now(){
547         return +new Date;
548 }
549
550 jQuery.extend = jQuery.fn.extend = function() {
551         // copy reference to target object
552         var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
553
554         // Handle a deep copy situation
555         if ( typeof target === "boolean" ) {
556                 deep = target;
557                 target = arguments[1] || {};
558                 // skip the boolean and the target
559                 i = 2;
560         }
561
562         // Handle case when target is a string or something (possible in deep copy)
563         if ( typeof target !== "object" && !jQuery.isFunction(target) )
564                 target = {};
565
566         // extend jQuery itself if only one argument is passed
567         if ( length == i ) {
568                 target = this;
569                 --i;
570         }
571
572         for ( ; i < length; i++ )
573                 // Only deal with non-null/undefined values
574                 if ( (options = arguments[ i ]) != null )
575                         // Extend the base object
576                         for ( var name in options ) {
577                                 var src = target[ name ], copy = options[ name ];
578
579                                 // Prevent never-ending loop
580                                 if ( target === copy )
581                                         continue;
582
583                                 // Recurse if we're merging object values
584                                 if ( deep && copy && typeof copy === "object" && !copy.nodeType )
585                                         target[ name ] = jQuery.extend( deep, 
586                                                 // Never move original objects, clone them
587                                                 src || ( copy.length != null ? [ ] : { } )
588                                         , copy );
589
590                                 // Don't bring in undefined values
591                                 else if ( copy !== undefined )
592                                         target[ name ] = copy;
593
594                         }
595
596         // Return the modified object
597         return target;
598 };
599
600 var expando = "jQuery" + now(), uuid = 0, windowData = {},
601         // exclude the following css properties to add px
602         exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
603         // cache defaultView
604         defaultView = document.defaultView || {},
605         toString = Object.prototype.toString;
606
607 jQuery.extend({
608         noConflict: function( deep ) {
609                 window.$ = _$;
610
611                 if ( deep )
612                         window.jQuery = _jQuery;
613
614                 return jQuery;
615         },
616
617         // See test/unit/core.js for details concerning isFunction.
618         // Since version 1.3, DOM methods and functions like alert
619         // aren't supported. They return false on IE (#2968).
620         isFunction: function( obj ) {
621                 return toString.call(obj) === "[object Function]";
622         },
623
624         isArray: function( obj ) {
625                 return toString.call(obj) === "[object Array]";
626         },
627
628         // check if an element is in a (or is an) XML document
629         isXMLDoc: function( elem ) {
630                 return elem.documentElement && !elem.body ||
631                         elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
632         },
633
634         // Evalulates a script in a global context
635         globalEval: function( data ) {
636                 data = jQuery.trim( data );
637
638                 if ( data ) {
639                         // Inspired by code by Andrea Giammarchi
640                         // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
641                         var head = document.getElementsByTagName("head")[0] || document.documentElement,
642                                 script = document.createElement("script");
643
644                         script.type = "text/javascript";
645                         if ( jQuery.support.scriptEval )
646                                 script.appendChild( document.createTextNode( data ) );
647                         else
648                                 script.text = data;
649
650                         // Use insertBefore instead of appendChild  to circumvent an IE6 bug.
651                         // This arises when a base node is used (#2709).
652                         head.insertBefore( script, head.firstChild );
653                         head.removeChild( script );
654                 }
655         },
656
657         nodeName: function( elem, name ) {
658                 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
659         },
660
661         cache: {},
662
663         data: function( elem, name, data ) {
664                 elem = elem == window ?
665                         windowData :
666                         elem;
667
668                 var id = elem[ expando ];
669
670                 // Compute a unique ID for the element
671                 if ( !id )
672                         id = elem[ expando ] = ++uuid;
673
674                 // Only generate the data cache if we're
675                 // trying to access or manipulate it
676                 if ( name && !jQuery.cache[ id ] )
677                         jQuery.cache[ id ] = {};
678
679                 // Prevent overriding the named cache with undefined values
680                 if ( data !== undefined )
681                         jQuery.cache[ id ][ name ] = data;
682
683                 // Return the named cache data, or the ID for the element
684                 return name ?
685                         jQuery.cache[ id ][ name ] || null :
686                         id;
687         },
688
689         removeData: function( elem, name ) {
690                 elem = elem == window ?
691                         windowData :
692                         elem;
693
694                 var id = elem[ expando ];
695
696                 // If we want to remove a specific section of the element's data
697                 if ( name ) {
698                         if ( jQuery.cache[ id ] ) {
699                                 // Remove the section of cache data
700                                 delete jQuery.cache[ id ][ name ];
701
702                                 // If we've removed all the data, remove the element's cache
703                                 name = "";
704
705                                 for ( name in jQuery.cache[ id ] )
706                                         break;
707
708                                 if ( !name )
709                                         jQuery.removeData( elem );
710                         }
711
712                 // Otherwise, we want to remove all of the element's data
713                 } else {
714                         // Clean up the element expando
715                         try {
716                                 delete elem[ expando ];
717                         } catch(e){
718                                 // IE has trouble directly removing the expando
719                                 // but it's ok with using removeAttribute
720                                 if ( elem.removeAttribute )
721                                         elem.removeAttribute( expando );
722                         }
723
724                         // Completely remove the data cache
725                         delete jQuery.cache[ id ];
726                 }
727         },
728
729         // args is for internal usage only
730         each: function( object, callback, args ) {
731                 var name, i = 0, length = object.length;
732
733                 if ( args ) {
734                         if ( length === undefined ) {
735                                 for ( name in object )
736                                         if ( callback.apply( object[ name ], args ) === false )
737                                                 break;
738                         } else
739                                 for ( ; i < length; )
740                                         if ( callback.apply( object[ i++ ], args ) === false )
741                                                 break;
742
743                 // A special, fast, case for the most common use of each
744                 } else {
745                         if ( length === undefined ) {
746                                 for ( name in object )
747                                         if ( callback.call( object[ name ], name, object[ name ] ) === false )
748                                                 break;
749                         } else
750                                 for ( var value = object[0];
751                                         i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
752                 }
753
754                 return object;
755         },
756
757         prop: function( elem, value, type, i, name ) {
758                 // Handle executable functions
759                 if ( jQuery.isFunction( value ) )
760                         value = value.call( elem, i );
761
762                 // Handle passing in a number to a CSS property
763                 return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ?
764                         value + "px" :
765                         value;
766         },
767
768         className: {
769                 // internal only, use addClass("class")
770                 add: function( elem, classNames ) {
771                         jQuery.each((classNames || "").split(/\s+/), function(i, className){
772                                 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
773                                         elem.className += (elem.className ? " " : "") + className;
774                         });
775                 },
776
777                 // internal only, use removeClass("class")
778                 remove: function( elem, classNames ) {
779                         if (elem.nodeType == 1)
780                                 elem.className = classNames !== undefined ?
781                                         jQuery.grep(elem.className.split(/\s+/), function(className){
782                                                 return !jQuery.className.has( classNames, className );
783                                         }).join(" ") :
784                                         "";
785                 },
786
787                 // internal only, use hasClass("class")
788                 has: function( elem, className ) {
789                         return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
790                 }
791         },
792
793         // A method for quickly swapping in/out CSS properties to get correct calculations
794         swap: function( elem, options, callback ) {
795                 var old = {};
796                 // Remember the old values, and insert the new ones
797                 for ( var name in options ) {
798                         old[ name ] = elem.style[ name ];
799                         elem.style[ name ] = options[ name ];
800                 }
801
802                 callback.call( elem );
803
804                 // Revert the old values
805                 for ( var name in options )
806                         elem.style[ name ] = old[ name ];
807         },
808
809         css: function( elem, name, force ) {
810                 if ( name == "width" || name == "height" ) {
811                         var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
812
813                         function getWH() {
814                                 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
815                                 var padding = 0, border = 0;
816                                 jQuery.each( which, function() {
817                                         padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
818                                         border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
819                                 });
820                                 val -= Math.round(padding + border);
821                         }
822
823                         if ( jQuery(elem).is(":visible") )
824                                 getWH();
825                         else
826                                 jQuery.swap( elem, props, getWH );
827
828                         return Math.max(0, val);
829                 }
830
831                 return jQuery.curCSS( elem, name, force );
832         },
833
834         curCSS: function( elem, name, force ) {
835                 var ret, style = elem.style;
836
837                 // We need to handle opacity special in IE
838                 if ( name == "opacity" && !jQuery.support.opacity ) {
839                         ret = jQuery.attr( style, "opacity" );
840
841                         return ret == "" ?
842                                 "1" :
843                                 ret;
844                 }
845
846                 // Make sure we're using the right name for getting the float value
847                 if ( name.match( /float/i ) )
848                         name = styleFloat;
849
850                 if ( !force && style && style[ name ] )
851                         ret = style[ name ];
852
853                 else if ( defaultView.getComputedStyle ) {
854
855                         // Only "float" is needed here
856                         if ( name.match( /float/i ) )
857                                 name = "float";
858
859                         name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
860
861                         var computedStyle = defaultView.getComputedStyle( elem, null );
862
863                         if ( computedStyle )
864                                 ret = computedStyle.getPropertyValue( name );
865
866                         // We should always get a number back from opacity
867                         if ( name == "opacity" && ret == "" )
868                                 ret = "1";
869
870                 } else if ( elem.currentStyle ) {
871                         var camelCase = name.replace(/\-(\w)/g, function(all, letter){
872                                 return letter.toUpperCase();
873                         });
874
875                         ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
876
877                         // From the awesome hack by Dean Edwards
878                         // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
879
880                         // If we're not dealing with a regular pixel number
881                         // but a number that has a weird ending, we need to convert it to pixels
882                         if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
883                                 // Remember the original values
884                                 var left = style.left, rsLeft = elem.runtimeStyle.left;
885
886                                 // Put in the new values to get a computed value out
887                                 elem.runtimeStyle.left = elem.currentStyle.left;
888                                 style.left = ret || 0;
889                                 ret = style.pixelLeft + "px";
890
891                                 // Revert the changed values
892                                 style.left = left;
893                                 elem.runtimeStyle.left = rsLeft;
894                         }
895                 }
896
897                 return ret;
898         },
899
900         clean: function( elems, context, fragment ) {
901                 var ret = [], scripts = [];
902                 context = context || document;
903
904                 // !context.createElement fails in IE with an error but returns typeof 'object'
905                 if ( typeof context.createElement === "undefined" )
906                         context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
907
908                 jQuery.each(elems, function(i, elem){
909                         if ( typeof elem === "number" )
910                                 elem += '';
911
912                         if ( !elem )
913                                 return;
914
915                         // Convert html string into DOM nodes
916                         if ( typeof elem === "string" ) {
917                                 // Fix "XHTML"-style tags in all browsers
918                                 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
919                                         return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
920                                                 all :
921                                                 front + "></" + tag + ">";
922                                 });
923
924                                 // Trim whitespace, otherwise indexOf won't work as expected
925                                 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
926
927                                 var wrap =
928                                         // option or optgroup
929                                         !tags.indexOf("<opt") &&
930                                         [ 1, "<select multiple='multiple'>", "</select>" ] ||
931
932                                         !tags.indexOf("<leg") &&
933                                         [ 1, "<fieldset>", "</fieldset>" ] ||
934
935                                         tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
936                                         [ 1, "<table>", "</table>" ] ||
937
938                                         !tags.indexOf("<tr") &&
939                                         [ 2, "<table><tbody>", "</tbody></table>" ] ||
940
941                                         // <thead> matched above
942                                         (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
943                                         [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
944
945                                         !tags.indexOf("<col") &&
946                                         [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
947
948                                         // IE can't serialize <link> and <script> tags normally
949                                         !jQuery.support.htmlSerialize &&
950                                         [ 1, "div<div>", "</div>" ] ||
951
952                                         [ 0, "", "" ];
953
954                                 // Go to html and back, then peel off extra wrappers
955                                 div.innerHTML = wrap[1] + elem + wrap[2];
956
957                                 // Move to the right depth
958                                 while ( wrap[0]-- )
959                                         div = div.lastChild;
960
961                                 // Remove IE's autoinserted <tbody> from table fragments
962                                 if ( !jQuery.support.tbody ) {
963
964                                         // String was a <table>, *may* have spurious <tbody>
965                                         var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
966                                                 div.firstChild && div.firstChild.childNodes :
967
968                                                 // String was a bare <thead> or <tfoot>
969                                                 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
970                                                         div.childNodes :
971                                                         [];
972
973                                         for ( var j = tbody.length - 1; j >= 0 ; --j )
974                                                 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
975                                                         tbody[ j ].parentNode.removeChild( tbody[ j ] );
976
977                                         }
978
979                                 // IE completely kills leading whitespace when innerHTML is used
980                                 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
981                                         div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
982                                 
983                                 if ( fragment ) {
984                                         var found = div.getElementsByTagName("script");
985                         
986                                         while ( found.length ) {
987                                                 scripts.push( found[0] );
988                                                 found[0].parentNode.removeChild( found[0] );
989                                         }
990                                 }
991
992                                 elem = jQuery.makeArray( div.childNodes );
993                         }
994
995                         if ( elem.nodeType )
996                                 ret.push( elem );
997                         else
998                                 ret = jQuery.merge( ret, elem );
999
1000                 });
1001                 
1002                 if ( fragment ) {
1003                         for ( var i = 0; ret[i]; i++ ) {
1004                                 if ( jQuery.nodeName( ret[i], "script" ) ) {
1005                                         ret[i].parentNode.removeChild( ret[i] );
1006                                 } else {
1007                                         if ( ret[i].nodeType === 1 )
1008                                                 ret = jQuery.merge( ret, ret[i].getElementsByTagName("script"));
1009                                         fragment.appendChild( ret[i] );
1010                                 }
1011                         }
1012                         
1013                         return scripts;
1014                 }
1015
1016                 return ret;
1017         },
1018
1019         attr: function( elem, name, value ) {
1020                 // don't set attributes on text and comment nodes
1021                 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
1022                         return undefined;
1023
1024                 var notxml = !jQuery.isXMLDoc( elem ),
1025                         // Whether we are setting (or getting)
1026                         set = value !== undefined;
1027
1028                 // Try to normalize/fix the name
1029                 name = notxml && jQuery.props[ name ] || name;
1030
1031                 // Only do all the following if this is a node (faster for style)
1032                 // IE elem.getAttribute passes even for style
1033                 if ( elem.tagName ) {
1034
1035                         // These attributes require special treatment
1036                         var special = /href|src|style/.test( name );
1037
1038                         // Safari mis-reports the default selected property of a hidden option
1039                         // Accessing the parent's selectedIndex property fixes it
1040                         if ( name == "selected" )
1041                                 elem.parentNode.selectedIndex;
1042
1043                         // If applicable, access the attribute via the DOM 0 way
1044                         if ( name in elem && notxml && !special ) {
1045                                 if ( set ){
1046                                         // We can't allow the type property to be changed (since it causes problems in IE)
1047                                         if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
1048                                                 throw "type property can't be changed";
1049
1050                                         elem[ name ] = value;
1051                                 }
1052
1053                                 // browsers index elements by id/name on forms, give priority to attributes.
1054                                 if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
1055                                         return elem.getAttributeNode( name ).nodeValue;
1056
1057                                 return elem[ name ];
1058                         }
1059
1060                         if ( !jQuery.support.style && notxml &&  name == "style" )
1061                                 return jQuery.attr( elem.style, "cssText", value );
1062
1063                         if ( set )
1064                                 // convert the value to a string (all browsers do this but IE) see #1070
1065                                 elem.setAttribute( name, "" + value );
1066
1067                         var attr = !jQuery.support.hrefNormalized && notxml && special
1068                                         // Some attributes require a special call on IE
1069                                         ? elem.getAttribute( name, 2 )
1070                                         : elem.getAttribute( name );
1071
1072                         // Non-existent attributes return null, we normalize to undefined
1073                         return attr === null ? undefined : attr;
1074                 }
1075
1076                 // elem is actually elem.style ... set the style
1077
1078                 // IE uses filters for opacity
1079                 if ( !jQuery.support.opacity && name == "opacity" ) {
1080                         if ( set ) {
1081                                 // IE has trouble with opacity if it does not have layout
1082                                 // Force it by setting the zoom level
1083                                 elem.zoom = 1;
1084
1085                                 // Set the alpha filter to set the opacity
1086                                 elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
1087                                         (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
1088                         }
1089
1090                         return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
1091                                 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
1092                                 "";
1093                 }
1094
1095                 name = name.replace(/-([a-z])/ig, function(all, letter){
1096                         return letter.toUpperCase();
1097                 });
1098
1099                 if ( set )
1100                         elem[ name ] = value;
1101
1102                 return elem[ name ];
1103         },
1104
1105         trim: function( text ) {
1106                 return (text || "").replace( /^\s+|\s+$/g, "" );
1107         },
1108
1109         makeArray: function( array ) {
1110                 var ret = [];
1111
1112                 if( array != null ){
1113                         var i = array.length;
1114                         // The window, strings (and functions) also have 'length'
1115                         if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
1116                                 ret[0] = array;
1117                         else
1118                                 while( i )
1119                                         ret[--i] = array[i];
1120                 }
1121
1122                 return ret;
1123         },
1124
1125         inArray: function( elem, array ) {
1126                 for ( var i = 0, length = array.length; i < length; i++ )
1127                 // Use === because on IE, window == document
1128                         if ( array[ i ] === elem )
1129                                 return i;
1130
1131                 return -1;
1132         },
1133
1134         merge: function( first, second ) {
1135                 // We have to loop this way because IE & Opera overwrite the length
1136                 // expando of getElementsByTagName
1137                 var i = 0, elem, pos = first.length;
1138                 // Also, we need to make sure that the correct elements are being returned
1139                 // (IE returns comment nodes in a '*' query)
1140                 if ( !jQuery.support.getAll ) {
1141                         while ( (elem = second[ i++ ]) )
1142                                 if ( elem.nodeType != 8 )
1143                                         first[ pos++ ] = elem;
1144
1145                 } else
1146                         while ( (elem = second[ i++ ]) )
1147                                 first[ pos++ ] = elem;
1148
1149                 return first;
1150         },
1151
1152         unique: function( array ) {
1153                 var ret = [], done = {};
1154
1155                 try {
1156
1157                         for ( var i = 0, length = array.length; i < length; i++ ) {
1158                                 var id = jQuery.data( array[ i ] );
1159
1160                                 if ( !done[ id ] ) {
1161                                         done[ id ] = true;
1162                                         ret.push( array[ i ] );
1163                                 }
1164                         }
1165
1166                 } catch( e ) {
1167                         ret = array;
1168                 }
1169
1170                 return ret;
1171         },
1172
1173         grep: function( elems, callback, inv ) {
1174                 var ret = [];
1175
1176                 // Go through the array, only saving the items
1177                 // that pass the validator function
1178                 for ( var i = 0, length = elems.length; i < length; i++ )
1179                         if ( !inv != !callback( elems[ i ], i ) )
1180                                 ret.push( elems[ i ] );
1181
1182                 return ret;
1183         },
1184
1185         map: function( elems, callback ) {
1186                 var ret = [];
1187
1188                 // Go through the array, translating each of the items to their
1189                 // new value (or values).
1190                 for ( var i = 0, length = elems.length; i < length; i++ ) {
1191                         var value = callback( elems[ i ], i );
1192
1193                         if ( value != null )
1194                                 ret[ ret.length ] = value;
1195                 }
1196
1197                 return ret.concat.apply( [], ret );
1198         }
1199 });
1200
1201 // Use of jQuery.browser is deprecated.
1202 // It's included for backwards compatibility and plugins,
1203 // although they should work to migrate away.
1204
1205 var userAgent = navigator.userAgent.toLowerCase();
1206
1207 // Figure out what browser is being used
1208 jQuery.browser = {
1209         version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
1210         safari: /webkit/.test( userAgent ),
1211         opera: /opera/.test( userAgent ),
1212         msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
1213         mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
1214 };
1215
1216 // Check to see if the W3C box model is being used
1217 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1218
1219 jQuery.each({
1220         parent: function(elem){return elem.parentNode;},
1221         parents: function(elem){return jQuery.dir(elem,"parentNode");},
1222         next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
1223         prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
1224         nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
1225         prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
1226         siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
1227         children: function(elem){return jQuery.sibling(elem.firstChild);},
1228         contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
1229 }, function(name, fn){
1230         jQuery.fn[ name ] = function( selector ) {
1231                 var ret = jQuery.map( this, fn );
1232
1233                 if ( selector && typeof selector == "string" )
1234                         ret = jQuery.multiFilter( selector, ret );
1235
1236                 return this.pushStack( jQuery.unique( ret ), name, selector );
1237         };
1238 });
1239
1240 jQuery.each({
1241         appendTo: "append",
1242         prependTo: "prepend",
1243         insertBefore: "before",
1244         insertAfter: "after",
1245         replaceAll: "replaceWith"
1246 }, function(name, original){
1247         jQuery.fn[ name ] = function() {
1248                 var args = arguments;
1249
1250                 return this.each(function(){
1251                         for ( var i = 0, length = args.length; i < length; i++ )
1252                                 jQuery( args[ i ] )[ original ]( this );
1253                 });
1254         };
1255 });
1256
1257 jQuery.each({
1258         removeAttr: function( name ) {
1259                 jQuery.attr( this, name, "" );
1260                 if (this.nodeType == 1)
1261                         this.removeAttribute( name );
1262         },
1263
1264         addClass: function( classNames ) {
1265                 jQuery.className.add( this, classNames );
1266         },
1267
1268         removeClass: function( classNames ) {
1269                 jQuery.className.remove( this, classNames );
1270         },
1271
1272         toggleClass: function( classNames ) {
1273                 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
1274         },
1275
1276         remove: function( selector ) {
1277                 if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
1278                         // Prevent memory leaks
1279                         jQuery( "*", this ).add([this]).each(function(){
1280                                 jQuery.event.remove(this);
1281                                 jQuery.removeData(this);
1282                         });
1283                         if (this.parentNode)
1284                                 this.parentNode.removeChild( this );
1285                 }
1286         },
1287
1288         empty: function() {
1289                 // Remove element nodes and prevent memory leaks
1290                 jQuery( ">*", this ).remove();
1291
1292                 // Remove any remaining nodes
1293                 while ( this.firstChild )
1294                         this.removeChild( this.firstChild );
1295         }
1296 }, function(name, fn){
1297         jQuery.fn[ name ] = function(){
1298                 return this.each( fn, arguments );
1299         };
1300 });
1301
1302 // Helper function used by the dimensions and offset modules
1303 function num(elem, prop) {
1304         return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;
1305 }