Added Mike Alsup's style/cssText fix and made a quick typeof change.
[jquery.git] / jquery / jquery.js
1 /*
2  * jQuery (jquery.com)
3  *
4  * Copyright (c) 2006 John Resig (ejohn.org)
5  * Licensed under the MIT License:
6  *   http://www.opensource.org/licenses/mit-license.php
7  *
8  * $Date$
9  * $Rev$
10  */
11
12 /* For JSLint (jslint.com): */
13 /*extern ActiveXObject Prototype setTimeout setInterval clearInterval document window XMLHttpRequest navigator*/
14
15 function $(a,c) {
16         var $a = a || $.context || document;
17         var $c = c && c.$jquery && c.get(0) || c;
18         
19         // Since we're using Prototype's $ function,
20         // be nice and have backwards compatability
21         if ( typeof Prototype != "undefined" ) {
22                 if ( $a.constructor == String ) {
23                         var re = new RegExp( "[^a-zA-Z0-9_-]" );
24                         if ( !re.test($a) ) {
25                                 $c = $c && $c.documentElement || document;
26                                 if ( $c.getElementsByTagName($a).length === 0 ) {
27                                         var obj = $c.getElementById($a);
28                                         if ( obj ) { return obj; }
29                                 }
30                         }
31                 } else if ( $a.constructor == Array ) {
32                         return $.map( $a, function(b){
33                                 if ( b.constructor == String ) {
34                                         return document.getElementById(b);
35                                 }
36                                 return b;
37                         });
38                 }
39         }
40
41         // Load Dynamic Function List
42         var self = {
43                 cur: $.Select($a,$c),
44                 $jquery: "$Rev$",
45                 
46                 // The only two getters
47                 size: function() {return this.get().length;},
48                 get: function(i) {
49                         return typeof i == 'undefined' ? this.cur : this.cur[i];
50                 },
51                 
52                 each: function(f) {
53                         for ( var i = 0; i < this.size(); i++ ) {
54                                 $.apply( this.get(i), f, [i] );
55                         }
56                         return this;
57                 },
58                 set: function(a,b) {
59                         return this.each(function(){
60                                 if ( typeof b == 'undefined' ) {
61                                         for ( var j in a ) {
62                                                 $.attr(this,j,a[j]);
63                                         }
64                                 } else {
65                                         $.attr(this,a,b);
66                                 }
67                         });
68                 },
69                 html: function(h) {
70                         return typeof h == 'undefined' && this.size() ?
71                                 this.get(0).innerHTML : this.set( "innerHTML", h );
72                 },
73                 val: function(h) {
74                         return typeof h == 'undefined' && this.size() ?
75                                 this.get(0).value : this.set( "value", h );
76                 },
77                 
78                 css: function(a,b) {
79                         return  a.constructor != String || b ?
80                                 this.each(function(){
81                                         if ( !b ) {
82                                                 for ( var j in a ) {
83                                                         $.attr(this.style,j,a[j]);
84                                                 }
85                                         } else {
86                                                 $.attr(this.style,a,b);
87                                         }
88                                 }) : $.css( this.get(0), a );
89                 },
90                 toggle: function() {
91                         return this.each(function(){
92                                 var d = $.getCSS(this,"display");
93                                 if ( d == "none" || d === '' ) {
94                                         $(this).show();
95                                 } else {
96                                         $(this).hide();
97                                 }
98                         });
99                 },
100                 show: function(a) {
101                         return this.each(function(){
102                                 this.style.display = this.$$oldblock ? this.$$oldblock : '';
103                                 if ( $.getCSS(this,"display") == "none" ) {
104                                         this.style.display = 'block';
105                                 }
106                         });
107                 },
108                 hide: function(a) {
109                         return this.each(function(){
110                                 this.$$oldblock = $.getCSS(this,"display");
111                                 if ( this.$$oldblock == "none" ) {
112                                         this.$$oldblock = 'block';
113                                 }
114                                 this.style.display = 'none';
115                         });
116                 },
117                 addClass: function(c) {
118                         return this.each(function(){
119                                 if ($.hasWord(this,c)) {
120                                         return null;
121                                 }
122                                 this.className += ( this.className.length > 0 ? " " : "" ) + c;
123                         });
124                 },
125                 removeClass: function(c) {
126                         return this.each(function(){
127                                 this.className = !c ? '' :
128                                         this.className.replace(
129                                                 new RegExp('(^|\\s*\\b[^-])'+c+'($|\\b(?=[^-]))', 'g'), '');
130                         });
131                 },
132                 // TODO: Optomize
133                 toggleClass: function(c) {
134                         return this.each(function(){
135                                 if ($.hasWord(this,c)) {
136                                         this.className = 
137                                                 this.className.replace(
138                                                         new RegExp('(\\s*\\b[^-])'+c+'($|\\b(?=[^-]))', 'g'), '');
139                                 } else {
140                                         this.className += ( this.className.length > 0 ? " " : "" ) + c;
141                                 }
142                         });
143                 },
144                 remove: function() {
145                         this.each(function(){this.parentNode.removeChild( this );});
146                         this.cur = [];
147                         return this;
148                 },
149                 
150                 wrap: function() {
151                         var a = $.clean(arguments);
152                         return this.each(function(){
153                                 var b = a[0].cloneNode(true);
154                                 this.parentNode.insertBefore( b, this );
155                                 while ( b.firstChild ) {
156                                         b = b.firstChild;
157                                 }
158                                 b.appendChild( this );
159                         });
160                 },
161                 
162                 append: function() {
163                         var clone = this.size() > 1;
164                         var a = $.clean(arguments);
165                         return this.each(function(){
166                                 for ( var i = 0; i < a.length; i++ ) {
167                                   this.appendChild( clone ? a[i].cloneNode(true) : a[i] );
168                                 }
169                         });
170                 },
171
172                 appendTo: function() {
173                         var a = arguments;
174                         return this.each(function(){
175                                 for ( var i = 0; i < a.length; i++ ) {
176                                         $(a[i]).append( this );
177                                 }
178                         });
179                 },
180                 
181                 prepend: function() {
182                         var clone = this.size() > 1;
183                         var a = $.clean(arguments);
184                         return this.each(function(){
185                                 for ( var i = a.length - 1; i >= 0; i-- ) {
186                                         this.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.firstChild );
187                                 }
188                         });
189                 },
190                 
191                 before: function() {
192                         var clone = this.size() > 1;
193                         var a = $.clean(arguments);
194                         return this.each(function(){
195                                 for ( var i = 0; i < a.length; i++ ) {
196                                         this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this );
197                                 }
198                         });
199                 },
200                 
201                 after: function() {
202                         var clone = this.size() > 1;
203                         var a = $.clean(arguments);
204                         return this.each(function(){
205                                 for ( var i = a.length - 1; i >= 0; i-- ) {
206                                         this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.nextSibling );
207                                 }
208                         });
209                 },
210
211                 empty: function() {
212                         return this.each(function(){
213                                 while ( this.firstChild ) {
214                                         this.removeChild( this.firstChild );
215                                 }
216                         });
217                 },
218                 
219                 bind: function(t,f) {
220                         return this.each(function(){$.event.add(this,t,f);});
221                 },
222                 unbind: function(t,f) {
223                         return this.each(function(){$.event.remove(this,t,f);});
224                 },
225                 trigger: function(t) {
226                         return this.each(function(){$.event.trigger(this,t);});
227                 },
228                 
229                 find: function(t) {
230                         var old = [], ret = [];
231                         this.each(function(){
232                                 old[old.length] = this;
233                                 ret = $.merge( ret, $.Select(t,this) );
234                         });
235                         this.old = old;
236                         this.cur = ret;
237                         return this;
238                 },
239                 end: function() {
240                         this.cur = this.old;
241                         return this;
242                 },
243
244                 parent: function(a) {
245                         this.cur = $.map(this.cur,function(d){
246                                 return d.parentNode;
247                         });
248                         if ( a ) {
249                                 this.cur = $.filter(a,this.cur).r;
250                         }
251                         return this;
252                 },
253                 
254                 parents: function(a) {
255                         this.cur = $.map(this.cur,$.parents);
256                         if ( a ) {
257                                 this.cur = $.filter(a,this.cur).r;
258                         }
259                         return this;
260                 },
261                 
262                 siblings: function(a) {
263                         // Incorrect, need to exclude current element
264                         this.cur = $.map(this.cur,$.sibling);
265                         if ( a ) {
266                                 this.cur = $.filter(a,this.cur).r;
267                         }
268                         return this;
269                 },
270                 
271                 filter: function(t) {
272                         this.cur = $.filter(t,this.cur).r;
273                         return this;
274                 },
275                 not: function(t) {
276                         this.cur = t.constructor == String ?
277                                 $.filter(t,this.cur,false).r :
278                                 $.grep(this.cur,function(a){return a != t;});
279                         return this;
280                 },
281                 add: function(t) {
282                         this.cur = $.merge( this.cur, t.constructor == String ?
283                                 $.Select(t) : t.constructor == Array ? t : [t] );
284                         return this;
285                 },
286                 is: function(t) {
287                         return $.filter(t,this.cur).r.length > 0;
288                 },
289                 isNot: function(t) {
290                         return !this.s(t);
291                 }
292         };
293         
294         // TODO: Remove need to return this
295         for ( var i in $.fn ) {
296                 if ( self[i] !== null ) {
297                         self["_"+i] = self[i];
298                 }
299                 self[i] = $.fn[i];
300         }
301         
302         if ( typeof Prototype != "undefined" && $a.constructor != String ) {
303                 if ( $c ) {
304                         $a = self.get();
305                 }
306                 for ( var k in self ) {(function(j){
307                         try {
308                                 if ( !$a[j] ) {
309                                         $a[j] = function() {
310                                                 return $.apply(self,self[j],arguments);
311                                         };
312                                 }
313                         } catch(e) {}
314                 })(k);}
315                 return $a;
316         }
317         
318         return self;
319 }
320
321 (function(){
322         var b = navigator.userAgent.toLowerCase();
323         $.browser =
324                 ( /safari/.test(b) && "safari" ) ||
325                 ( /opera/.test(b) && "opera" ) ||
326                 ( /msie/.test(b) && "msie" ) ||
327                 ( !/compatible/.test(b) && "mozilla" ) ||
328                 "other";
329 })();
330
331 $.apply = function(o,f,a) {
332         a = a || [];
333         if ( f.apply ) {
334                 return f.apply( o, a );
335         } else {
336                 var p = [];
337                 for (var i = 0; i < a.length; i++) {
338                         p[i] = 'a['+i+']';
339                 }
340                 o.$$exec = this;
341                 var r = eval('o.$$exec(' + p.join(',') + ')');
342                 o.$$exec = null;
343                 return r;
344         }
345 };
346
347 $.getCSS = function(e,p) {
348         // Adapted from Prototype 1.4.0
349         if ( p == 'height' || p == 'width' ) {
350                 if ($.getCSS(e,"display") != 'none') {
351                         return p == 'height' ?
352                                 e.offsetHeight || parseInt(e.style.height,10) : 
353                                 e.offsetWidth || parseInt(e.style.width,10);
354                 }
355                 var els = e.style;
356                 var ov = els.visibility;
357                 var op = els.position;
358                 var od = els.display;
359                 els.visibility = 'hidden';
360                 els.position = 'absolute';
361                 els.display = '';
362                 var oHeight = e.clientHeight || parseInt(e.style.height,10);
363                 var oWidth = e.clientWidth || parseInt(e.style.width,10);
364                 els.display = od;
365                 els.position = op;
366                 els.visibility = ov;
367                 return p == 'height' ? oHeight : oWidth;
368         }
369         
370         if (e.style[p]) {
371                 return e.style[p];
372         } else if (e.currentStyle) {
373                 return e.currentStyle[p];
374         } else if (document.defaultView && document.defaultView.getComputedStyle) {
375                 p = p.replace(/([A-Z])/g,"-$1");
376                 p = p.toLowerCase();
377                 var s = document.defaultView.getComputedStyle(e,"");
378                 var r = s ? s.getPropertyValue(p) : p;
379                 return r;
380         } else {
381                 return null;
382         }
383 };
384 $.css = $.getCSS;
385
386 $.clean = function(a) {
387         var r = [];
388         for ( var i = 0; i < a.length; i++ ) {
389                 if ( a[i].constructor == String ) {
390                         if ( a[i].indexOf("<tr") == 0 ) {
391 //alert("tr");
392                                 var tr = true;
393                                 a[i] = "<table>" + a[i] + "</table>";
394                         }
395                         var div = document.createElement("div");
396                         div.innerHTML = a[i];
397                         if ( tr ) {
398                                 div = div.firstChild.firstChild;
399                         }
400                         for ( var j = 0; j < div.childNodes.length; j++ ) {
401                                 r[r.length] = div.childNodes[j];
402                         }
403                 } else if ( a[i].length ) {
404                         for ( var k = 0; k < a[i].length; k++ ) {
405                                 r[r.length] = a[i][k];
406                         }
407                 } else if ( a[i] !== null ) {
408                         r[r.length] = 
409                                 a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
410                 }
411         }
412         return r;
413 };
414
415 $.g = {
416         '': "m[2] == '*' || a.nodeName.toUpperCase() == m[2].toUpperCase()",
417         '#': "a.attributes['id'].nodeValue == m[2]",
418         ':': {
419                 lt: "i < m[3]-0",
420                 gt: "i > m[3]-0",
421                 nth: "m[3] - 0 == i",
422                 eq: "m[3] - 0 == i",
423                 first: "i == 0",
424                 last: "i == r.length - 1",
425                 even: "i % 2 == 0",
426                 odd: "i % 2 == 1",
427                 "first-child": "$.sibling(a,0).cur",
428                 "nth-child": "(m[3] == 'even'?$.sibling(a,m[3]).n % 2 == 0 :(m[3] == 'odd'?$.sibling(a,m[3]).n % 2 == 1:$.sibling(a,m[3]).cur))",
429                 "last-child": "$.sibling(a,0,true).cur",
430                 "nth-last-child": "$.sibling(a,m[3],true).cur",
431                 "first-of-type": "$.ofType(a,0)",
432                 "nth-of-type": "$.ofType(a,m[3])",
433                 "last-of-type": "$.ofType(a,0,true)",
434                 "nth-last-of-type": "$.ofType(a,m[3],true)",
435                 "only-of-type": "$.ofType(a) == 1",
436                 "only-child": "$.sibling(a).length == 1",
437                 parent: "a.childNodes.length > 0",
438                 empty: "a.childNodes.length == 0",
439                 root: "a == ( a.ownerDocument ? a.ownerDocument : document ).documentElement",
440                 contains: "(a.innerText || a.innerHTML).indexOf(m[3]) != -1",
441                 visible: "(!a.type || a.type != 'hidden') && ($.getCSS(a,'display') != 'none' && $.getCSS(a,'visibility') != 'hidden')",
442                 hidden: "(a.type && a.type == 'hidden') || $.getCSS(a,'display') == 'none' || $.getCSS(a,'visibility') == 'hidden'",
443                 enabled: "a.disabled == false",
444                 disabled: "a.disabled",
445                 checked: "a.checked"
446         },
447         // TODO: Write getAttribute helper
448         ".": "$.hasWord(a,m[2])",
449         "@": {
450                 "=": "$.attr(a,m[3]) == m[4]",
451                 "!=": "$.attr(a,m[3]) != m[4]",
452                 "~=": "$.hasWord($.attr(a,m[3]),m[4])",
453                 "|=": "$.attr(a,m[3]).indexOf(m[4]) == 0",
454                 "^=": "$.attr(a,m[3]).indexOf(m[4]) == 0",
455                 "$=": "$.attr(a,m[3]).substr( $.attr(a,m[3]).length - m[4].length, m[4].length ) == m[4]",
456                 "*=": "$.attr(a,m[3]).indexOf(m[4]) >= 0",
457                 "": "m[3] == '*' ? a.attributes.length > 0 : $.attr(a,m[3])"
458         },
459         "[": "$.Select(m[2],a).length > 0"
460 };
461
462 $.fn = {};
463
464 $.Select = function( t, context ) {
465         context = context || $.context || document;
466         if ( t.constructor != String ) {
467                 return [t];
468         }
469         
470         if ( t.indexOf("//") === 0 ) {
471                 context = context.documentElement;
472                 t = t.substr(2,t.length);
473         } else if ( t.indexOf("/") === 0 ) {
474                 context = context.documentElement;
475                 t = t.substr(1,t.length);
476                 // FIX Assume the root element is right :(
477                 if ( t.indexOf('/') ) {
478                         t = t.substr(t.indexOf('/'),t.length);
479                 }
480         }
481         
482         var ret = [context];
483         var done = [];
484         var last = null;
485   
486         while ( t.length > 0 && last != t ) {
487     var r = [];
488                 last = t;
489             
490     t = $.cleanSpaces(t);
491             
492     var re = new RegExp( "^//", "i" );
493     t = t.replace( re, "" );
494         
495                 if ( t.indexOf('..') === 0 || t.indexOf('/..') === 0 ) {
496                         if ( t.indexOf('/') === 0 ) {
497                                 t = t.substr(1,t.length);
498                         }
499                         r = $.map( ret, function(a){ return a.parentNode; } );
500                         t = t.substr(2,t.length);
501                         t = $.cleanSpaces(t);
502                 } else if ( t.indexOf('>') === 0 || t.indexOf('/') === 0 ) {
503                         r = $.map( ret, function(a){ return ( a.childNodes.length > 0 ? $.sibling( a.firstChild ) : null ); } );
504                         t = t.substr(1,t.length);
505                         t = $.cleanSpaces(t);
506                 } else if ( t.indexOf('+') === 0 ) {
507                         r = $.map( ret, function(a){ return $.sibling(a).next; } );
508                         t = t.substr(1,t.length);
509                         t = $.cleanSpaces(t);
510                 } else if ( t.indexOf('~') === 0 ) {
511                         r = $.map( ret, function(a){
512                                 var r = [];
513                                 var s = $.sibling(a);
514                                 if ( s.n > 0 ) {
515                                         for ( var i = s.n; i < s.length; i++ ) {
516                                                 r[r.length] = s[i];
517                                         }
518                                 }
519                                 return r;
520                         });
521                         t = t.substr(1,t.length);
522                         t = $.cleanSpaces(t);
523                 } else if ( t.indexOf(',') === 0 || t.indexOf('|') === 0 ) {
524                         if ( ret[0] == context ) { ret.shift(); }
525                         done = $.merge( done, ret );
526                         r = ret = [context];
527                         t = " " + t.substr(1,t.length);
528                 } else {
529                         var re2 = new RegExp( "^([#.]?)([a-z0-9\\*_-]*)", "i" );
530                         var m = re2.exec(t);
531                         
532                         if ( m[1] == "#" ) { // Ummm, should make this work in all XML docs
533                                 var oid = document.getElementById(m[2]);
534                                 r = ret = oid ? [oid] : [];
535                                 t = t.replace( re2, "" );
536                         } else {
537                                 if ( m[2] === "" || m[1] == "." ) { m[2] = "*"; }
538         
539                                 for ( var i = 0; i < ret.length; i++ ) {
540                                         var o = ret[i];
541                                         if ( o ) {
542                                                 switch( m[2] ) {
543                                                         case '*':
544                                                                 r = $.merge( $.getAll(o), r );
545                                                         break;
546                                                         case 'text': case 'radio': case 'checkbox': case 'hidden':
547                                                         case 'button': case 'submit': case 'image': case 'password':
548                                                         case 'reset': case 'file':
549                                                                 r = $.merge( $.grep( $.tag(o,"input"), 
550                                                                         function(a){ return a.type == m[2]; }), r );
551                                                         break;
552                                                         case 'input':
553                                                                 r = $.merge( $.tag(o,"input"), r );
554                                                                 r = $.merge( $.tag(o,"select"), r );
555                                                                 r = $.merge( $.tag(o,"textarea"), r );
556                                                         break;
557                                                         default:
558                                                                 r = $.merge( r, $.tag(o,m[2]) );
559                                                         break;
560                                                 }
561                                         }
562                                 }
563                         }
564                 }
565
566                 if ( t ) {
567                         var val = $.filter(t,r);
568                         ret = r = val.r;
569                         t = $.cleanSpaces(val.t);
570                 }
571         }
572
573         if ( ret && ret[0] == context ) { ret.shift(); }
574         done = $.merge( done, ret );
575
576         return done;
577 };
578
579 $.tag = function(a,b){
580         return a && a.getElementsByTagName ?
581                 a.getElementsByTagName( b ) : [];
582 };
583
584 $.attr = function(o,a,v){
585         if ( a && a.constructor == String ) {
586                 var fix = {
587                         'for': 'htmlFor',
588                         'text': 'cssText',
589                         'class': 'className',
590                         'float': 'cssFloat',
591                         'style': 'cssText'
592                 };
593                 a = (fix[a] && fix[a].replace && fix[a]) || a;
594                 var r = new RegExp("-([a-z])","ig");
595                 a = a.replace(r,function(z,b){return b.toUpperCase();});
596                 if ( typeof v != 'undefined' ) {
597                         o[a] = v;
598                         if ( o.setAttribute ) {
599                                 o.setAttribute(a,v);
600                         }
601                 } 
602                 return o[a] || o.getAttribute(a) || '';
603         } else {
604                 return '';
605         }
606 };
607
608 $.filter = function(t,r,not) {
609         var g = $.grep;
610         if ( not === false ) {
611                 g = function(a,f) {return $.grep(a,f,true);};
612         }
613         
614         while ( t.length > 0 && t.match(/^[:\\.#\\[a-zA-Z\\*]/) ) {
615                 var re = new RegExp( "^\\[ *@([a-z0-9\\(\\)_-]+) *([~!\\|\\*$^=]*) *'?\"?([^'\"]*)'?\"? *\\]", "i" );
616                 var m = re.exec(t);
617                 
618                 if ( m !== null ) {
619                         m = ['', '@', m[2], m[1], m[3]];
620                 } else {
621                         re = new RegExp( "^(\\[) *([^\\]]*) *\\]", "i" );
622                         m = re.exec(t);
623                         
624                         if ( m === null ) {
625                                 re = new RegExp( "^(:)([a-z0-9\\*_-]*)\\( *[\"']?([^ \\)'\"]*)['\"]? *\\)", "i" );
626                                 m = re.exec(t);
627                                 
628                                 if ( m === null ) {
629                                         re = new RegExp( "^([:\\.#]*)([a-z0-9\\*_-]*)", "i" );
630                                         m = re.exec(t);
631                                 }
632                         }
633                 }
634                 t = t.replace( re, "" );
635                 
636                 if ( m[1] == ":" && m[2] == "not" ) {
637                         r = $.filter(m[3],r,false).r;
638                 } else {
639                         var f = null;
640
641                         if ( $.g[m[1]].constructor == String ) {
642                                 f = $.g[m[1]];
643                         } else if ( $.g[m[1]][m[2]] ) {
644                                 f = $.g[m[1]][m[2]];
645                         }
646                                                 
647                         if ( f !== null ) {
648                                 eval('f = function(a,i){return ' + f + '}');
649                                 r = g( r, f );
650                         }
651                 }
652         }
653
654         return { r: r, t: t };
655 };
656
657 $.parents = function(a){
658         var b = [];
659         var c = a.parentNode;
660         while ( c !== null && c != document ) {
661                 b[b.length] = c;
662                 c = c.parentNode;
663         }
664         return b;
665 };
666
667 $.cleanSpaces = function(t){
668         return t.replace(/^\s+|\s+$/g, '');
669 };
670
671 $.ofType = function(a,n,e) {
672         var t = $.grep($.sibling(a),function(b){return b.nodeName == a.nodeName;});
673         if ( e ) { n = t.length - n - 1; }
674         return typeof n != 'undefined' ? t[n] == a : t.length;
675 };
676
677 $.sibling = function(a,n,e) {
678         var type = [];
679         var tmp = a.parentNode.childNodes;
680         for ( var i = 0; i < tmp.length; i++ ) {
681                 if ( tmp[i].nodeType == 1 ) {
682                         type[type.length] = tmp[i];
683                 }
684                 if ( tmp[i] == a ) {
685                         type.n = type.length - 1;
686                 }
687         }
688         if ( e ) { n = type.length - n - 1; }
689         type.cur = ( type[n] == a );
690         type.prev = ( type.n > 0 ? type[type.n - 1] : null );
691         type.next = ( type.n < type.length - 1 ? type[type.n + 1] : null );
692         return type;
693 };
694
695 $.hasWord = function(e,a) {
696         if ( typeof e == 'undefined' ) { return false; }
697         if ( e.className !== null ) { e = e.className; }
698         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
699 };
700
701 $.getAll = function(o,r) {
702         r = r || [];
703         var s = o.childNodes;
704         for ( var i = 0; i < s.length; i++ ) {
705                 if ( s[i].nodeType == 1 ) {
706                         r[r.length] = s[i];
707                         $.getAll( s[i], r );
708                 }
709         }
710         return r;
711 };
712
713 $.merge = function(a,b) {
714         var d = [];
715         for ( var k = 0; k < b.length; k++ ) { d[k] = b[k]; }
716         
717         for ( var i = 0; i < a.length; i++ ) {
718                 var c = true;
719                 for ( var j = 0; j < b.length; j++ ) {
720                         if ( a[i] == b[j] ) {
721                                 c = false;
722                         }
723                 }
724                 if ( c ) {
725                         d[d.length] = a[i];
726                 }
727         }
728
729         return d;
730 };
731
732 $.grep = function(a,f,s) {
733         var r = [];
734         if ( typeof a != 'undefined' ) {
735                 for ( var i = 0; i < a.length; i++ ) {
736                         if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) ) {
737                                 r[r.length] = a[i];
738                         }
739                 }
740         }
741         return r;
742 };
743
744 $.map = function(a,f) {
745         var r = [];
746         for ( var i = 0; i < a.length; i++ ) {
747                 var t = f(a[i],i);
748                 if ( t !== null ) {
749                         if ( t.constructor != Array ) { t = [t]; }
750                         r = $.merge( t, r );
751                 }
752         }
753         return r;
754 };
755
756 $.event = {};
757
758 // Bind an event to an element
759 // Original by Dean Edwards
760 $.event.add = function(element, type, handler) {
761         if ( element.location ) { element = window; } // Ughhhhh....
762         if (!handler.$$guid) { handler.$$guid = $.event.add.guid++; }
763         if (!element.events) { element.events = {}; }
764         var handlers = element.events[type];
765         if (!handlers) {
766                 handlers = element.events[type] = {};
767                 if (element["on" + type]) {
768                         handlers[0] = element["on" + type];
769                 }
770         }
771         handlers[handler.$$guid] = handler;
772         element["on" + type] = $.event.handle;
773 };
774
775 $.event.add.guid = 1;
776
777 // Detach an event or set of events from an element
778 $.event.remove = function(element, type, handler) {
779         if (element.events) {
780                 if (type && element.events[type]) {
781                         if ( handler ) {
782                                 delete element.events[type][handler.$$guid];
783                         } else {
784                                 for ( var i in element.events[type] ) {
785                                         delete element.events[type][i];
786                                 }
787                         }
788                 } else {
789                         for ( var j in element.events ) {
790                                 $.event.remove( element, j );
791                         }
792                 }
793         }
794 };
795
796 $.event.trigger = function(element,type,data) {
797         data = data || [{ type: type }];
798         if ( element && element["on" + type] ) {
799                 $.apply( element, element["on" + type], data );
800         }
801 };
802
803 $.event.handle = function(event) {
804         if ( !event && !window.event ) { return null; }
805
806         var returnValue = true, handlers = [];
807         event = event || $.event.fix(window.event);
808
809         for ( var j in this.events[event.type] ) {
810                 handlers[handlers.length] = this.events[event.type][j];
811         }
812
813         for ( var i = 0; i < handlers.length; i++ ) {
814                 if ( handlers[i].constructor == Function ) {
815                         this.$$handleEvent = handlers[i];
816                         if (this.$$handleEvent(event) === false) {
817                                 event.preventDefault();
818                                 event.stopPropagation();
819                                 returnValue = false;
820                         }
821                 }
822         }
823         return returnValue;
824 };
825
826 $.event.fix = function(event) {
827         event.preventDefault = $.event.fix.preventDefault;
828         event.stopPropagation = $.event.fix.stopPropagation;
829         return event;
830 };
831
832 $.event.fix.preventDefault = function() {
833         this.returnValue = false;
834 };
835
836 $.event.fix.stopPropagation = function() {
837         this.cancelBubble = true;
838 };
839
840 // Move to module
841
842 $.fn.text = function(e) {
843         e = e || this.cur;
844         var t = "";
845         for ( var j = 0; j < e.length; j++ ) {
846                 for ( var i = 0; i < e[j].childNodes.length; i++ ) {
847                         t += e[j].childNodes[i].nodeType != 1 ?
848                                 e[j].childNodes[i].nodeValue :
849                                 $.fn.text(e[j].childNodes[i].childNodes);
850                 }
851         }
852         return t;
853 };
854
855 /*setTimeout(function(){
856         if ( typeof Prototype != "undefined" && $.g == null && $.clean == null )
857                 throw "Error: You are overwriting jQuery, please include jQuery last.";
858 }, 1000);*/