Removed all inline documentation. The current version of all documentation is stored...
[jquery.git] / src / jquery / jquery.js
1 /*
2  * jQuery @VERSION - New Wave Javascript
3  *
4  * Copyright (c) 2007 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 if ( typeof jQuery != "undefined" )
14         var _jQuery = jQuery;
15
16 var jQuery = window.jQuery = function(a,c) {
17         // If the context is global, return a new object
18         if ( window == this || !this.init )
19                 return new jQuery(a,c);
20         
21         return this.init(a,c);
22 };
23
24 // Map over the $ in case of overwrite
25 if ( typeof $ != "undefined" )
26         var _$ = $;
27         
28 // Map the jQuery namespace to the '$' one
29 window.$ = jQuery;
30
31 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
32
33 jQuery.fn = jQuery.prototype = {
34         init: function(a,c) {
35                 // Make sure that a selection was provided
36                 a = a || document;
37
38                 // Handle HTML strings
39                 if ( typeof a  == "string" ) {
40                         var m = quickExpr.exec(a);
41                         if ( m && (m[1] || !c) ) {
42                                 // HANDLE: $(html) -> $(array)
43                                 if ( m[1] )
44                                         a = jQuery.clean( [ m[1] ], c );
45
46                                 // HANDLE: $("#id")
47                                 else {
48                                         var tmp = document.getElementById( m[3] );
49                                         if ( tmp )
50                                                 // Handle the case where IE and Opera return items
51                                                 // by name instead of ID
52                                                 if ( tmp.id != m[3] )
53                                                         return jQuery().find( a );
54                                                 else {
55                                                         this[0] = tmp;
56                                                         this.length = 1;
57                                                         return this;
58                                                 }
59                                         else
60                                                 a = [];
61                                 }
62
63                         // HANDLE: $(expr)
64                         } else
65                                 return new jQuery( c ).find( a );
66
67                 // HANDLE: $(function)
68                 // Shortcut for document ready
69                 } else if ( jQuery.isFunction(a) )
70                         return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a );
71
72                 return this.setArray(
73                         // HANDLE: $(array)
74                         a.constructor == Array && a ||
75
76                         // HANDLE: $(arraylike)
77                         // Watch for when an array-like object is passed as the selector
78                         (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) ||
79
80                         // HANDLE: $(*)
81                         [ a ] );
82         },
83         
84         jquery: "@VERSION",
85
86         size: function() {
87                 return this.length;
88         },
89         
90         length: 0,
91
92         get: function( num ) {
93                 return num == undefined ?
94
95                         // Return a 'clean' array
96                         jQuery.makeArray( this ) :
97
98                         // Return just the object
99                         this[num];
100         },
101         
102         pushStack: function( a ) {
103                 var ret = jQuery(a);
104                 ret.prevObject = this;
105                 return ret;
106         },
107         
108         setArray: function( a ) {
109                 this.length = 0;
110                 Array.prototype.push.apply( this, a );
111                 return this;
112         },
113
114         each: function( fn, args ) {
115                 return jQuery.each( this, fn, args );
116         },
117
118         index: function( obj ) {
119                 var pos = -1;
120                 this.each(function(i){
121                         if ( this == obj ) pos = i;
122                 });
123                 return pos;
124         },
125
126         attr: function( key, value, type ) {
127                 var obj = key;
128                 
129                 // Look for the case where we're accessing a style value
130                 if ( key.constructor == String )
131                         if ( value == undefined )
132                                 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined;
133                         else {
134                                 obj = {};
135                                 obj[ key ] = value;
136                         }
137                 
138                 // Check to see if we're setting style values
139                 return this.each(function(index){
140                         // Set all the styles
141                         for ( var prop in obj )
142                                 jQuery.attr(
143                                         type ? this.style : this,
144                                         prop, jQuery.prop(this, obj[prop], type, index, prop)
145                                 );
146                 });
147         },
148
149         css: function( key, value ) {
150                 return this.attr( key, value, "curCSS" );
151         },
152
153         text: function(e) {
154                 if ( typeof e != "object" && e != null )
155                         return this.empty().append( document.createTextNode( e ) );
156
157                 var t = "";
158                 jQuery.each( e || this, function(){
159                         jQuery.each( this.childNodes, function(){
160                                 if ( this.nodeType != 8 )
161                                         t += this.nodeType != 1 ?
162                                                 this.nodeValue : jQuery.fn.text([ this ]);
163                         });
164                 });
165                 return t;
166         },
167
168         wrapAll: function(html) {
169                 if ( this[0] )
170                         // The elements to wrap the target around
171                         jQuery(html, this[0].ownerDocument)
172                                 .clone()
173                                 .insertBefore(this[0])
174                                 .map(function(){
175                                         var elem = this;
176                                         while ( elem.firstChild )
177                                                 elem = elem.firstChild;
178                                         return elem;
179                                 })
180                                 .append(this);
181
182                 return this;
183         },
184
185         wrapInner: function(html) {
186                 return this.each(function(){
187                         jQuery(this).contents().wrapAll(html);
188                 });
189         },
190
191         wrap: function(html) {
192                 return this.each(function(){
193                         jQuery(this).wrapAll(html);
194                 });
195         },
196
197         append: function() {
198                 return this.domManip(arguments, true, 1, function(a){
199                         this.appendChild( a );
200                 });
201         },
202
203         prepend: function() {
204                 return this.domManip(arguments, true, -1, function(a){
205                         this.insertBefore( a, this.firstChild );
206                 });
207         },
208         
209         before: function() {
210                 return this.domManip(arguments, false, 1, function(a){
211                         this.parentNode.insertBefore( a, this );
212                 });
213         },
214
215         after: function() {
216                 return this.domManip(arguments, false, -1, function(a){
217                         this.parentNode.insertBefore( a, this.nextSibling );
218                 });
219         },
220
221         end: function() {
222                 return this.prevObject || jQuery([]);
223         },
224
225         find: function(t) {
226                 var data = jQuery.map(this, function(a){ return jQuery.find(t,a); });
227                 return this.pushStack( /[^+>] [^+>]/.test( t ) || t.indexOf("..") > -1 ?
228                         jQuery.unique( data ) : data );
229         },
230
231         clone: function(deep) {
232                 deep = deep != undefined ? deep : true;
233                 var $this = this.add(this.find("*"));
234                 if (jQuery.browser.msie) {
235                         // Need to remove events on the element and its descendants
236                         $this.each(function() {
237                                 this._$events = {};
238                                 for (var type in this.$events)
239                                         this._$events[type] = jQuery.extend({},this.$events[type]);
240                         }).unbind();
241                 }
242
243                 // Do the clone
244                 var r = this.pushStack( jQuery.map( this, function(a){
245                         return a.cloneNode( deep );
246                 }) );
247
248                 if (jQuery.browser.msie) {
249                         $this.each(function() {
250                                 // Add the events back to the original and its descendants
251                                 var events = this._$events;
252                                 for (var type in events)
253                                         for (var handler in events[type])
254                                                 jQuery.event.add(this, type, events[type][handler], events[type][handler].data);
255                                 this._$events = null;
256                         });
257                 }
258
259                 // copy form values over
260                 if (deep) {
261                         var inputs = r.add(r.find('*')).filter('select,input[@type=checkbox]');
262                         $this.filter('select,input[@type=checkbox]').each(function(i) {
263                                 if (this.selectedIndex)
264                                         inputs[i].selectedIndex = this.selectedIndex;
265                                 if (this.checked)
266                                         inputs[i].checked = true;
267                         });
268                 }
269
270                 // Return the cloned set
271                 return r;
272         },
273
274         filter: function(t) {
275                 return this.pushStack(
276                         jQuery.isFunction( t ) &&
277                         jQuery.grep(this, function(el, index){
278                                 return t.apply(el, [index]);
279                         }) ||
280
281                         jQuery.multiFilter(t,this) );
282         },
283
284         not: function(t) {
285                 return this.pushStack(
286                         t.constructor == String &&
287                         jQuery.multiFilter(t, this, true) ||
288
289                         jQuery.grep(this, function(a) {
290                                 return ( t.constructor == Array || t.jquery )
291                                         ? jQuery.inArray( a, t ) < 0
292                                         : a != t;
293                         })
294                 );
295         },
296
297         add: function(t) {
298                 return this.pushStack( jQuery.merge(
299                         this.get(),
300                         t.constructor == String ?
301                                 jQuery(t).get() :
302                                 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ?
303                                         t : [t] )
304                 );
305         },
306
307         is: function(expr) {
308                 return expr ? jQuery.multiFilter(expr,this).length > 0 : false;
309         },
310         
311         val: function( val ) {
312                 return val == undefined ?
313                         ( this.length ? this[0].value : null ) :
314                         this.attr( "value", val );
315         },
316         
317         html: function( val ) {
318                 return val == undefined ?
319                         ( this.length ? this[0].innerHTML : null ) :
320                         this.empty().append( val );
321         },
322
323         replaceWith: function( val ) {
324                 return this.after( val ).remove();
325         },
326
327         slice: function() {
328                 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
329         },
330
331         map: function(fn){
332                 return this.pushStack(jQuery.map( this, function(elem,i){
333                         return fn.call( elem, i, elem );
334                 }));
335         },
336         
337         domManip: function(args, table, dir, fn){
338                 var clone = this.length > 1, a; 
339
340                 return this.each(function(){
341                         if ( !a ) {
342                                 a = jQuery.clean(args, this.ownerDocument);
343                                 if ( dir < 0 )
344                                         a.reverse();
345                         }
346
347                         var obj = this;
348
349                         if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
350                                 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
351
352                         jQuery.each( a, function(){
353                                 if ( jQuery.nodeName(this, "script") ) {
354                                         if ( this.src )
355                                                 jQuery.ajax({ url: this.src, async: false, dataType: "script" });
356                                         else
357                                                 jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
358                                 } else
359                                         fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
360                         });
361                 });
362         }
363 };
364
365 jQuery.extend = jQuery.fn.extend = function() {
366         // copy reference to target object
367         var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;
368
369         // Handle a deep copy situation
370         if ( target.constructor == Boolean ) {
371                 deep = target;
372                 target = arguments[1] || {};
373         }
374
375         // extend jQuery itself if only one argument is passed
376         if ( al == 1 ) {
377                 target = this;
378                 a = 0;
379         }
380
381         var prop;
382
383         for ( ; a < al; a++ )
384                 // Only deal with non-null/undefined values
385                 if ( (prop = arguments[a]) != null )
386                         // Extend the base object
387                         for ( var i in prop ) {
388                                 // Prevent never-ending loop
389                                 if ( target == prop[i] )
390                                         continue;
391
392                                 // Recurse if we're merging object values
393                                 if ( deep && typeof prop[i] == 'object' && target[i] )
394                                         jQuery.extend( target[i], prop[i] );
395
396                                 // Don't bring in undefined values
397                                 else if ( prop[i] != undefined )
398                                         target[i] = prop[i];
399                         }
400
401         // Return the modified object
402         return target;
403 };
404
405 jQuery.extend({
406         noConflict: function(deep) {
407                 window.$ = _$;
408                 if ( deep )
409                         window.jQuery = _jQuery;
410                 return jQuery;
411         },
412
413         // This may seem like some crazy code, but trust me when I say that this
414         // is the only cross-browser way to do this. --John
415         isFunction: function( fn ) {
416                 return !!fn && typeof fn != "string" && !fn.nodeName && 
417                         fn.constructor != Array && /function/i.test( fn + "" );
418         },
419         
420         // check if an element is in a XML document
421         isXMLDoc: function(elem) {
422                 return elem.documentElement && !elem.body ||
423                         elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
424         },
425
426         // Evalulates a script in a global context
427         // Evaluates Async. in Safari 2 :-(
428         globalEval: function( data ) {
429                 data = jQuery.trim( data );
430                 if ( data ) {
431                         if ( window.execScript )
432                                 window.execScript( data );
433                         else if ( jQuery.browser.safari )
434                                 // safari doesn't provide a synchronous global eval
435                                 window.setTimeout( data, 0 );
436                         else
437                                 eval.call( window, data );
438                 }
439         },
440
441         nodeName: function( elem, name ) {
442                 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
443         },
444
445         // args is for internal usage only
446         each: function( obj, fn, args ) {
447                 if ( args ) {
448                         if ( obj.length == undefined )
449                                 for ( var i in obj )
450                                         fn.apply( obj[i], args );
451                         else
452                                 for ( var i = 0, ol = obj.length; i < ol; i++ )
453                                         if ( fn.apply( obj[i], args ) === false ) break;
454
455                 // A special, fast, case for the most common use of each
456                 } else {
457                         if ( obj.length == undefined )
458                                 for ( var i in obj )
459                                         fn.call( obj[i], i, obj[i] );
460                         else
461                                 for ( var i = 0, ol = obj.length, val = obj[0]; 
462                                         i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
463                 }
464
465                 return obj;
466         },
467         
468         prop: function(elem, value, type, index, prop){
469                         // Handle executable functions
470                         if ( jQuery.isFunction( value ) )
471                                 value = value.call( elem, [index] );
472                                 
473                         // exclude the following css properties to add px
474                         var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
475
476                         // Handle passing in a number to a CSS property
477                         return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ?
478                                 value + "px" :
479                                 value;
480         },
481
482         className: {
483                 // internal only, use addClass("class")
484                 add: function( elem, c ){
485                         jQuery.each( (c || "").split(/\s+/), function(i, cur){
486                                 if ( !jQuery.className.has( elem.className, cur ) )
487                                         elem.className += ( elem.className ? " " : "" ) + cur;
488                         });
489                 },
490
491                 // internal only, use removeClass("class")
492                 remove: function( elem, c ){
493                         elem.className = c != undefined ?
494                                 jQuery.grep( elem.className.split(/\s+/), function(cur){
495                                         return !jQuery.className.has( c, cur ); 
496                                 }).join(" ") : "";
497                 },
498
499                 // internal only, use is(".class")
500                 has: function( t, c ) {
501                         return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
502                 }
503         },
504
505         swap: function(e,o,f) {
506                 for ( var i in o ) {
507                         e.style["old"+i] = e.style[i];
508                         e.style[i] = o[i];
509                 }
510                 f.apply( e, [] );
511                 for ( var i in o )
512                         e.style[i] = e.style["old"+i];
513         },
514
515         css: function(e,p) {
516                 if ( p == "height" || p == "width" ) {
517                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
518
519                         jQuery.each( d, function(){
520                                 old["padding" + this] = 0;
521                                 old["border" + this + "Width"] = 0;
522                         });
523
524                         jQuery.swap( e, old, function() {
525                                 if ( jQuery(e).is(':visible') ) {
526                                         oHeight = e.offsetHeight;
527                                         oWidth = e.offsetWidth;
528                                 } else {
529                                         e = jQuery(e.cloneNode(true))
530                                                 .find(":radio").removeAttr("checked").end()
531                                                 .css({
532                                                         visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
533                                                 }).appendTo(e.parentNode)[0];
534
535                                         var parPos = jQuery.css(e.parentNode,"position") || "static";
536                                         if ( parPos == "static" )
537                                                 e.parentNode.style.position = "relative";
538
539                                         oHeight = e.clientHeight;
540                                         oWidth = e.clientWidth;
541
542                                         if ( parPos == "static" )
543                                                 e.parentNode.style.position = "static";
544
545                                         e.parentNode.removeChild(e);
546                                 }
547                         });
548
549                         return p == "height" ? oHeight : oWidth;
550                 }
551
552                 return jQuery.curCSS( e, p );
553         },
554
555         curCSS: function(elem, prop, force) {
556                 var ret, stack = [], swap = [];
557
558                 // A helper method for determining if an element's values are broken
559                 function color(a){
560                         if ( !jQuery.browser.safari )
561                                 return false;
562
563                         var ret = document.defaultView.getComputedStyle(a,null);
564                         return !ret || ret.getPropertyValue("color") == "";
565                 }
566
567                 if (prop == "opacity" && jQuery.browser.msie) {
568                         ret = jQuery.attr(elem.style, "opacity");
569                         return ret == "" ? "1" : ret;
570                 }
571                 
572                 if (prop.match(/float/i))
573                         prop = styleFloat;
574
575                 if (!force && elem.style[prop])
576                         ret = elem.style[prop];
577
578                 else if (document.defaultView && document.defaultView.getComputedStyle) {
579
580                         if (prop.match(/float/i))
581                                 prop = "float";
582
583                         prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
584                         var cur = document.defaultView.getComputedStyle(elem, null);
585
586                         if ( cur && !color(elem) )
587                                 ret = cur.getPropertyValue(prop);
588
589                         // If the element isn't reporting its values properly in Safari
590                         // then some display: none elements are involved
591                         else {
592                                 // Locate all of the parent display: none elements
593                                 for ( var a = elem; a && color(a); a = a.parentNode )
594                                         stack.unshift(a);
595
596                                 // Go through and make them visible, but in reverse
597                                 // (It would be better if we knew the exact display type that they had)
598                                 for ( a = 0; a < stack.length; a++ )
599                                         if ( color(stack[a]) ) {
600                                                 swap[a] = stack[a].style.display;
601                                                 stack[a].style.display = "block";
602                                         }
603
604                                 // Since we flip the display style, we have to handle that
605                                 // one special, otherwise get the value
606                                 ret = prop == "display" && swap[stack.length-1] != null ?
607                                         "none" :
608                                         document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || "";
609
610                                 // Finally, revert the display styles back
611                                 for ( a = 0; a < swap.length; a++ )
612                                         if ( swap[a] != null )
613                                                 stack[a].style.display = swap[a];
614                         }
615
616                         if ( prop == "opacity" && ret == "" )
617                                 ret = "1";
618
619                 } else if (elem.currentStyle) {
620                         var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
621                         ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
622                 }
623
624                 return ret;
625         },
626         
627         clean: function(a, doc) {
628                 var r = [];
629                 doc = doc || document;
630
631                 jQuery.each( a, function(i,arg){
632                         if ( !arg ) return;
633
634                         if ( arg.constructor == Number )
635                                 arg = arg.toString();
636                         
637                         // Convert html string into DOM nodes
638                         if ( typeof arg == "string" ) {
639                                 // Trim whitespace, otherwise indexOf won't work as expected
640                                 var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];
641
642                                 var wrap =
643                                         // option or optgroup
644                                         !s.indexOf("<opt") &&
645                                         [1, "<select>", "</select>"] ||
646                                         
647                                         !s.indexOf("<leg") &&
648                                         [1, "<fieldset>", "</fieldset>"] ||
649                                         
650                                         s.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
651                                         [1, "<table>", "</table>"] ||
652                                         
653                                         !s.indexOf("<tr") &&
654                                         [2, "<table><tbody>", "</tbody></table>"] ||
655                                         
656                                         // <thead> matched above
657                                         (!s.indexOf("<td") || !s.indexOf("<th")) &&
658                                         [3, "<table><tbody><tr>", "</tr></tbody></table>"] ||
659                                         
660                                         !s.indexOf("<col") &&
661                                         [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"] ||
662
663                                         // IE can't serialize <link> and <script> tags normally
664                                         jQuery.browser.msie &&
665                                         [1, "div<div>", "</div>"] ||
666                                         
667                                         [0,"",""];
668
669                                 // Go to html and back, then peel off extra wrappers
670                                 div.innerHTML = wrap[1] + arg + wrap[2];
671                                 
672                                 // Move to the right depth
673                                 while ( wrap[0]-- )
674                                         div = div.lastChild;
675                                 
676                                 // Remove IE's autoinserted <tbody> from table fragments
677                                 if ( jQuery.browser.msie ) {
678                                         
679                                         // String was a <table>, *may* have spurious <tbody>
680                                         if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 ) 
681                                                 tb = div.firstChild && div.firstChild.childNodes;
682                                                 
683                                         // String was a bare <thead> or <tfoot>
684                                         else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
685                                                 tb = div.childNodes;
686
687                                         for ( var n = tb.length-1; n >= 0 ; --n )
688                                                 if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
689                                                         tb[n].parentNode.removeChild(tb[n]);
690         
691                                         // IE completely kills leading whitespace when innerHTML is used        
692                                         if ( /^\s/.test(arg) )  
693                                                 div.insertBefore( doc.createTextNode( arg.match(/^\s*/)[0] ), div.firstChild );
694
695                                 }
696                                 
697                                 arg = jQuery.makeArray( div.childNodes );
698                         }
699
700                         if ( 0 === arg.length && (!jQuery.nodeName(arg, "form") && !jQuery.nodeName(arg, "select")) )
701                                 return;
702
703                         if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options )
704                                 r.push( arg );
705                         else
706                                 r = jQuery.merge( r, arg );
707
708                 });
709
710                 return r;
711         },
712         
713         attr: function(elem, name, value){
714                 var fix = jQuery.isXMLDoc(elem) ? {} : jQuery.props;
715
716                 // Safari mis-reports the default selected property of a hidden option
717                 // Accessing the parent's selectedIndex property fixes it
718                 if ( name == "selected" && jQuery.browser.safari )
719                         elem.parentNode.selectedIndex;
720                 
721                 // Certain attributes only work when accessed via the old DOM 0 way
722                 if ( fix[name] ) {
723                         if ( value != undefined ) elem[fix[name]] = value;
724                         return elem[fix[name]];
725                 } else if ( jQuery.browser.msie && name == "style" )
726                         return jQuery.attr( elem.style, "cssText", value );
727
728                 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
729                         return elem.getAttributeNode(name).nodeValue;
730
731                 // IE elem.getAttribute passes even for style
732                 else if ( elem.tagName ) {
733
734                         if ( value != undefined ) elem.setAttribute( name, value );
735                         if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) ) 
736                                 return elem.getAttribute( name, 2 );
737                         return elem.getAttribute( name );
738
739                 // elem is actually elem.style ... set the style
740                 } else {
741                         // IE actually uses filters for opacity
742                         if ( name == "opacity" && jQuery.browser.msie ) {
743                                 if ( value != undefined ) {
744                                         // IE has trouble with opacity if it does not have layout
745                                         // Force it by setting the zoom level
746                                         elem.zoom = 1; 
747         
748                                         // Set the alpha filter to set the opacity
749                                         elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") +
750                                                 (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
751                                 }
752         
753                                 return elem.filter ? 
754                                         (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : "";
755                         }
756                         name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
757                         if ( value != undefined ) elem[name] = value;
758                         return elem[name];
759                 }
760         },
761         
762         trim: function(t){
763                 return (t||"").replace(/^\s+|\s+$/g, "");
764         },
765
766         makeArray: function( a ) {
767                 var r = [];
768
769                 // Need to use typeof to fight Safari childNodes crashes
770                 if ( typeof a != "array" )
771                         for ( var i = 0, al = a.length; i < al; i++ )
772                                 r.push( a[i] );
773                 else
774                         r = a.slice( 0 );
775
776                 return r;
777         },
778
779         inArray: function( b, a ) {
780                 for ( var i = 0, al = a.length; i < al; i++ )
781                         if ( a[i] == b )
782                                 return i;
783                 return -1;
784         },
785
786         merge: function(first, second) {
787                 // We have to loop this way because IE & Opera overwrite the length
788                 // expando of getElementsByTagName
789
790                 // Also, we need to make sure that the correct elements are being returned
791                 // (IE returns comment nodes in a '*' query)
792                 if ( jQuery.browser.msie ) {
793                         for ( var i = 0; second[i]; i++ )
794                                 if ( second[i].nodeType != 8 )
795                                         first.push(second[i]);
796                 } else
797                         for ( var i = 0; second[i]; i++ )
798                                 first.push(second[i]);
799
800                 return first;
801         },
802
803         unique: function(first) {
804                 var r = [], num = jQuery.mergeNum++;
805
806                 try {
807                         for ( var i = 0, fl = first.length; i < fl; i++ )
808                                 if ( num != first[i].mergeNum ) {
809                                         first[i].mergeNum = num;
810                                         r.push(first[i]);
811                                 }
812                 } catch(e) {
813                         r = first;
814                 }
815
816                 return r;
817         },
818
819         mergeNum: 0,
820
821         grep: function(elems, fn, inv) {
822                 // If a string is passed in for the function, make a function
823                 // for it (a handy shortcut)
824                 if ( typeof fn == "string" )
825                         fn = eval("false||function(a,i){return " + fn + "}");
826
827                 var result = [];
828
829                 // Go through the array, only saving the items
830                 // that pass the validator function
831                 for ( var i = 0, el = elems.length; i < el; i++ )
832                         if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
833                                 result.push( elems[i] );
834
835                 return result;
836         },
837
838         map: function(elems, fn) {
839                 // If a string is passed in for the function, make a function
840                 // for it (a handy shortcut)
841                 if ( typeof fn == "string" )
842                         fn = eval("false||function(a){return " + fn + "}");
843
844                 var result = [];
845
846                 // Go through the array, translating each of the items to their
847                 // new value (or values).
848                 for ( var i = 0, el = elems.length; i < el; i++ ) {
849                         var val = fn(elems[i],i);
850
851                         if ( val !== null && val != undefined ) {
852                                 if ( val.constructor != Array ) val = [val];
853                                 result = result.concat( val );
854                         }
855                 }
856
857                 return result;
858         }
859 });
860
861 var userAgent = navigator.userAgent.toLowerCase();
862
863 // Figure out what browser is being used
864 jQuery.browser = {
865         version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
866         safari: /webkit/.test(userAgent),
867         opera: /opera/.test(userAgent),
868         msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
869         mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
870 };
871
872 var styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat";
873         
874 jQuery.extend({
875         // Check to see if the W3C box model is being used
876         boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
877         
878         styleFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
879         
880         props: {
881                 "for": "htmlFor",
882                 "class": "className",
883                 "float": styleFloat,
884                 cssFloat: styleFloat,
885                 styleFloat: styleFloat,
886                 innerHTML: "innerHTML",
887                 className: "className",
888                 value: "value",
889                 disabled: "disabled",
890                 checked: "checked",
891                 readonly: "readOnly",
892                 selected: "selected",
893                 maxlength: "maxLength"
894         }
895 });
896
897 jQuery.each({
898         parent: "a.parentNode",
899         parents: "jQuery.parents(a)",
900         next: "jQuery.nth(a,2,'nextSibling')",
901         prev: "jQuery.nth(a,2,'previousSibling')",
902         siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
903         children: "jQuery.sibling(a.firstChild)",
904         contents: "jQuery.nodeName(a,'iframe')?a.contentDocument||a.contentWindow.document:jQuery.makeArray(a.childNodes)"
905 }, function(i,n){
906         jQuery.fn[ i ] = function(a) {
907                 var ret = jQuery.map(this,n);
908                 if ( a && typeof a == "string" )
909                         ret = jQuery.multiFilter(a,ret);
910                 return this.pushStack( jQuery.unique(ret) );
911         };
912 });
913
914 jQuery.each({
915         appendTo: "append",
916         prependTo: "prepend",
917         insertBefore: "before",
918         insertAfter: "after",
919         replaceAll: "replaceWith"
920 }, function(i,n){
921         jQuery.fn[ i ] = function(){
922                 var a = arguments;
923                 return this.each(function(){
924                         for ( var j = 0, al = a.length; j < al; j++ )
925                                 jQuery(a[j])[n]( this );
926                 });
927         };
928 });
929
930 jQuery.each( {
931         removeAttr: function( key ) {
932                 jQuery.attr( this, key, "" );
933                 this.removeAttribute( key );
934         },
935         addClass: function(c){
936                 jQuery.className.add(this,c);
937         },
938         removeClass: function(c){
939                 jQuery.className.remove(this,c);
940         },
941         toggleClass: function( c ){
942                 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
943         },
944         remove: function(a){
945                 if ( !a || jQuery.filter( a, [this] ).r.length )
946                         this.parentNode.removeChild( this );
947         },
948         empty: function() {
949                 while ( this.firstChild )
950                         this.removeChild( this.firstChild );
951         }
952 }, function(i,n){
953         jQuery.fn[ i ] = function() {
954                 return this.each( n, arguments );
955         };
956 });
957
958 // DEPRECATED
959 jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){
960         jQuery.fn[ n ] = function(num,fn) {
961                 return this.filter( ":" + n + "(" + num + ")", fn );
962         };
963 });
964
965 jQuery.each( [ "height", "width" ], function(i,n){
966         jQuery.fn[ n ] = function(h) {
967                 return h == undefined ?
968                         ( this.length ? jQuery.css( this[0], n ) : null ) :
969                         this.css( n, h.constructor == String ? h : h + "px" );
970         };
971 });