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