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