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