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