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