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