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