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