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