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