First batch of doc/commenting additions.
[jquery.git] / jquery / jquery.js
1 /*
2  * jQuery - New Wave Javascript
3  *
4  * Copyright (c) 2006 John Resig (jquery.com)
5  * Licensed under the MIT License:
6  *   http://www.opensource.org/licenses/mit-license.php
7  *
8  * $Date$
9  * $Rev$
10  */
11
12 // Global undefined variable
13 window.undefined = window.undefined;
14
15 /**
16  * Create a new jQuery Object
17  * @constructor
18  */
19 function jQuery(a,c) {
20
21         // Shortcut for document ready (because $(document).each() is silly)
22         if ( a && a.constructor == Function )
23                 return $(document).ready(a);
24
25         // Make sure t hat a selection was provided
26         a = a || jQuery.context || document;
27
28         /*
29          * Handle support for overriding other $() functions. Way too many libraries
30          * provide this function to simply ignore it and overwrite it.
31          */
32
33         // Check to see if this is a possible collision case
34         if ( jQuery._$ && !c && a.constructor == String && 
35       
36                 // Make sure that the expression is a colliding one
37                 !/[^a-zA-Z0-9_-]/.test(a) &&
38         
39                 // and that there are no elements that match it
40                 // (this is the one truly ambiguous case)
41                 !document.getElementsByTagName(a).length )
42
43                         // Use the default method, in case it works some voodoo
44                         return jQuery._$( a );
45
46         // Watch for when a jQuery object is passed as the selector
47         if ( a.jquery )
48                 return a;
49
50         // Watch for when a jQuery object is passed at the context
51         if ( c && c.jquery )
52                 return $(c.get()).find(a);
53         
54         // If the context is global, return a new object
55         if ( window == this )
56                 return new jQuery(a,c);
57
58         // Watch for when an array is passed in
59         this.get( a.constructor == Array ?
60                 // Assume that it's an array of DOM Elements
61                 a :
62
63                 // Find the matching elements and save them for later
64                 jQuery.Select( a, c ) );
65
66         var fn = arguments[ arguments.length - 1 ];
67         if ( fn && fn.constructor == Function )
68                 this.each(fn);
69 }
70
71 // Map over the $ in case of overwrite
72 if ( $ )
73         jQuery._$ = $;
74
75 // Map the jQuery namespace to the '$' one
76 var $ = jQuery;
77
78 jQuery.fn = jQuery.prototype = {
79         /**
80          * The current SVN version of jQuery.
81          *
82          * @private
83          * @property
84          * @name jquery
85          * @type String
86          */
87         jquery: "$Rev$",
88         
89         /**
90          * The number of elements currently matched.
91          *
92          * @property
93          * @name length
94          * @type Number
95          */
96         
97         /**
98          * The number of elements currently matched.
99          *
100          * @name size
101          * @type Number
102          */
103         size: function() {
104                 return this.length;
105         },
106         
107         /**
108          * Access all matched elements. This serves as a backwards-compatible
109          * way of accessing all matched elements (other than the jQuery object
110          * itself, which is, in fact, an array of elements).
111          *
112          * @name get
113          * @type Array<Element>
114          */
115          
116         /**
117          * Access a single matched element. <tt>num</tt> is used to access the 
118          * <tt>num</tt>th element matched.
119          *
120          * @name get
121          * @type Element
122          * @param Number num Access the element in the <tt>num</tt>th position.
123          */
124          
125         /**
126          * Set the jQuery object to an array of elements.
127          *
128          * @private
129          * @name get
130          * @type jQuery
131          * @param Elements elems An array of elements
132          */
133         get: function( num ) {
134                 // Watch for when an array (of elements) is passed in
135                 if ( num && num.constructor == Array ) {
136                 
137                         // Use a tricky hack to make the jQuery object
138                         // look and feel like an array
139                         this.length = 0;
140                         [].push.apply( this, num );
141                         
142                         return this;
143                 } else
144                         return num == undefined ?
145
146                                 // Return a 'clean' array
147                                 $.map( this, function(a){ return a } ) :
148
149                                 // Return just the object
150                                 this[num];
151         },
152         
153         /**
154          * Execute a function within the context of every matched element.
155          * This means that every time the passed-in function is executed
156          * (which is once for every element matched) the 'this' keyword
157          * points to the specific element.
158          *
159          * Additionally, the function, when executed, is passed a single
160          * argument representing the position of the element in the matched
161          * set.
162          *
163          * @name each
164          * @type jQuery
165          * @param Function fn A function to execute
166          */
167         each: function( fn ) {
168                 // Iterate through all of the matched elements
169                 for ( var i = 0; i < this.length; i++ )
170                 
171                         // Execute the function within the context of each element
172                         fn.apply( this[i], [i] );
173                 
174                 return this;
175         },
176         
177         /**
178          * Access a property on the first matched element.
179          * This method makes it easy to retreive a property value
180          * from the first matched element.
181          *
182          * @name attr
183          * @type Object
184          * @param String name The name of the property to access.
185          */
186          
187         /**
188          * Set a hash of key/value object properties to all matched elements.
189          * This serves as the best way to set a large number of properties
190          * on all matched elements.
191          *
192          * @name attr
193          * @type jQuery
194          * @param Hash prop A set of key/value pairs to set as object properties.
195          */
196          
197         /**
198          * Set a single property to a value, on all matched elements.
199          *
200          * @name attr
201          * @type jQuery
202          * @param String key The name of the property to set.
203          * @param Object value The value to set the property to.
204          */
205         attr: function( key, value ) {
206                 // Check to see if we're setting style values
207                 return key.constructor != String || value ?
208                         this.each(function(){
209                                 // See if we're setting a hash of styles
210                                 if ( value == undefined )
211                                         // Set all the styles
212                                         for ( var prop in key )
213                                                 jQuery.attr(
214                                                         type ? this.style : this,
215                                                         prop, key[prop]
216                                                 );
217                                 
218                                 // See if we're setting a single key/value style
219                                 else
220                                         jQuery.attr(
221                                                 type ? this.style : this,
222                                                 key, value
223                                         );
224                         }) :
225                         
226                         // Look for the case where we're accessing a style value
227                         jQuery[ type || "attr" ]( this[0], key );
228         },
229         
230         /**
231          * Access a style property on the first matched element.
232          * This method makes it easy to retreive a style property value
233          * from the first matched element.
234          *
235          * @name css
236          * @type Object
237          * @param String name The name of the property to access.
238          */
239          
240         /**
241          * Set a hash of key/value style properties to all matched elements.
242          * This serves as the best way to set a large number of style properties
243          * on all matched elements.
244          *
245          * @name css
246          * @type jQuery
247          * @param Hash prop A set of key/value pairs to set as style properties.
248          */
249          
250         /**
251          * Set a single style property to a value, on all matched elements.
252          *
253          * @name css
254          * @type jQuery
255          * @param String key The name of the property to set.
256          * @param Object value The value to set the property to.
257          */
258         css: function( key, value ) {
259                 return this.attr( key, value, "css" );
260         },
261         
262         /**
263          * Retreive the text contents of all matched elements. The result is
264          * a string that contains the combined text contents of all matched
265          * elements. This method works on both HTML and XML documents.
266          *
267          * @name text
268          * @type String
269          */
270         text: function(e) {
271                 e = e || this;
272                 var t = "";
273                 for ( var j = 0; j < e.length; j++ ) {
274                         var r = e[j].childNodes;
275                         for ( var i = 0; i < r.length; i++ )
276                                 t += r[i].nodeType != 1 ?
277                                         r[i].nodeValue : jQuery.fn.text([ r[i] ]);
278                 }
279                 return t;
280         },
281         
282         /**
283          * Set a single style property to a value, on all matched elements.
284          *
285          * @name wrap
286          * @type jQuery
287          * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
288          * @any Element elem A DOM element that will be wrapped.
289          * @any Array<Element> elems An array of elements, the first of which will be wrapped.
290          * @any Object 
291          */
292         wrap: function() {
293                 var a = jQuery.clean(arguments);
294                 return this.each(function(){
295                         var b = a[0].cloneNode(true);
296                         this.parentNode.insertBefore( b, this );
297                         while ( b.firstChild )
298                                 b = b.firstChild;
299                         b.appendChild( this );
300                 });
301         },
302         
303         append: function() {
304                 return this.domManip(arguments, true, 1, function(a){
305                         this.appendChild( 1 );
306                 });
307         },
308         
309         prepend: function() {
310                 return this.domManip(arguments, true, -1, function(a){
311                         this.insertBefore( a, this.firstChild );
312                 });
313         },
314         
315         before: function() {
316                 return this.domManip(arguments, false, 1, function(a){
317                         this.parentNode.insertBefore( a, this );
318                 });
319         },
320         
321         after: function() {
322                 return this.domManip(arguments, false, -1, function(a){
323                         this.parentNode.insertBefore( a, this.nextSibling );
324                 });
325         },
326         
327         /**
328          * A wrapper function for each() to be used by append and prepend.
329          * Handles cases where you're trying to modify the inner contents of
330          * a table, when you actually need to work with the tbody.
331          *
332          * @private
333          * @member jQuery
334          * @param {Function} fn The function doing the DOM manipulation.
335          * @type jQuery
336          */
337         domManip: function(args, table, dir, fn){
338                 var clone = this.size() > 1;
339                 var a = jQuery.clean(args);
340                 
341                 return this.each(function(){
342                         var obj = this;
343                         
344                         if ( table && this.nodeName == "TABLE" ) {
345                                 var tbody = this.getElementsByTagName("tbody");
346
347                                 if ( !tbody.length ) {
348                                         obj = document.createElement("tbody");
349                                         this.appendChild( obj );
350                                 } else
351                                         obj = tbody[0];
352                         }
353         
354                         for ( var i = ( dir < 0 ? a.length - 1 : 0 );
355                                 i != ( dir < 0 ? dir : a.length ); i += dir )
356                                         fn.apply( obj, [ a[i] ] );
357                 });
358         },
359         
360         pushStack: function(a,args) {
361                 var fn = args && args[args.length-1];
362
363                 if ( !fn || fn.constructor != Function ) {
364                         if ( !this.stack ) this.stack = [];
365                         this.stack.push( this.get() );
366                         this.get( a );
367                 } else {
368                         var old = this.get();
369                         this.get( a );
370                         if ( fn.constructor == Function )
371                                 return this.each( fn );
372                         this.get( old );
373                 }
374
375                 return this;
376         },
377
378         end: function() {
379                 this.get( this.stack.pop() );
380                 return this;
381         },
382         
383         find: function(t) {
384                 return this.pushStack( jQuery.map( this, function(a){
385                         return jQuery.Select(t,a);
386                 }), arguments );
387         },
388         
389         filter: function(t) {
390                 return t.constructor == Array ?
391                         // Multi Filtering
392                         this.pushStack( jQuery.map(this,function(a){
393                                 for ( var i = 0; i < t.length; i++ )
394                                         if ( jQuery.filter(t[i],[a]).r.length )
395                                                 return a;
396                         }), arguments ) :
397                         
398                         this.pushStack( jQuery.filter(t,this).r, arguments );
399         },
400         not: function(t) {
401                 return this.pushStack( t.constructor == String ?
402                         jQuery.filter(t,this,false).r :
403                         jQuery.grep(this,function(a){ return a != t; }), arguments );
404         },
405         add: function(t) {
406                 return this.pushStack( jQuery.merge( this, t.constructor == String ?
407                         jQuery.Select(t) : t.constructor == Array ? t : [t] ), arguments );
408         },
409         
410         /**
411          * A wrapper function for each() to be used by append and prepend.
412          * Handles cases where you're trying to modify the inner contents of
413          * a table, when you actually need to work with the tbody.
414          *
415          * @member jQuery
416          * @param {String} expr The expression with which to filter
417          * @type Boolean
418          */
419         is: function(expr) {
420                 return jQuery.filter(expr,this).r.length > 0;
421         }
422 };
423
424 (function(){
425         var b = navigator.userAgent.toLowerCase();
426
427         // Figure out what browser is being used
428         jQuery.browser =
429                 ( /webkit/.test(b) && "safari" ) ||
430                 ( /opera/.test(b) && "opera" ) ||
431                 ( /msie/.test(b) && "msie" ) ||
432                 ( !/compatible/.test(b) && "mozilla" ) ||
433                 "other";
434
435         // Check to see if the W3C box model is being used
436         jQuery.boxModel = ( jQuery.browser != "msie" || document.compatMode == "CSS1Compat" );
437
438         var axis = {
439                 parent: "a.parentNode",
440                 parents: jQuery.parents,
441                 ancestors: jQuery.parents,
442                 next: "a.nextSibling",
443                 prev: "a.previousSibling",
444                 siblings: jQuery.sibling
445         };
446         
447         for ( var i in axis ) {(function(){
448                 var t = axis[i];
449                 jQuery.fn[ i ] = function(a) {
450                         var ret = jQuery.map(this,t);
451                         if ( a ) ret = jQuery.filter(a,ret).r;
452                         return this.pushStack( ret, arguments );
453                 };
454         })();}
455         
456         var to = "html,append,prepend,before,after".split(',');
457         
458         for ( var i = 0; i < to.length; i++ ) {(function(){
459                 var n = to[i];
460                 jQuery.fn[ n + "To" ] = function(){
461                         var a = arguments;
462                         return this.each(function(){
463                                 for ( var i = 0; i < a.length; i++ )
464                                         $(a[i])[n]( this );
465                         });
466                 };
467         })();}
468         
469         var each = {
470                 show: function(){
471                         this.style.display = this.oldblock ? this.oldblock : "";
472                         if ( jQuery.css(this,"display") == "none" )
473                                 this.style.display = "block";
474                 },
475                 
476                 hide: function(){
477                         this.oldblock = jQuery.css(this,"display");
478                         if ( this.oldblock == "none" )
479                                 this.oldblock = "block";
480                         this.style.display = "none";
481                 },
482                 
483                 toggle: function(){
484                         var d = jQuery.css(this,"display");
485                         $(this)[ !d || d == "none" ? 'show' : 'hide' ]();
486                 },
487                 
488                 addClass: function(c){
489                         jQuery.className.add(this,c);
490                 },
491                 
492                 removeClass: function(c){
493                         jQuery.className.remove(this,c);
494                 },
495         
496                 toggleClass: function( c ){
497                         jQuery.className[ jQuery.hasWord(this,a) ? 'remove' : 'add' ](this,c);
498                 },
499                 
500                 remove: function(){
501                         this.parentNode.removeChild( this );
502                 },
503         
504                 empty: function(){
505                         while ( this.firstChild )
506                                 this.removeChild( this.firstChild );
507                 },
508                 
509                 bind: function( type, fn ) {
510                         jQuery.event.add( this, type, fn );
511                 },
512                 
513                 unbind: function( type, fn ) {
514                         jQuery.event.remove( this, type, fn );
515                 },
516                 
517                 trigger: function( type ) {
518                         jQuery.event.trigger( this, type );
519                 },
520         };
521         
522         for ( var i in each ) {(function(){
523                 var n = each[i];
524                 jQuery.fn[ i ] = function(a,b) {
525                         var a = arguments;
526                         return this.each(function(){
527                                 n.apply( this, a );
528                         });
529                 };
530         })();}
531         
532         var attr = {
533                 val: 'value',
534                 html: 'innerHTML'
535         };
536         
537         for ( var i in attr ) {(function(){
538                 var n = attr[i];
539                 jQuery.fn[ i ] = function(h) {
540                         return h == undefined && this.length ?
541                                 this[0][n] : this.set( n, h );
542                 };
543         })();}
544
545 })();
546
547 jQuery.className = {
548         add: function(o,c){
549                 if (jQuery.hasWord(o,c)) return;
550                 o.className += ( o.className ? " " : "" ) + c;
551         },
552         remove: function(o,c){
553                 o.className = !c ? "" :
554                         o.className.replace(
555                                 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
556         }
557 };
558
559 $.swap = function(e,o,f) {
560         for ( var i in o ) {
561                 e.style["old"+i] = e.style[i];
562                 e.style[i] = o[i];
563         }
564         f.apply( e, [] );
565         for ( var i in o )
566                 e.style[i] = e.style["old"+i];
567 };
568
569 jQuery.css = function(e,p) {
570         // Adapted from Prototype 1.4.0
571         if ( p == "height" || p == "width" ) {
572                 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
573
574                 for ( var i in d ) {
575                         old["padding" + d[i]] = 0;
576                         old["border" + d[i] + "Width"] = 0;
577                 }
578
579                 $.swap( e, old, function() {
580                         if (jQuery.css(e,"display") != 'none') {
581                                 oHeight = e.offsetHeight;
582                                 oWidth = e.offsetWidth;
583                         } else
584                                 $.swap( e, { visibility: 'hidden', position: 'absolute', display: '' },
585                                         function(){
586                                                 oHeight = e.clientHeight;
587                                                 oWidth = e.clientWidth;
588                                         });
589                 });
590
591                 return p == "height" ? oHeight : oWidth;
592         }
593         
594         var r;
595
596         if (e.style[p])
597                 r = e.style[p];
598         else if (e.currentStyle)
599                 r = e.currentStyle[p];
600         else if (document.defaultView && document.defaultView.getComputedStyle) {
601                 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
602                 var s = document.defaultView.getComputedStyle(e,"");
603                 r = s ? s.getPropertyValue(p) : null;
604         }
605         
606         return r;
607 };
608
609 jQuery.clean = function(a) {
610         var r = [];
611         for ( var i = 0; i < a.length; i++ ) {
612                 if ( a[i].constructor == String ) {
613
614                         if ( !a[i].indexOf("<tr") ) {
615                                 var tr = true;
616                                 a[i] = "<table>" + a[i] + "</table>";
617                         } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
618                                 var td = true;
619                                 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
620                         }
621
622                         var div = document.createElement("div");
623                         div.innerHTML = a[i];
624
625                         if ( tr || td ) {
626                                 div = div.firstChild.firstChild;
627                                 if ( td ) div = div.firstChild;
628                         }
629
630                         for ( var j = 0; j < div.childNodes.length; j++ )
631                                 r[r.length] = div.childNodes[j];
632                 } else if ( a[i].length && !a[i].nodeType )
633                         for ( var k = 0; k < a[i].length; k++ )
634                                 r[r.length] = a[i][k];
635                 else if ( a[i] !== null )
636                         r[r.length] =
637                                 a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
638         }
639         return r;
640 };
641
642 jQuery.g = {
643         "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
644         "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
645         ":": {
646                 lt: "i<m[3]-0",
647                 gt: "i>m[3]-0",
648                 nth: "m[3]-0==i",
649                 eq: "m[3]-0==i",
650                 first: "i==0",
651                 last: "i==r.length-1",
652                 even: "i%2==0",
653                 odd: "i%2==1",
654                 "first-child": "jQuery.sibling(a,0).cur",
655                 "nth-child": "(m[3]=='even'?jQuery.sibling(a,m[3]).n%2==0:(m[3]=='odd'?jQuery.sibling(a,m[3]).n%2==1:jQuery.sibling(a,m[3]).cur))",
656                 "last-child": "jQuery.sibling(a,0,true).cur",
657                 "nth-last-child": "jQuery.sibling(a,m[3],true).cur",
658                 "first-of-type": "jQuery.ofType(a,0)",
659                 "nth-of-type": "jQuery.ofType(a,m[3])",
660                 "last-of-type": "jQuery.ofType(a,0,true)",
661                 "nth-last-of-type": "jQuery.ofType(a,m[3],true)",
662                 "only-of-type": "jQuery.ofType(a)==1",
663                 "only-child": "jQuery.sibling(a).length==1",
664                 parent: "a.childNodes.length",
665                 empty: "!a.childNodes.length",
666                 root: "a==(a.ownerDocument||document).documentElement",
667                 contains: "(a.innerText||a.innerHTML).indexOf(m[3])!=-1",
668                 visible: "(!a.type||a.type!='hidden')&&(jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!= 'hidden')",
669                 hidden: "(a.type&&a.type=='hidden')||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')== 'hidden'",
670                 enabled: "!a.disabled",
671                 disabled: "a.disabled",
672                 checked: "a.checked"
673         },
674         ".": "jQuery.hasWord(a,m[2])",
675         "@": {
676                 "=": "jQuery.attr(a,m[3])==m[4]",
677                 "!=": "jQuery.attr(a,m[3])!=m[4]",
678                 "~=": "jQuery.hasWord(jQuery.attr(a,m[3]),m[4])",
679                 "|=": "!jQuery.attr(a,m[3]).indexOf(m[4])",
680                 "^=": "!jQuery.attr(a,m[3]).indexOf(m[4])",
681                 "$=": "jQuery.attr(a,m[3]).substr( jQuery.attr(a,m[3]).length - m[4].length,m[4].length )==m[4]",
682                 "*=": "jQuery.attr(a,m[3]).indexOf(m[4])>=0",
683                 "": "m[3]=='*'?a.attributes.length>0:jQuery.attr(a,m[3])"
684         },
685         "[": "jQuery.Select(m[2],a).length"
686 };
687
688 jQuery.token = [
689         "\\.\\.|/\\.\\.", "a.parentNode",
690         ">|/", "jQuery.sibling(a.firstChild)",
691         "\\+", "jQuery.sibling(a).next",
692         "~", function(a){
693                 var r = [];
694                 var s = jQuery.sibling(a);
695                 if ( s.n > 0 )
696                         for ( var i = s.n; i < s.length; i++ )
697                                 r[r.length] = s[i];
698                 return r;
699         }
700 ];
701
702 jQuery.Select = function( t, context ) {
703         // Make sure that the context is a DOM Element
704         if ( context && context.getElementsByTagName == undefined )
705                 context = null;
706
707         // Set the correct context (if none is provided)
708         context = context || jQuery.context || document;
709
710         if ( t.constructor != String ) return [t];
711
712         if ( !t.indexOf("//") ) {
713                 context = context.documentElement;
714                 t = t.substr(2,t.length);
715         } else if ( !t.indexOf("/") ) {
716                 context = context.documentElement;
717                 t = t.substr(1,t.length);
718                 // FIX Assume the root element is right :(
719                 if ( t.indexOf("/") >= 1 )
720                         t = t.substr(t.indexOf("/"),t.length);
721         }
722
723         var ret = [context];
724         var done = [];
725         var last = null;
726
727         while ( t.length > 0 && last != t ) {
728                 var r = [];
729                 last = t;
730
731                 t = jQuery.cleanSpaces(t).replace( /^\/\//i, "" );
732                 
733                 var foundToken = false;
734                 
735                 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
736                         var re = new RegExp("^(" + jQuery.token[i] + ")");
737                         var m = re.exec(t);
738                         
739                         if ( m ) {
740                                 r = ret = jQuery.map( ret, jQuery.token[i+1] );
741                                 t = jQuery.cleanSpaces( t.replace( re, "" ) );
742                                 foundToken = true;
743                         }
744                 }
745                 
746                 if ( !foundToken ) {
747
748                         if ( !t.indexOf(",") || !t.indexOf("|") ) {
749                                 if ( ret[0] == context ) ret.shift();
750                                 done = jQuery.merge( done, ret );
751                                 r = ret = [context];
752                                 t = " " + t.substr(1,t.length);
753                         } else {
754                                 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
755                                 var m = re2.exec(t);
756         
757                                 if ( m[1] == "#" ) {
758                                         // Ummm, should make this work in all XML docs
759                                         var oid = document.getElementById(m[2]);
760                                         r = ret = oid ? [oid] : [];
761                                         t = t.replace( re2, "" );
762                                 } else {
763                                         if ( !m[2] || m[1] == "." ) m[2] = "*";
764         
765                                         for ( var i = 0; i < ret.length; i++ )
766                                                 r = jQuery.merge( r,
767                                                         m[2] == "*" ?
768                                                                 jQuery.getAll(ret[i]) :
769                                                                 ret[i].getElementsByTagName(m[2])
770                                                 );
771                                 }
772                         }
773                         
774                 }
775
776                 if ( t ) {
777                         var val = jQuery.filter(t,r);
778                         ret = r = val.r;
779                         t = jQuery.cleanSpaces(val.t);
780                 }
781         }
782
783         if ( ret && ret[0] == context ) ret.shift();
784         done = jQuery.merge( done, ret );
785
786         return done;
787 };
788
789 jQuery.getAll = function(o,r) {
790         r = r || [];
791         var s = o.childNodes;
792         for ( var i = 0; i < s.length; i++ )
793                 if ( s[i].nodeType == 1 ) {
794                         r[r.length] = s[i];
795                         jQuery.getAll( s[i], r );
796                 }
797         return r;
798 };
799
800 jQuery.attr = function(o,a,v){
801         if ( a && a.constructor == String ) {
802                 var fix = {
803                         "for": "htmlFor",
804                         "class": "className",
805                         "float": "cssFloat"
806                 };
807                 a = (fix[a] && fix[a].replace && fix[a]) || a;
808                 var r = /-([a-z])/ig;
809                 a = a.replace(r,function(z,b){return b.toUpperCase();});
810                 if ( v != undefined ) {
811                         o[a] = v;
812                         if ( o.setAttribute && a != "disabled" )
813                                 o.setAttribute(a,v);
814                 }
815                 return o[a] || o.getAttribute(a) || "";
816         } else
817                 return "";
818 };
819
820 jQuery.filter = function(t,r,not) {
821         var g = jQuery.grep;
822         if ( not === false )
823                 g = function(a,f) {return jQuery.grep(a,f,true);};
824
825         while ( t && t.match(/^[:\\.#\\[a-zA-Z\\*]/) ) {
826                 var re = /^\[ *@([a-z*_-][a-z0-9()_-]*) *([~!|*$^=]*) *'?"?([^'"]*)'?"? *\]/i;
827                 var m = re.exec(t);
828
829                 if ( m )
830                         m = ["", "@", m[2], m[1], m[3]];
831                 else {
832                         re = /^(\[) *([^\]]*) *\]/i;
833                         m = re.exec(t);
834
835                         if ( !m ) {
836                                 re = /^(:)([a-z0-9*_-]*)\( *["']?([^ \)'"]*)['"]? *\)/i;
837                                 m = re.exec(t);
838
839                                 if ( !m ) {
840                                         re = /^([:\.#]*)([a-z0-9*_-]*)/i;
841                                         m = re.exec(t);
842                                 }
843                         }
844                 }
845                 t = t.replace( re, "" );
846
847                 if ( m[1] == ":" && m[2] == "not" )
848                         r = jQuery.filter(m[3],r,false).r;
849                 else {
850                         var f = null;
851
852                         if ( jQuery.g[m[1]].constructor == String )
853                                 f = jQuery.g[m[1]];
854                         else if ( jQuery.g[m[1]][m[2]] )
855                                 f = jQuery.g[m[1]][m[2]];
856
857                         if ( f ) {
858                                 eval("f = function(a,i){return " + f + "}");
859                                 r = g( r, f );
860                         }
861                 }
862         }
863
864         return { r: r, t: t };
865 };
866
867 jQuery.parents = function(a){
868         var b = [];
869         var c = a.parentNode;
870         while ( c && c != document ) {
871                 b[b.length] = c;
872                 c = c.parentNode;
873         }
874         return b;
875 };
876
877 jQuery.cleanSpaces = function(t){
878         return t.replace(/^\s+|\s+$/g, "");
879 };
880
881 jQuery.ofType = function(a,n,e) {
882         var t = jQuery.grep(jQuery.sibling(a),function(b){ return b.nodeName == a.nodeName; });
883         if ( e ) n = t.length - n - 1;
884         return n != undefined ? t[n] == a : t.length;
885 };
886
887 jQuery.sibling = function(a,n,e) {
888         var type = [];
889         var tmp = a.parentNode.childNodes;
890         for ( var i = 0; i < tmp.length; i++ ) {
891                 if ( tmp[i].nodeType == 1 )
892                         type[type.length] = tmp[i];
893                 if ( tmp[i] == a )
894                         type.n = type.length - 1;
895         }
896         if ( e ) n = type.length - n - 1;
897         type.cur = type[n] == a;
898         type.next = type[type.n + 1];
899         return type;
900 };
901
902 jQuery.hasWord = function(e,a) {
903         if ( e.className )
904                 e = e.className;
905         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
906 };
907
908 jQuery.merge = function(a,b) {
909         var d = [];
910         for ( var k = 0; k < b.length; k++ ) d[k] = b[k];
911
912         for ( var i = 0; i < a.length; i++ ) {
913                 var c = true;
914                 for ( var j = 0; j < b.length; j++ )
915                         if ( a[i] == b[j] )
916                                 c = false;
917                 if ( c ) d[d.length] = a[i];
918         }
919
920         return d;
921 };
922
923 jQuery.grep = function(a,f,s) {
924         if ( f.constructor == String )
925                 f = new Function("a","i","return " + f);
926         var r = [];
927         if ( a )
928                 for ( var i = 0; i < a.length; i++ )
929                         if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) )
930                                 r[r.length] = a[i];
931         return r;
932 };
933
934 jQuery.map = function(a,f) {
935         if ( f.constructor == String )
936                 f = new Function("a","return " + f);
937         
938         var r = [];
939         for ( var i = 0; i < a.length; i++ ) {
940                 var t = f(a[i],i);
941                 if ( t !== null && t != undefined ) {
942                         if ( t.constructor != Array ) t = [t];
943                         r = jQuery.merge( t, r );
944                 }
945         }
946         return r;
947 };
948
949 jQuery.event = {
950
951         // Bind an event to an element
952         // Original by Dean Edwards
953         add: function(element, type, handler) {
954                 // For whatever reason, IE has trouble passing the window object
955                 // around, causing it to be cloned in the process
956                 if ( jQuery.browser == "msie" && element.setInterval != undefined )
957                         element = window;
958         
959                 if (!handler.guid) handler.guid = jQuery.event.guid++;
960                 if (!element.events) element.events = {};
961                 var handlers = element.events[type];
962                 if (!handlers) {
963                         handlers = element.events[type] = {};
964                         if (element["on" + type])
965                                 handlers[0] = element["on" + type];
966                 }
967                 handlers[handler.guid] = handler;
968                 element["on" + type] = this.handle;
969
970                 if (!this.global[type])
971                         this.global[type] = [];
972                 this.global[type].push( element );
973         },
974         
975         guid: 1,
976         global: {},
977         
978         // Detach an event or set of events from an element
979         remove: function(element, type, handler) {
980                 if (element.events)
981                         if (type && element.events[type])
982                                 if ( handler )
983                                         delete element.events[type][handler.guid];
984                                 else
985                                         for ( var i in element.events[type] )
986                                                 delete element.events[type][i];
987                         else
988                                 for ( var j in element.events )
989                                         this.remove( element, j );
990         },
991         
992         trigger: function(type,data,element) {
993                 // Touch up the incoming data
994                 data = data || [];
995
996                 // Handle a global trigger
997                 if ( !element ) {
998                         var g = this.global[type];
999                         if ( g )
1000                                 for ( var i = 0; i < g.length; i++ )
1001                                         this.trigger( type, data, g[i] );
1002
1003                 // Handle triggering a single element
1004                 } else if ( element["on" + type] ) {
1005                         // Pass along a fake event
1006                         data.unshift( this.fix({ type: type, target: element }) );
1007
1008                         // Trigger the event
1009                         element["on" + type].apply( element, data );
1010                 }
1011         },
1012         
1013         handle: function(event) {
1014                 // Handle adding events to items in IFrames, in IE
1015                 event = event ||
1016                         jQuery.event.fix( ((this.ownerDocument || this.document || 
1017                                 this).parentWindow || window).event );
1018
1019                 // If no correct event was found, fail
1020                 if ( !event ) return;
1021         
1022                 var returnValue = true, handlers = [];
1023         
1024                 for ( var j in this.events[event.type] )
1025                         handlers[handlers.length] = this.events[event.type][j];
1026         
1027                 for ( var i = 0; i < handlers.length; i++ )
1028                         if ( handlers[i].constructor == Function ) {
1029                                 this.handleEvent = handlers[i];
1030                                 if (this.handleEvent(event) === false) {
1031                                         event.preventDefault();
1032                                         event.stopPropagation();
1033                                         returnValue = false;
1034                                 }
1035                         }
1036                 return returnValue;
1037         },
1038         
1039         fix: function(event) {
1040                 if ( event ) {
1041                         event.preventDefault = function() {
1042                                 this.returnValue = false;
1043                         };
1044                 
1045                         event.stopPropagation = function() {
1046                                 this.cancelBubble = true;
1047                         };
1048                 }
1049                 
1050                 return event;
1051         }
1052
1053 };