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