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