IE is now forced layout if it doesn't have it (such that opacity now works as expecte...
[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.domManip(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.domManip(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
324         // Figure out what browser is being used
325         $.browser =
326                 ( /webkit/.test(b) && "safari" ) ||
327                 ( /opera/.test(b) && "opera" ) ||
328                 ( /msie/.test(b) && "msie" ) ||
329                 ( !/compatible/.test(b) && "mozilla" ) ||
330                 "other";
331
332         // Check to see if the W3C box model is being used
333         $.boxModel = ( $.browser != "msie" || 
334                 document.compatMode == "CSS1Compat" );
335 })();
336
337 $.apply = function(o,f,a) {
338         a = a || [];
339         if ( f.apply ) {
340                 return f.apply( o, a );
341         } else {
342                 var p = [];
343                 for (var i = 0; i < a.length; i++) {
344                         p[i] = 'a['+i+']';
345                 }
346                 o.$$exec = this;
347                 var r = eval('o.$$exec(' + p.join(',') + ')');
348                 o.$$exec = null;
349                 return r;
350         }
351 };
352
353 $.getCSS = function(e,p) {
354         // Adapted from Prototype 1.4.0
355         if ( p == 'height' || p == 'width' ) {
356
357                 // Handle extra width/height provided by the W3C box model
358                 var ph = !$.boxModel ? 0 : 
359                         parseInt($.css(e,"paddingTop")) + parseInt($.css(e,"paddingBottom")) +
360                         parseInt($.css(e,"borderTop")) + parseInt($.css(e,"borderBottom"));
361
362                 var pw = !$.boxModel ? 0 : 
363                         parseInt($.css(e,"paddingLeft")) + parseInt($.css(e,"paddingRight")) +
364                         parseInt($.css(e,"borderLeft")) + parseInt($.css(e,"borderRight"));
365
366                 var oHeight, oWidth;
367
368                 if ($.css(e,"display") != 'none') {
369                         oHeight = e.offsetHeight || parseInt(e.style.height,10);
370                         oWidth = e.offsetWidth || parseInt(e.style.width,10);
371                 } else {
372                         var els = e.style;
373                         var ov = els.visibility;
374                         var op = els.position;
375                         var od = els.display;
376                         els.visibility = 'hidden';
377                         els.position = 'absolute';
378                         els.display = '';
379                         oHeight = e.clientHeight || parseInt(e.style.height,10);
380                         oWidth = e.clientWidth || parseInt(e.style.width,10);
381                         els.display = od;
382                         els.position = op;
383                         els.visibility = ov;
384                 }
385
386                 return p == 'height' ?
387                         (oHeight - ph < 0 ? 0 : oHeight - ph) :
388                         (oWidth - pw < 0 ? 0 : oWidth - pw);
389         }
390         
391         if (e.style[p]) {
392                 return e.style[p];
393         } else if (e.currentStyle) {
394                 return e.currentStyle[p];
395         } else if (document.defaultView && document.defaultView.getComputedStyle) {
396                 p = p.replace(/([A-Z])/g,"-$1");
397                 p = p.toLowerCase();
398                 var s = document.defaultView.getComputedStyle(e,"");
399                 var r = s ? s.getPropertyValue(p) : p;
400                 return r;
401         } else {
402                 return null;
403         }
404 };
405 $.css = $.getCSS;
406
407 $.clean = function(a) {
408         var r = [];
409         for ( var i = 0; i < a.length; i++ ) {
410                 if ( a[i].constructor == String ) {
411
412                         if ( !a[i].indexOf("<tr") ) {
413                                 var tr = true;
414                                 a[i] = "<table>" + a[i] + "</table>";
415                         } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
416                                 var td = true;
417                                 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
418                         }
419
420                         var div = document.createElement("div");
421                         div.innerHTML = a[i];
422
423                         if ( tr || td ) {
424                                 div = div.firstChild.firstChild;
425                                 if ( td ) {
426                                         div = div.firstChild;
427                                 }
428                         }
429         
430                         for ( var j = 0; j < div.childNodes.length; j++ ) {
431                                 r[r.length] = div.childNodes[j];
432                         }
433                 } else if ( a[i].length && !a[i].nodeType ) {
434                         for ( var k = 0; k < a[i].length; k++ ) {
435                                 r[r.length] = a[i][k];
436                         }
437                 } else if ( a[i] !== null ) {
438                         r[r.length] = 
439                                 a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
440                 }
441         }
442         return r;
443 };
444
445 $.fn = {};
446
447 /**
448  * A wrapper function for each() to be used by append and prepend.
449  * Handles cases where you're trying to modify the inner contents of
450  * a table, when you actually need to work with the tbody.
451  */
452 $.fn.domManip = function(fn){
453         return this.each(function(){
454                 var obj = this;
455
456                 if ( this.nodeName == 'TABLE' ) {
457                         if ( !this.firstChild ) {
458                                 this.appendChild( document.createElement("tbody") );
459                         }
460                         obj = this.firstChild;
461                 }
462
463                 $.apply( obj, fn );
464         });
465 };
466
467 $.g = {
468         '': "m[2] == '*' || a.nodeName.toUpperCase() == m[2].toUpperCase()",
469         '#': "a.getAttribute('id') && a.getAttribute('id').nodeValue == m[2]",
470         ':': {
471                 lt: "i < m[3]-0",
472                 gt: "i > m[3]-0",
473                 nth: "m[3] - 0 == i",
474                 eq: "m[3] - 0 == i",
475                 first: "i == 0",
476                 last: "i == r.length - 1",
477                 even: "i % 2 == 0",
478                 odd: "i % 2 == 1",
479                 "first-child": "$.sibling(a,0).cur",
480                 "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))",
481                 "last-child": "$.sibling(a,0,true).cur",
482                 "nth-last-child": "$.sibling(a,m[3],true).cur",
483                 "first-of-type": "$.ofType(a,0)",
484                 "nth-of-type": "$.ofType(a,m[3])",
485                 "last-of-type": "$.ofType(a,0,true)",
486                 "nth-last-of-type": "$.ofType(a,m[3],true)",
487                 "only-of-type": "$.ofType(a) == 1",
488                 "only-child": "$.sibling(a).length == 1",
489                 parent: "a.childNodes.length > 0",
490                 empty: "a.childNodes.length == 0",
491                 root: "a == ( a.ownerDocument ? a.ownerDocument : document ).documentElement",
492                 contains: "(a.innerText || a.innerHTML).indexOf(m[3]) != -1",
493                 visible: "(!a.type || a.type != 'hidden') && ($.getCSS(a,'display') != 'none' && $.getCSS(a,'visibility') != 'hidden')",
494                 hidden: "(a.type && a.type == 'hidden') || $.getCSS(a,'display') == 'none' || $.getCSS(a,'visibility') == 'hidden'",
495                 enabled: "a.disabled == false",
496                 disabled: "a.disabled",
497                 checked: "a.checked"
498         },
499         // TODO: Write getAttribute helper
500         ".": "$.hasWord(a,m[2])",
501         "@": {
502                 "=": "$.attr(a,m[3]) == m[4]",
503                 "!=": "$.attr(a,m[3]) != m[4]",
504                 "~=": "$.hasWord($.attr(a,m[3]),m[4])",
505                 "|=": "$.attr(a,m[3]).indexOf(m[4]) == 0",
506                 "^=": "$.attr(a,m[3]).indexOf(m[4]) == 0",
507                 "$=": "$.attr(a,m[3]).substr( $.attr(a,m[3]).length - m[4].length, m[4].length ) == m[4]",
508                 "*=": "$.attr(a,m[3]).indexOf(m[4]) >= 0",
509                 "": "m[3] == '*' ? a.attributes.length > 0 : $.attr(a,m[3])"
510         },
511         "[": "$.Select(m[2],a).length > 0"
512 };
513
514 $.Select = function( t, context ) {
515         context = context || $.context || document;
516         if ( t.constructor != String ) {
517                 return [t];
518         }
519         
520         if ( t.indexOf("//") === 0 ) {
521                 context = context.documentElement;
522                 t = t.substr(2,t.length);
523         } else if ( t.indexOf("/") === 0 ) {
524                 context = context.documentElement;
525                 t = t.substr(1,t.length);
526                 // FIX Assume the root element is right :(
527                 if ( t.indexOf('/') ) {
528                         t = t.substr(t.indexOf('/'),t.length);
529                 }
530         }
531         
532         var ret = [context];
533         var done = [];
534         var last = null;
535   
536         while ( t.length > 0 && last != t ) {
537     var r = [];
538                 last = t;
539             
540     t = $.cleanSpaces(t);
541             
542     var re = new RegExp( "^//", "i" );
543     t = t.replace( re, "" );
544         
545                 if ( t.indexOf('..') === 0 || t.indexOf('/..') === 0 ) {
546                         if ( t.indexOf('/') === 0 ) {
547                                 t = t.substr(1,t.length);
548                         }
549                         r = $.map( ret, function(a){ return a.parentNode; } );
550                         t = t.substr(2,t.length);
551                         t = $.cleanSpaces(t);
552                 } else if ( t.indexOf('>') === 0 || t.indexOf('/') === 0 ) {
553                         r = $.map( ret, function(a){ return ( a.childNodes.length > 0 ? $.sibling( a.firstChild ) : null ); } );
554                         t = t.substr(1,t.length);
555                         t = $.cleanSpaces(t);
556                 } else if ( t.indexOf('+') === 0 ) {
557                         r = $.map( ret, function(a){ return $.sibling(a).next; } );
558                         t = t.substr(1,t.length);
559                         t = $.cleanSpaces(t);
560                 } else if ( t.indexOf('~') === 0 ) {
561                         r = $.map( ret, function(a){
562                                 var r = [];
563                                 var s = $.sibling(a);
564                                 if ( s.n > 0 ) {
565                                         for ( var i = s.n; i < s.length; i++ ) {
566                                                 r[r.length] = s[i];
567                                         }
568                                 }
569                                 return r;
570                         });
571                         t = t.substr(1,t.length);
572                         t = $.cleanSpaces(t);
573                 } else if ( t.indexOf(',') === 0 || t.indexOf('|') === 0 ) {
574                         if ( ret[0] == context ) { ret.shift(); }
575                         done = $.merge( done, ret );
576                         r = ret = [context];
577                         t = " " + t.substr(1,t.length);
578                 } else {
579                         var re2 = new RegExp( "^([#.]?)([a-z0-9\\*_-]*)", "i" );
580                         var m = re2.exec(t);
581                         
582                         if ( m[1] == "#" ) { // Ummm, should make this work in all XML docs
583                                 var oid = document.getElementById(m[2]);
584                                 r = ret = oid ? [oid] : [];
585                                 t = t.replace( re2, "" );
586                         } else {
587                                 if ( m[2] === "" || m[1] == "." ) { m[2] = "*"; }
588         
589                                 for ( var i = 0; i < ret.length; i++ ) {
590                                         var o = ret[i];
591                                         if ( o ) {
592                                                 switch( m[2] ) {
593                                                         case '*':
594                                                                 r = $.merge( $.getAll(o), r );
595                                                         break;
596                                                         case 'text': case 'radio': case 'checkbox': case 'hidden':
597                                                         case 'button': case 'submit': case 'image': case 'password':
598                                                         case 'reset': case 'file':
599                                                                 r = $.merge( $.grep( $.tag(o,"input"), 
600                                                                         function(a){ return a.type == m[2]; }), r );
601                                                         break;
602                                                         case 'input':
603                                                                 r = $.merge( $.tag(o,"input"), r );
604                                                                 r = $.merge( $.tag(o,"select"), r );
605                                                                 r = $.merge( $.tag(o,"textarea"), r );
606                                                         break;
607                                                         default:
608                                                                 r = $.merge( r, $.tag(o,m[2]) );
609                                                         break;
610                                                 }
611                                         }
612                                 }
613                         }
614                 }
615
616                 if ( t ) {
617                         var val = $.filter(t,r);
618                         ret = r = val.r;
619                         t = $.cleanSpaces(val.t);
620                 }
621         }
622
623         if ( ret && ret[0] == context ) { ret.shift(); }
624         done = $.merge( done, ret );
625
626         return done;
627 };
628
629 $.tag = function(a,b){
630         return a && typeof a.getElementsByTagName != 'undefined' ?
631                 a.getElementsByTagName( b ) : [];
632 };
633
634 $.attr = function(o,a,v){
635         if ( a && a.constructor == String ) {
636                 var fix = {
637                         'for': 'htmlFor',
638                         'text': 'cssText',
639                         'class': 'className',
640                         'float': 'cssFloat'
641                 };
642                 a = (fix[a] && fix[a].replace && fix[a]) || a;
643                 var r = new RegExp("-([a-z])","ig");
644                 a = a.replace(r,function(z,b){return b.toUpperCase();});
645                 if ( typeof v != 'undefined' ) {
646                         o[a] = v;
647                         if ( o.setAttribute ) {
648                                 o.setAttribute(a,v);
649                         }
650                 } 
651                 return o[a] || o.getAttribute(a) || '';
652         } else {
653                 return '';
654         }
655 };
656
657 $.filter = function(t,r,not) {
658         var g = $.grep;
659         if ( not === false ) {
660                 g = function(a,f) {return $.grep(a,f,true);};
661         }
662         
663         while ( t.length > 0 && t.match(/^[:\\.#\\[a-zA-Z\\*]/) ) {
664                 var re = new RegExp( "^\\[ *@([a-z0-9\\(\\)_-]+) *([~!\\|\\*$^=]*) *'?\"?([^'\"]*)'?\"? *\\]", "i" );
665                 var m = re.exec(t);
666                 
667                 if ( m !== null ) {
668                         m = ['', '@', m[2], m[1], m[3]];
669                 } else {
670                         re = new RegExp( "^(\\[) *([^\\]]*) *\\]", "i" );
671                         m = re.exec(t);
672                         
673                         if ( m === null ) {
674                                 re = new RegExp( "^(:)([a-z0-9\\*_-]*)\\( *[\"']?([^ \\)'\"]*)['\"]? *\\)", "i" );
675                                 m = re.exec(t);
676                                 
677                                 if ( m === null ) {
678                                         re = new RegExp( "^([:\\.#]*)([a-z0-9\\*_-]*)", "i" );
679                                         m = re.exec(t);
680                                 }
681                         }
682                 }
683                 t = t.replace( re, "" );
684                 
685                 if ( m[1] == ":" && m[2] == "not" ) {
686                         r = $.filter(m[3],r,false).r;
687                 } else {
688                         var f = null;
689
690                         if ( $.g[m[1]].constructor == String ) {
691                                 f = $.g[m[1]];
692                         } else if ( $.g[m[1]][m[2]] ) {
693                                 f = $.g[m[1]][m[2]];
694                         }
695                                                 
696                         if ( f !== null ) {
697                                 eval('f = function(a,i){return ' + f + '}');
698                                 r = g( r, f );
699                         }
700                 }
701         }
702
703         return { r: r, t: t };
704 };
705
706 $.parents = function(a){
707         var b = [];
708         var c = a.parentNode;
709         while ( c !== null && c != document ) {
710                 b[b.length] = c;
711                 c = c.parentNode;
712         }
713         return b;
714 };
715
716 $.cleanSpaces = function(t){
717         return t.replace(/^\s+|\s+$/g, '');
718 };
719
720 $.ofType = function(a,n,e) {
721         var t = $.grep($.sibling(a),function(b){return b.nodeName == a.nodeName;});
722         if ( e ) { n = t.length - n - 1; }
723         return typeof n != 'undefined' ? t[n] == a : t.length;
724 };
725
726 $.sibling = function(a,n,e) {
727         var type = [];
728         var tmp = a.parentNode.childNodes;
729         for ( var i = 0; i < tmp.length; i++ ) {
730                 if ( tmp[i].nodeType == 1 ) {
731                         type[type.length] = tmp[i];
732                 }
733                 if ( tmp[i] == a ) {
734                         type.n = type.length - 1;
735                 }
736         }
737         if ( e ) { n = type.length - n - 1; }
738         type.cur = ( type[n] == a );
739         type.prev = ( type.n > 0 ? type[type.n - 1] : null );
740         type.next = ( type.n < type.length - 1 ? type[type.n + 1] : null );
741         return type;
742 };
743
744 $.hasWord = function(e,a) {
745         if ( typeof e == 'undefined' ) { return false; }
746         if ( e.className !== null ) { e = e.className; }
747         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
748 };
749
750 $.getAll = function(o,r) {
751         r = r || [];
752         var s = o.childNodes;
753         for ( var i = 0; i < s.length; i++ ) {
754                 if ( s[i].nodeType == 1 ) {
755                         r[r.length] = s[i];
756                         $.getAll( s[i], r );
757                 }
758         }
759         return r;
760 };
761
762 $.merge = function(a,b) {
763         var d = [];
764         for ( var k = 0; k < b.length; k++ ) { d[k] = b[k]; }
765         
766         for ( var i = 0; i < a.length; i++ ) {
767                 var c = true;
768                 for ( var j = 0; j < b.length; j++ ) {
769                         if ( a[i] == b[j] ) {
770                                 c = false;
771                         }
772                 }
773                 if ( c ) {
774                         d[d.length] = a[i];
775                 }
776         }
777
778         return d;
779 };
780
781 $.grep = function(a,f,s) {
782         var r = [];
783         if ( typeof a != 'undefined' ) {
784                 for ( var i = 0; i < a.length; i++ ) {
785                         if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) ) {
786                                 r[r.length] = a[i];
787                         }
788                 }
789         }
790         return r;
791 };
792
793 $.map = function(a,f) {
794         var r = [];
795         for ( var i = 0; i < a.length; i++ ) {
796                 var t = f(a[i],i);
797                 if ( t !== null ) {
798                         if ( t.constructor != Array ) { t = [t]; }
799                         r = $.merge( t, r );
800                 }
801         }
802         return r;
803 };
804
805 $.event = {};
806
807 // Bind an event to an element
808 // Original by Dean Edwards
809 $.event.add = function(element, type, handler) {
810         // For whatever reason, IE has trouble passing the window object
811         // around, causing it to be cloned in the process
812         if ( $.browser == "msie" && typeof element.setInterval != "undefined" ) {
813                 element = window;
814         }
815
816         if (!handler.$$guid) { handler.$$guid = $.event.add.guid++; }
817         if (!element.events) { element.events = {}; }
818         var handlers = element.events[type];
819         if (!handlers) {
820                 handlers = element.events[type] = {};
821                 if (element["on" + type]) {
822                         handlers[0] = element["on" + type];
823                 }
824         }
825         handlers[handler.$$guid] = handler;
826         element["on" + type] = $.event.handle;
827 };
828
829 $.event.add.guid = 1;
830
831 // Detach an event or set of events from an element
832 $.event.remove = function(element, type, handler) {
833         if (element.events) {
834                 if (type && element.events[type]) {
835                         if ( handler ) {
836                                 delete element.events[type][handler.$$guid];
837                         } else {
838                                 for ( var i in element.events[type] ) {
839                                         delete element.events[type][i];
840                                 }
841                         }
842                 } else {
843                         for ( var j in element.events ) {
844                                 $.event.remove( element, j );
845                         }
846                 }
847         }
848 };
849
850 $.event.trigger = function(element,type,data) {
851         data = data || [ $.event.fix({ type: type }) ];
852         if ( element && element["on" + type] ) {
853                 $.apply( element, element["on" + type], data );
854         }
855 };
856
857 $.event.handle = function(event) {
858         if ( !event && !window.event ) { return null; }
859
860         var returnValue = true, handlers = [];
861         event = event || $.event.fix(window.event);
862
863         for ( var j in this.events[event.type] ) {
864                 handlers[handlers.length] = this.events[event.type][j];
865         }
866
867         for ( var i = 0; i < handlers.length; i++ ) {
868                 if ( handlers[i].constructor == Function ) {
869                         this.$$handleEvent = handlers[i];
870                         if (this.$$handleEvent(event) === false) {
871                                 event.preventDefault();
872                                 event.stopPropagation();
873                                 returnValue = false;
874                         }
875                 }
876         }
877         return returnValue;
878 };
879
880 $.event.fix = function(event) {
881         event.preventDefault = $.event.fix.preventDefault;
882         event.stopPropagation = $.event.fix.stopPropagation;
883         return event;
884 };
885
886 $.event.fix.preventDefault = function() {
887         this.returnValue = false;
888 };
889
890 $.event.fix.stopPropagation = function() {
891         this.cancelBubble = true;
892 };
893
894 // Move to module
895
896 $.fn.text = function(e) {
897         e = e || this.cur;
898         var t = "";
899         for ( var j = 0; j < e.length; j++ ) {
900                 for ( var i = 0; i < e[j].childNodes.length; i++ ) {
901                         t += e[j].childNodes[i].nodeType != 1 ?
902                                 e[j].childNodes[i].nodeValue :
903                                 $.fn.text(e[j].childNodes[i].childNodes);
904                 }
905         }
906         return t;
907 };
908
909 /*setTimeout(function(){
910         if ( typeof Prototype != "undefined" && $.g == null && $.clean == null )
911                 throw "Error: You are overwriting jQuery, please include jQuery last.";
912 }, 1000);*/