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