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