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