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