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