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