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